/* =========================================================
   QMSPL Portal — shared styles
   Brand = charcoal (from logo). Logo red appears only in the logo.
   Red / amber / green / grey are reserved for STATUS.
   ========================================================= */
:root {
  --bg: #F5F6F8; --surface: #FFFFFF; --surface-2: #F9FAFB; --border: #E3E5E9; --border-strong: #CDD1D8;
  --text: #1B1C1F; --text-2: #4A4E57; --muted: #737884;
  --brand: #303034; --brand-hover: #1D1D20; --brand-text: #FFFFFF; --brand-soft: #EDEEF0;
  --focus: #5B6CFF;
  --red: #D92D20;   --red-soft: #FDECEA;   --red-text: #B42318;
  --amber: #F79009; --amber-soft: #FEF4E6; --amber-text: #B54708;
  --green: #12B76A; --green-soft: #E7F8EF; --green-text: #027A48;
  --grey: #98A2B3;  --grey-soft: #F0F2F5;  --grey-text: #475467;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 12px 32px -8px rgba(16,24,40,.18), 0 4px 8px -4px rgba(16,24,40,.08);
  --radius: 10px; --radius-sm: 7px; --sidebar-w: 232px; --topbar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214; --surface: #18191C; --surface-2: #1E1F23; --border: #2A2C31; --border-strong: #3A3D44;
    --text: #ECEDEF; --text-2: #C4C7CD; --muted: #9398A2;
    --brand: #ECEDEF; --brand-hover: #FFFFFF; --brand-text: #18191C; --brand-soft: #26282D;
    --red-soft: #3A1D1B; --red-text: #FDA29B; --amber-soft: #3A2A12; --amber-text: #FEC84B;
    --green-soft: #133226; --green-text: #6CE9A6; --grey-soft: #2A2C31; --grey-text: #C4C7CD;
    --shadow-lg: 0 12px 32px -8px rgba(0,0,0,.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214; --surface: #18191C; --surface-2: #1E1F23; --border: #2A2C31; --border-strong: #3A3D44;
  --text: #ECEDEF; --text-2: #C4C7CD; --muted: #9398A2;
  --brand: #ECEDEF; --brand-hover: #FFFFFF; --brand-text: #18191C; --brand-soft: #26282D;
  --red-soft: #3A1D1B; --red-text: #FDA29B; --amber-soft: #3A2A12; --amber-text: #FEC84B;
  --green-soft: #133226; --green-text: #6CE9A6; --grey-soft: #2A2C31; --grey-text: #C4C7CD;
  --shadow-lg: 0 12px 32px -8px rgba(0,0,0,.6); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
a.link { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 2px; }
a.link:hover { text-decoration-color: var(--text); }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 15px; height: 15px; }
svg.i.lg { width: 24px; height: 24px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.sub { font-size: 12px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.hidden, [hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

/* ---------- Shell ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 30; }
.sidebar .brand { height: var(--topbar-h); display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--border); flex: none; }
.sidebar .brand img { height: 30px; }
:root[data-theme="dark"] .sidebar .brand img { filter: brightness(1.7); }
.nav { padding: 10px; overflow-y: auto; flex: 1; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; }
.nav a, .nav-soon { display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; position: relative; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--text); font-weight: 600; }
.nav a.active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav-soon { color: var(--muted); opacity: .6; cursor: default; }
.nav .soon { margin-left: auto; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; border: 1px solid var(--border); padding: 0 5px; border-radius: 4px; }
.nav .count { margin-left: auto; font-size: 11px; font-weight: 600; background: var(--amber-soft); color: var(--amber-text); padding: 1px 7px; border-radius: 99px; }
.sidebar .me { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.me-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--brand-text); display: grid; place-items: center; font-size: 11.5px; font-weight: 600; flex: none; }
.avatar.alt { background: #6B7280; color: #fff; }
.avatar.xs { width: 24px; height: 24px; font-size: 10px; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; border-radius: 12px; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 24px; }
.gsearch { flex: 1; max-width: 520px; position: relative; }
.gsearch input { width: 100%; height: 38px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px; padding: 0 70px 0 38px; outline: none; }
.gsearch input:focus { border-color: var(--border-strong); background: var(--surface); }
.gsearch > svg { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.kbd { position: absolute; right: 10px; top: 9px; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; background: var(--surface); }
.gsearch-results { position: absolute; top: 44px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; max-height: 70vh; overflow: auto; z-index: 50; }
.gsearch-results .grp { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px 4px; }
.gsearch-results a { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 7px; }
.gsearch-results a:hover, .gsearch-results a.sel { background: var(--surface-2); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn .badge { position: absolute; top: 4px; right: 3px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); }
.user-btn { width: auto; padding: 0 6px; gap: 6px; display: flex; }
.hamburger { display: none; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 5px; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-ghost { color: var(--red-text); }
.btn .spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Page ---------- */
.page { padding: 24px; max-width: 1480px; }
.page.narrow { max-width: 1040px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-head p { margin: 3px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.crumb a:hover { color: var(--text); }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow-sm); text-align: left; transition: border-color .15s, box-shadow .15s; }
.kpi:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.kpi.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.kpi.static { cursor: default; }
.kpi .top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .ic { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; background: var(--brand-soft); color: var(--text-2); flex: none; }
.kpi .ic.red { background: var(--red-soft); color: var(--red-text); }
.kpi .ic.amber { background: var(--amber-soft); color: var(--amber-text); }
.kpi .ic.green { background: var(--green-soft); color: var(--green-text); }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .trend { font-size: 12px; margin-top: 2px; display: flex; align-items: center; gap: 3px; color: var(--muted); min-height: 17px; }
.kpi .trend b { font-weight: 600; display: inline-flex; align-items: center; gap: 2px; }
.kpi .trend b.good { color: var(--green-text); } .kpi .trend b.bad { color: var(--red-text); }

/* ---------- Panels & filters ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel + .panel, .panel + .section, .section + .section { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-body { padding: 16px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.filters .spacer { flex: 1; }
.fsel { height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0 28px 0 10px; outline: none; appearance: none; cursor: pointer; max-width: 200px;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23737884' stroke-width='2'%3e%3cpath d='m6 9 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 14px; }
.fsel.set { border-color: var(--brand); background-color: var(--brand-soft); font-weight: 500; }
.fsearch { position: relative; }
.fsearch input { height: 34px; width: 280px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0 10px 0 32px; outline: none; }
.fsearch input:focus { border-color: var(--border-strong); }
.fsearch svg { position: absolute; left: 10px; top: 9.5px; color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; user-select: none; }
.toggle.on { border-color: var(--brand); background: var(--brand-soft); font-weight: 500; }
.toggle input { margin: 0; accent-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 6px 0 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); display: grid; place-items: center; padding: 2px; border-radius: 50%; }
.chip button:hover { background: var(--surface-2); color: var(--text); }
.chip.clear { background: transparent; border: 0; color: var(--text-2); font-weight: 500; cursor: pointer; padding: 0 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
.table-wrap.tall { max-height: calc(100vh - 330px); min-height: 280px; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { color: var(--text); }
.grid th .s { display: inline-flex; vertical-align: -3px; opacity: .45; }
.grid th.sorted .s { opacity: 1; color: var(--text); }
.grid th.num { text-align: right; }
.grid td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid tbody tr { transition: background .1s; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid.compact td { padding: 8px 10px; }
.cname { font-weight: 600; color: var(--text); display: block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.cname:hover { text-decoration: underline; }
.svc { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px; background: var(--brand-soft); color: var(--text-2); margin: 1px 3px 1px 0; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.red { background: var(--red-soft); color: var(--red-text); }
.pill.amber { background: var(--amber-soft); color: var(--amber-text); }
.pill.green { background: var(--green-soft); color: var(--green-text); }
.pill.grey { background: var(--grey-soft); color: var(--grey-text); }
.pill.neutral { background: var(--brand-soft); color: var(--text-2); }
.pill.neutral::before { display: none; }
.dot-btn { border: 0; background: transparent; padding: 6px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.dot-btn:hover { background: var(--brand-soft); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: block; flex: none; }
.dot.red { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.dot.amber { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.dot.green { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot.grey { background: var(--grey); box-shadow: 0 0 0 3px var(--grey-soft); }
.dot.sm { width: 9px; height: 9px; }
.due-text { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-when { font-size: 12px; font-weight: 500; }
.due-when.red { color: var(--red-text); } .due-when.amber { color: var(--amber-text); } .due-when.green { color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.pager .pages { display: flex; gap: 4px; align-items: center; }
.pager .pages button { min-width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface); border-radius: 7px; cursor: pointer; color: var(--text-2); }
.pager .pages button.on { background: var(--brand); color: var(--brand-text); border-color: var(--brand); font-weight: 600; }
.pager .pages button:disabled { opacity: .4; cursor: default; }
.pager select { height: 30px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }

.sk { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

.empty { text-align: center; padding: 48px 20px; }
.empty .art { width: 56px; height: 56px; border-radius: 14px; background: var(--brand-soft); display: grid; place-items: center; margin: 0 auto 14px; color: var(--text-2); }
.empty h3 { margin: 0 0 4px; font-size: 16px; }
.empty p { margin: 0 auto 16px; color: var(--muted); max-width: 420px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.f { grid-column: span 6; min-width: 0; }
.f.c1 { grid-column: span 1; } .f.c2 { grid-column: span 2; } .f.c3 { grid-column: span 3; } .f.c4 { grid-column: span 4; } .f.c5 { grid-column: span 5; } .f.c8 { grid-column: span 8; } .f.c12 { grid-column: span 12; }
.f label, .lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.f label .req { color: var(--red-text); margin-left: 2px; }
.f label .opt { color: var(--muted); font-weight: 400; }
.inp { width: 100%; height: 38px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); padding: 0 11px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.inp { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
select.inp { appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23737884' stroke-width='2'%3e%3cpath d='m6 9 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 15px; }
.inp:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.inp[readonly] { background: var(--surface-2); color: var(--text-2); }
.inp.upper { text-transform: uppercase; }
.f.err .inp, .inp.err { border-color: var(--red); }
.f .msg { font-size: 12px; margin-top: 4px; color: var(--muted); }
.f.err .msg, .msg.err { color: var(--red-text); }
.f .msg.ok { color: var(--green-text); }
.input-group { display: flex; }
.input-group .pre { display: grid; place-items: center; padding: 0 10px; border: 1px solid var(--border-strong); border-right: 0; border-radius: 8px 0 0 8px; background: var(--surface-2); color: var(--muted); font-size: 13px; }
.input-group .inp { border-radius: 0 8px 8px 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; padding-top: 6px; }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.section > .sh { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.section > .sh h2 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 9px; }
.section > .sh p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.section > .sb { padding: 18px; }
.repeat-card { border: 1px solid var(--border); border-radius: 9px; padding: 14px; background: var(--surface-2); position: relative; }
.repeat-card + .repeat-card { margin-top: 12px; }
.repeat-card .rc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.repeat-card .rc-head b { font-size: 13px; }
.form-foot { position: sticky; bottom: 0; z-index: 10; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 0; margin-top: 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.form-foot .left { margin-right: auto; display: flex; align-items: center; color: var(--muted); font-size: 13px; }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 9px; border: 1px solid; margin-bottom: 14px; }
.alert.amber { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 40%, transparent); color: var(--amber-text); }
.alert.red { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 40%, transparent); color: var(--red-text); }
.alert.info { background: var(--brand-soft); border-color: var(--border); color: var(--text-2); }
.alert.green { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 40%, transparent); color: var(--green-text); }
.alert a { text-decoration: underline; font-weight: 600; }
.tagbox { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 38px; border: 1px solid var(--border-strong); border-radius: 8px; padding: 4px 6px; background: var(--surface); cursor: text; }
.tagbox:focus-within { border-color: var(--brand); }
.tagbox input { border: 0; outline: none; flex: 1; min-width: 120px; height: 28px; background: transparent; }
.tagbox .chip { height: 24px; }

/* ---------- Tabs & detail header ---------- */
.detail-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.detail-head .title { flex: 1; min-width: 240px; }
.detail-head h1 { margin: 0; font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-head .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 13px; margin-top: 6px; }
.detail-head .meta span { display: inline-flex; align-items: center; gap: 5px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .n { font-size: 11px; background: var(--brand-soft); padding: 0 6px; border-radius: 99px; color: var(--text-2); }
.dl { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.mini-card { border: 1px solid var(--border); border-radius: 9px; padding: 14px; background: var(--surface); }
.mini-card .flags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .tl-ic { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); display: grid; place-items: center; flex: none; color: var(--text-2); }

/* ---------- Floating: popovers, menus, modals, toasts ---------- */
.pop { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); width: 380px; max-width: calc(100vw - 24px); animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.pop-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.due-item { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.due-item:last-child { border-bottom: 0; }
.due-item .row1 { display: flex; gap: 10px; align-items: flex-start; }
.due-item .dot { margin-top: 4px; }
.due-item .t { font-weight: 500; }
.due-item .acts { display: flex; gap: 6px; margin-top: 8px; padding-left: 19px; flex-wrap: wrap; }
.menu { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; min-width: 200px; animation: pop .12s ease-out; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 9px; padding: 8px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; text-align: left; color: var(--text-2); }
.menu button:hover, .menu a:hover { background: var(--surface-2); color: var(--text); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.menu .danger { color: var(--red-text); }
.menu .mh { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 10px 4px; }
.backdrop { position: fixed; inset: 0; background: rgba(16,18,24,.45); z-index: 70; display: grid; place-items: center; padding: 16px; animation: fade .15s; overflow-y: auto; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 440px; max-width: 100%; }
.modal.wide { width: 720px; }
.modal .mh2 { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 0; }
.modal h3 { margin: 0; font-size: 17px; }
.modal .mb { padding: 14px 20px; color: var(--text-2); }
.modal .mb p { margin: 0 0 12px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--surface); padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); display: flex; gap: 9px; align-items: center; min-width: 260px; max-width: 420px; animation: pop .15s; font-weight: 500; }
.toast .ok { color: var(--green); } .toast .bad { color: #FDA29B; }
.copybox { display: flex; gap: 6px; }
.copybox input { flex: 1; }

/* ---------- Mobile ---------- */
.cards { display: none; }
.bottom-bar { display: none; }
@media (max-width: 1440px) { .col-hide-lg { display: none; } }
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main { margin-left: 0; }
  .hamburger { display: grid; }
  .topbar { padding: 0 12px; gap: 6px; }
  .kbd, .hide-sm { display: none !important; }
  .gsearch input { padding-right: 12px; }
  .page { padding: 16px 16px 92px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; } .kpi .val { font-size: 20px; }
  .fsearch { flex: 1 1 100%; } .fsearch input { width: 100%; }
  .filters .fsel, .filters .toggle { flex: 1 1 calc(50% - 4px); max-width: none; }
  .table-wrap.has-cards { display: none; }
  .cards { display: block; }
  .ccard { padding: 14px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
  .ccard:last-child { border-bottom: 0; }
  .ccard .dot-btn { grid-row: span 3; align-self: start; margin-top: -4px; }
  .ccard .name { font-weight: 600; }
  .ccard .cta { display: flex; gap: 8px; margin-top: 8px; }
  .ccard .cta .btn { flex: 1; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .f, .f.c1, .f.c2, .f.c3, .f.c4, .f.c5 { grid-column: span 1; } .f.c8, .f.c12, .f.full-sm { grid-column: span 2; }
  .dl { grid-template-columns: 1fr; gap: 2px; } .dl dd { margin-bottom: 8px; }
  .bottom-bar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-bar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; position: relative; }
  .bottom-bar a.active { color: var(--text); font-weight: 600; }
  .toasts { left: 16px; right: 16px; bottom: 84px; }
  .toast { max-width: none; }
  .pop { left: 12px !important; right: 12px; width: auto; }
  .form-foot { bottom: 64px; }
}
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } .f, .f.c1, .f.c2, .f.c3, .f.c4, .f.c5, .f.c8, .f.c12 { grid-column: span 1; } }
@media print { .sidebar, .topbar, .bottom-bar, .toasts { display: none !important; } .main { margin: 0; } }

/* client services register: service rows, each with its invoices in a sub-table that opens below */
.cs-table > tbody > tr > td { vertical-align: top; }
.cs-table .cs-tog { padding: 0 6px; height: 26px; }
.cs-table .cs-tog + .pill { margin-left: 4px; }
.cs-table > tbody > tr.cs-sub > td { background: var(--bg); padding: 8px 12px 12px; }
.cs-sub .table-wrap { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
