/* Safety Shield CRM — one stylesheet, no build step.
   Brand colours come from Admin → Branding and are injected as --brand / --accent. */

:root {
  --brand: #1F4E79;
  --brand-ink: #ffffff;
  --accent: #F2A900;
  --ink: #18212b;
  --ink-2: #4a5663;
  --ink-3: #6f7b88;
  --line: #d9dee4;
  --line-2: #eceff3;
  --page: #f3f5f7;
  --card: #ffffff;
  --green: #1d7a46;  --green-bg: #e3f3e9;
  --amber: #8a5a00;  --amber-bg: #fdf0d2;
  --red: #b42318;    --red-bg: #fde7e5;
  --blue: #1f5fa8;   --blue-bg: #e4eefa;
  --grey: #55606c;   --grey-bg: #eceff2;
  --radius: 6px;
  --radius-lg: 10px;
  --sidebar: 248px;
  --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --focus: 0 0 0 3px rgba(242, 169, 0, .55);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--page); }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 3px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.005em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.num, td.num, .money { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pre { white-space: pre-line; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar::after { content: ""; display: block; height: 6px; flex: none; margin-top: auto;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 10px, #1c1c1c 10px 20px); }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem .9rem; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand img { max-height: 34px; max-width: 150px; background: #fff; border-radius: 4px; padding: 2px 4px; }
.brand-mark { width: 30px; height: 34px; flex: none; }
.nav { padding: .25rem .6rem 1.5rem; }
.nav-group { margin-top: .9rem; }
.nav-group > span { display: block; padding: 0 .55rem .25rem; font-size: .78rem; opacity: .7; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .42rem .55rem; border-radius: var(--radius);
  color: inherit; text-decoration: none; opacity: .92; }
.nav a:hover { background: rgba(255,255,255,.1); opacity: 1; }
.nav a.active { background: rgba(255,255,255,.16); opacity: 1; box-shadow: inset 3px 0 0 var(--accent); font-weight: 700; }
.nav .soon { font-size: .72rem; opacity: .6; }
.nav .count { font-size: .75rem; background: var(--accent); color: #1c1c1c; border-radius: 99px; padding: 0 .45rem; font-weight: 700; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar form.search { flex: 1; max-width: 560px; position: relative; }
.topbar input[type=search] { width: 100%; padding-left: 2.1rem; background: var(--page) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236f7b88' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E") no-repeat .7rem center; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: .8rem; font-weight: 700; text-decoration: none; }


.content { padding: 1.25rem 1.5rem 3rem; max-width: 1400px; width: 100%; }
.crumbs { font-size: .85rem; color: var(--ink-3); margin-bottom: .35rem; }
.crumbs a { color: var(--ink-3); }
.crumbs span + span::before, .crumbs a + span::before, .crumbs a + a::before { content: "/"; margin: 0 .4rem; color: var(--line); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-2); margin-top: .25rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Reference tag — the record's identity, styled like an inspection tag */
.ref { display: inline-flex; align-items: stretch; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em;
  border: 1.5px solid var(--ink); border-radius: 4px; overflow: hidden; font-size: .95rem; background: #fff; vertical-align: middle; }
.ref::before { content: ""; width: 9px; background: repeating-linear-gradient(-45deg, var(--accent) 0 4px, var(--ink) 4px 8px); }
.ref > span { padding: .1rem .55rem; }
td .ref { font-size: .82rem; border-width: 1px; }
td .ref::before { width: 6px; }

/* ---------- Cards, panels ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel + .panel { margin-top: 1rem; }
.grid > .panel + .panel { margin-top: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line-2); }
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-body { padding: 1rem; }
.panel-body.flush { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: .8rem 1rem; text-decoration: none; color: inherit; display: block; border-top: 3px solid var(--tone, var(--line)); }
a.stat:hover { border-color: var(--ink-3); border-top-color: var(--tone, var(--ink-3)); }
.stat .label { color: var(--ink-2); font-size: .88rem; }
.stat .value { font-size: 1.65rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .hint { font-size: .8rem; color: var(--ink-3); }
.tone-green { --tone: var(--green); } .tone-amber { --tone: var(--accent); } .tone-red { --tone: var(--red); }
.tone-blue { --tone: var(--blue); } .tone-grey { --tone: var(--grey); }
.section-title { font-size: .95rem; color: var(--ink-2); margin: 1.25rem 0 .5rem; font-weight: 700; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dl.facts dt { color: var(--ink-3); }
dl.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .08rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.badge-green { color: var(--green); background: var(--green-bg); }
.badge-amber { color: var(--amber); background: var(--amber-bg); }
.badge-red { color: var(--red); background: var(--red-bg); }
.badge-blue { color: var(--blue); background: var(--blue-bg); }
.badge-grey { color: var(--grey); background: var(--grey-bg); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-weight: 700; color: var(--ink-2); font-size: .82rem; padding: .55rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
table.data td { padding: .6rem .75rem; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #f8fafc; }
table.data a.sort { color: inherit; text-decoration: none; }
table.data a.sort:hover { color: var(--brand); text-decoration: underline; }
table.data td.num, table.data th.num { text-align: right; }
table.data .primary-link { font-weight: 700; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--ink-2); }
.empty p { margin-bottom: .75rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; padding: .75rem 1rem; border-bottom: 1px solid var(--line-2); }
.filters .field { margin: 0; }
.filters input[type=search] { min-width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; padding: .75rem 1rem 0; }
.chip { display: inline-flex; gap: .35rem; align-items: center; padding: .2rem .65rem; border: 1px solid var(--line); border-radius: 99px; text-decoration: none; color: var(--ink-2); font-size: .85rem; background: #fff; }
.chip.on { border-color: var(--brand); color: var(--brand); background: var(--blue-bg); font-weight: 700; }
.chip b { font-variant-numeric: tabular-nums; }

.pagination { display: flex; gap: .25rem; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-top: 1px solid var(--line-2); font-size: .88rem; color: var(--ink-3); flex-wrap: wrap; }
.pagination .pages { display: flex; gap: .25rem; }
.pagination a, .pagination span.cur { padding: .2rem .6rem; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.pagination span.cur { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .85rem 1rem; }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field > label, .label { font-weight: 700; font-size: .88rem; }
.field .hint { font-size: .8rem; color: var(--ink-3); }
.req::after { content: " *"; color: var(--red); }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=password], input[type=search], input[type=url], input[type=color], select, textarea {
  font: inherit; color: inherit; width: 100%; padding: .48rem .65rem; border: 1px solid #b9c1ca; border-radius: var(--radius); background: #fff; min-height: 40px; }
input[type=color] { padding: .15rem; width: 64px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.is-invalid { border-color: var(--red) !important; }
.error { color: var(--red); font-size: .84rem; font-weight: 700; }
.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
.check input { width: 18px; height: 18px; margin-top: .15rem; accent-color: var(--brand); }
fieldset { border: 0; padding: 0; margin: 0; }
fieldset legend { font-weight: 700; font-size: 1rem; padding: 0; margin-bottom: .5rem; }
.form-section + .form-section { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line-2); }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; padding: 1rem; border-top: 1px solid var(--line-2); background: #fafbfc; border-radius: 0 0 var(--radius-lg) var(--radius-lg); flex-wrap: wrap; }

.postcode-row { display: flex; gap: .5rem; }
.postcode-row input { max-width: 160px; text-transform: uppercase; }
.pc-results { margin-top: .5rem; }
.pc-msg { font-size: .85rem; margin-top: .35rem; }

/* ---------- Buttons ---------- */
.btn { font: inherit; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .48rem .95rem; border-radius: var(--radius);
  border: 1px solid #b9c1ca; background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; min-height: 40px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.1); border-color: var(--brand); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #1c1c1c; }
.btn-danger { color: var(--red); border-color: #e7b4ae; }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm { padding: .25rem .6rem; min-height: 32px; font-size: .85rem; }
.btn-link { border: 0; background: none; color: var(--brand); padding: 0; min-height: 0; font-weight: 700; text-decoration: underline; cursor: pointer; font: inherit; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
form.inline { display: inline; }

/* ---------- Flash ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; font-weight: 700; }
.flash-ok { background: var(--green-bg); color: var(--green); border-color: #b7dfc6; }
.flash-error { background: var(--red-bg); color: var(--red); border-color: #f2b8b2; }
.flash-info { background: var(--blue-bg); color: var(--blue); border-color: #bcd3ef; font-weight: 400; }
.flash ul { margin: .25rem 0 0 1.1rem; padding: 0; font-weight: 400; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 700; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a .muted { font-weight: 400; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .65rem 1rem; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { font-size: .8rem; color: var(--ink-3); }
.timeline .t-status { border-left: 3px solid var(--blue); }
.timeline .t-question { border-left: 3px solid var(--accent); background: #fffaf0; }
.timeline .t-system { color: var(--ink-2); }

/* ---------- Documents ---------- */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.file { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; font-size: .82rem; display: flex; flex-direction: column; }
.file .thumb { height: 96px; background: var(--page) center/cover no-repeat; display: grid; place-items: center; color: var(--ink-3); font-weight: 700; text-decoration: none; }
.file .meta { padding: .4rem .5rem; display: flex; flex-direction: column; gap: .1rem; }
.file .meta a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Estimate lines editor ---------- */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: .8rem; text-align: left; color: var(--ink-2); padding: .4rem .35rem; border-bottom: 1px solid var(--line); }
.lines td { padding: .35rem; vertical-align: top; border-bottom: 1px solid var(--line-2); }
.lines textarea { min-height: 40px; height: 40px; }
.lines input { min-width: 0; }
.lines .w-qty { width: 78px; } .lines .w-unit { width: 86px; } .lines .w-price { width: 108px; }
.lines .w-disc { width: 70px; } .lines .w-vat { width: 78px; } .lines .w-total { width: 110px; text-align: right; padding-top: .8rem; }
.lines .w-x { width: 40px; }
.totals { margin-left: auto; width: min(360px, 100%); border-collapse: collapse; }
.totals td { padding: .3rem .5rem; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--ink); }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(16, 24, 32, .3); }
dialog::backdrop { background: rgba(16, 24, 32, .45); }
dialog .panel-head { border-bottom: 1px solid var(--line-2); }
dialog .panel-body { max-height: 70vh; overflow-y: auto; }

/* ---------- Bars (dashboard chart) ---------- */
.bars { display: flex; align-items: flex-end; gap: .5rem; height: 120px; padding-top: .5rem; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; height: 100%; justify-content: flex-end; font-size: .78rem; color: var(--ink-3); }
.bars .bar i { display: block; width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .bar b { color: var(--ink); font-variant-numeric: tabular-nums; }
.pipeline { display: flex; flex-direction: column; gap: .4rem; }
.pipeline a { display: grid; grid-template-columns: 150px 1fr 40px; gap: .5rem; align-items: center; text-decoration: none; color: inherit; font-size: .88rem; }
.pipeline .track { background: var(--line-2); height: 10px; border-radius: 99px; overflow: hidden; }
.pipeline .track i { display: block; height: 100%; background: var(--brand); }

/* ---------- Signature ---------- */
.sig-wrap { border: 1.5px dashed #9aa5b1; border-radius: var(--radius); background: #fff; position: relative; touch-action: none; }
.sig-wrap canvas { display: block; width: 100%; height: 170px; cursor: crosshair; }
.sig-wrap .sig-hint { position: absolute; left: 1rem; bottom: .6rem; color: var(--ink-3); font-size: .85rem; pointer-events: none; }

/* ---------- Auth / public ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: var(--page); }
.auth-card { width: min(420px, 100%); }
.auth-card .panel-body { padding: 1.5rem; }
.public-top { background: var(--brand); color: var(--brand-ink); }
.public-top .inner { max-width: 980px; margin: 0 auto; padding: .9rem 1.25rem; display: flex; align-items: center; gap: .75rem; font-weight: 700; }
.public-top img { max-height: 38px; background: #fff; border-radius: 4px; padding: 2px 4px; }
.public-top::after { content: ""; display: block; height: 5px; background: repeating-linear-gradient(-45deg, var(--accent) 0 10px, #1c1c1c 10px 20px); }
.public-main { max-width: 980px; margin: 0 auto; padding: 1.25rem; }
body.embed { background: transparent; }
body.embed .public-main { padding: 0; max-width: none; }

/* ---------- Responsive ---------- */
.topbar .menu-btn { display: none; }
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(290px, 86vw); z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(16,24,32,.45); }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: .5rem .75rem; }
  .content { padding: 1rem .75rem 3rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .col-8, .col-6, .col-4, .col-3, .col-2 { grid-column: span 12; }
  .col-3.half, .col-2.half, .col-4.half { grid-column: span 6; }
  .hide-sm { display: none; }
  .user-menu .name { display: none; }
  /* Tables become cards */
  table.data.stack thead { display: none; }
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack tr { padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
  table.data.stack td { border: 0; padding: .12rem 0; }
  table.data.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-3); font-size: .82rem; }
  table.data.stack td.num { text-align: left; }
  .lines thead { display: none; }
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100% !important; }
  .lines tr { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .lines td { border: 0; padding: 0; }
  .lines td.c-desc { grid-column: span 6; }
  .lines td.c-qty, .lines td.c-unit, .lines td.c-price { grid-column: span 2; }
  .lines td.c-disc, .lines td.c-vat { grid-column: span 2; }
  .lines td.w-total { grid-column: span 1; padding-top: .55rem; }
  .lines td.w-x { grid-column: span 1; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--ink-3); }
  .pipeline a { grid-template-columns: 120px 1fr 32px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .sidebar, .topbar, .actions, .form-actions, .filters { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .panel { border: 0; }
}
