/* =====================================================================
   Invoicing app: design system. No frameworks, system fonts.
   ===================================================================== */
:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #0f172a;
  --text: #1e293b;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e5e7ef;
  --border-strong: #cfd5e2;

  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --violet: #7c3aed;

  --good: #059669;
  --good-50: #ecfdf5;
  --warn: #c2410c;
  --warn-50: #fff7ed;
  --amber: #b45309;
  --amber-50: #fffbeb;
  --bad: #dc2626;
  --bad-50: #fef2f2;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .12);
  --font: "Plus Jakarta Sans", "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 248px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
h1 { font-size: 1.65rem; letter-spacing: -.02em; line-height: 1.2; margin: 0; color: var(--ink); display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1.02rem; letter-spacing: -.01em; margin: 0 0 .9rem; color: var(--ink); }
h3 { font-size: .95rem; margin: .4rem 0; }
p { margin: 0 0 .8rem; }
img { max-width: 100%; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.icon { flex-shrink: 0; }

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); }
.text-good { color: var(--good); }
.text-warn { color: var(--warn); }
.text-bad { color: var(--bad); }
.hint { color: var(--muted); font-size: .8rem; font-weight: 400; }
label > .hint { display: block; margin-top: .2rem; }
.req { color: var(--bad); }
.spacer { flex: 1; }

/* =====================================================================
   App shell: sidebar + main
   ===================================================================== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; gap: 1rem; padding: 1.1rem .9rem;
  background: linear-gradient(180deg, #0f172a 0%, #151e36 100%); color: #cbd5e1;
  overflow-y: auto;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: .65rem; color: #fff; font-weight: 700; min-width: 0; }
.brand:hover { color: #fff; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.01em; }
.brand-logo { height: 34px; width: auto; max-width: 120px; border-radius: 8px; background: #fff; padding: 3px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--violet)); color: #fff;
  font: 700 .85rem/1 var(--font); letter-spacing: .02em; box-shadow: 0 4px 14px rgba(79, 70, 229, .35);
}
.brand-mark-lg { width: 56px; height: 56px; font-size: 1.2rem; border-radius: 16px; }
.sidebar-cta { margin-top: .2rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 10px;
  color: #aab4c8; font-weight: 500; font-size: .93rem; background: none; border: 0; width: 100%; cursor: pointer; font-family: inherit; text-align: left;
}
.nav a:hover, .nav-btn:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.nav a.active { color: #fff; background: rgba(129, 140, 248, .18); box-shadow: inset 3px 0 0 #818cf8; }
.nav a.active .icon { color: #a5b4fc; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: .7rem; }
.sidebar-close { display: none; color: #cbd5e1; }
.nav-overlay { display: none; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); }
.mobilebar { display: none; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.8rem 28px 4rem; }
.container-narrow { max-width: 1040px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.icon-btn-primary:hover { background: var(--primary-600); color: #fff; }
.sidebar .icon-btn { background: transparent; border-color: rgba(255, 255, 255, .12); }

/* =====================================================================
   Page structure
   ===================================================================== */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.page-head p { margin: .35rem 0 0; }
.crumbs { font-size: .83rem; color: var(--muted); margin-bottom: .3rem; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem 1.4rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.card-head h2 { margin: 0; }
.card.empty { text-align: center; padding: 2.4rem 1.4rem; }
.empty-state { text-align: center; color: var(--muted); padding: 1.6rem 1rem; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); font-size: .92rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; align-items: start; margin-bottom: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.section-title { margin: 2.2rem 0 1rem; font-size: 1.2rem; }

/* =====================================================================
   Stats & KPIs
   ===================================================================== */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat, .kpi {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.05rem 1.2rem; box-shadow: var(--shadow); overflow: hidden;
}
.stat::before, .kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--border-strong); }
.stat-label, .kpi-label { color: var(--muted); font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value, .kpi-value { font-size: 1.5rem; font-weight: 700; margin-top: .25rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--ink); overflow-wrap: anywhere; }
.stat-highlight { background: linear-gradient(135deg, var(--primary-50), #f5f3ff); border-color: var(--primary-100); }
.stat-highlight::before { background: var(--primary); }
.stats .stat:has(.text-good)::before { background: var(--good); }
.stats .stat:has(.text-warn)::before { background: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi-received::before { background: var(--primary); }
.kpi-invoiced::before { background: #f59e0b; }
.kpi-worked::before { background: #94a3b8; }
.kpi-outstanding::before { background: var(--warn); }
.kpi-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .35rem; font-size: .82rem; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; padding: .05rem .45rem; border-radius: 99px; font-size: .78rem; }
.delta-up { color: var(--good); background: var(--good-50); }
.delta-down { color: var(--bad); background: var(--bad-50); }

/* =====================================================================
   Tables (stack into cards on phones; labels come from app.js)
   ===================================================================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -.4rem; padding: 0 .4rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .7rem .65rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); border-bottom-color: var(--border); }
.table thead th:first-child { border-top-left-radius: 8px; }
.table thead th:last-child { border-top-right-radius: 8px; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #fafbff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 0; color: var(--ink); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td a.strong { color: var(--ink); }
.table td a.strong:hover { color: var(--primary); }
.table-compact td { padding: .5rem .55rem; }
.is-archived { opacity: .55; }
.check-cell { width: 32px; }

/* =====================================================================
   Badges, tabs, segmented controls
   ===================================================================== */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .16rem .6rem; border-radius: 99px; font-size: .73rem; font-weight: 600; white-space: nowrap; background: #eef0f5; color: #475569; vertical-align: middle; line-height: 1.5; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge-unbilled { background: #eef0f5; color: #475569; }
.badge-draft { background: #f3e8ff; color: #7e22ce; }
.badge-invoiced, .badge-unpaid { background: var(--amber-50); color: var(--amber); }
.badge-partial { background: #fef9c3; color: #854d0e; }
.badge-paid { background: var(--good-50); color: var(--good); }
.badge-overdue { background: var(--bad-50); color: var(--bad); }
.badge-muted { background: #eef0f5; color: var(--muted); }

.tabs, .segmented-tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs a { padding: .35rem .8rem; border-radius: 99px; color: var(--muted); font-size: .86rem; font-weight: 500; }
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--primary-50); color: var(--primary); font-weight: 600; }
.page-tabs { margin-bottom: 1rem; }
.segmented-tabs { background: var(--surface-2); border: 1px solid var(--border); padding: 4px; border-radius: 12px; display: inline-flex; }
.segmented-tabs a { padding: .42rem .9rem; border-radius: 9px; color: var(--muted); font-size: .88rem; font-weight: 600; white-space: nowrap; }
.segmented-tabs a:hover { color: var(--ink); }
.segmented-tabs a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

/* =====================================================================
   Forms
   ===================================================================== */
label { display: block; font-weight: 600; font-size: .86rem; color: var(--ink); }
.label { display: block; font-weight: 600; font-size: .86rem; color: var(--ink); }
input, select, textarea {
  display: block; width: 100%; margin-top: .35rem; padding: .6rem .75rem; font: inherit; font-weight: 400; font-size: .95rem;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s; min-height: 42px;
}
textarea { min-height: 0; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #b7bfd0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); }
input[disabled], input[readonly] { background: var(--surface-2); color: var(--muted); }
input[type=checkbox], input[type=radio] { display: inline-block; width: 17px; height: 17px; min-height: 0; margin: 0 .45rem 0 0; vertical-align: middle; accent-color: var(--primary); }
input[type=file] { padding: .45rem; }
select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; }
label.check { font-weight: 500; display: inline-flex; align-items: center; cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.05rem 1.25rem; }
.form-grid h2 { margin: 0; }
.span-2 { grid-column: span 2; }
.stack > * + * { margin-top: .95rem; }
.form-actions { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; margin-top: 1.1rem; }
.form-grid .form-actions { margin-top: 0; }
.inline-form { display: flex; gap: .55rem; align-items: flex-end; margin: 1rem 0 .3rem; flex-wrap: wrap; }
.inline-form label { flex: 1; min-width: 160px; }
.inline { display: inline; margin: 0; }
.row-2, .due-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.danger-zone { margin-top: 1rem; }
.copy-row { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.copy-row input { margin: 0; font-size: .84rem; font-family: var(--mono); }
.logo-row { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.logo-preview { max-height: 64px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: #fff; }

/* Cost entry */
.cost-fields { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto 110px 130px 130px; gap: .85rem; align-items: end; }
.f-desc { min-width: 0; }
.f-total strong { display: block; padding: .6rem 0; font-variant-numeric: tabular-nums; font-size: 1.05rem; color: var(--ink); }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; margin-top: .35rem; background: var(--surface); }
.segmented label { font-weight: 500; padding: .55rem .85rem; cursor: pointer; display: flex; align-items: center; border-right: 1px solid var(--border-strong); min-height: 40px; }
.segmented label:last-child { border-right: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--primary-50); color: var(--primary); font-weight: 600; }
.quick-add { border-top: 3px solid var(--primary); }
.quick-add h2 { margin-bottom: .9rem; }
[data-cost-form][data-type="fixed"] [data-when="hourly"],
[data-cost-form][data-type="hourly"] [data-when="fixed"] { display: none; }

/* Invoice builder */
.cost-group { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 1rem; overflow: hidden; }
.cost-group-head { display: flex; justify-content: space-between; align-items: center; padding: .7rem .9rem; background: var(--surface-2); border-bottom: 1px solid var(--border); gap: .8rem; flex-wrap: wrap; }
.cost-group .table-wrap { margin: 0; padding: 0 .4rem; }
.selected-total { text-align: right; font-size: 1.05rem; padding-top: .5rem; }
.selected-total strong { font-size: 1.25rem; color: var(--ink); }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; background: rgba(244, 245, 250, .92); backdrop-filter: blur(8px); padding: .85rem 0; border-top: 1px solid var(--border); }
.preview-actions { margin: 0 0 1.2rem; }
.pick-list { display: grid; gap: .6rem; }
.pick { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .95rem 1.1rem; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: var(--surface); transition: all .15s; }
.pick:hover { border-color: var(--primary); background: var(--primary-50); color: var(--text); transform: translateY(-1px); }
.pick .muted { margin-left: .4rem; }
.pick-amount { font-weight: 700; white-space: nowrap; color: var(--ink); }

/* Invoice page */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.invoice-layout aside { position: sticky; top: 1.2rem; }
.doc-frame { background: #e9ebf2; border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; overflow-x: auto; }
.doc-frame .invoice-doc { box-shadow: var(--shadow-lg); border-radius: 6px; min-width: 640px; }
.details { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); font-size: .86rem; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.details.compact dd { text-align: right; font-variant-numeric: tabular-nums; }
.payment-list { list-style: none; margin: 0 0 1rem; padding: 0; border-top: 1px solid var(--border); }
.payment-list li { display: flex; justify-content: space-between; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.payment-form { border-top: 1px solid var(--border); padding-top: .7rem; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; min-height: 40px;
  font: inherit; font-weight: 600; font-size: .9rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px; cursor: pointer; white-space: nowrap; line-height: 1.2;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); color: var(--ink); border-color: #b7bfd0; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible { outline: 3px solid rgba(79, 70, 229, .35); outline-offset: 2px; }
.btn-primary { background: linear-gradient(180deg, #5b53ee, var(--primary)); border-color: var(--primary-600); color: #fff; box-shadow: 0 1px 2px rgba(67, 56, 202, .3), inset 0 1px 0 rgba(255, 255, 255, .15); }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.btn-sm { padding: .38rem .75rem; font-size: .83rem; min-height: 34px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-danger-outline { color: var(--bad); border-color: #f3c0c0; }
.btn-danger-outline:hover { background: var(--bad-50); color: var(--bad); border-color: #eaa; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* =====================================================================
   Flash messages
   ===================================================================== */
.flash { padding: .8rem 1rem .8rem 2.6rem; border-radius: 12px; margin-bottom: 1rem; border: 1px solid; position: relative; font-size: .93rem; }
.flash::before { content: ""; position: absolute; left: 1rem; top: 1.05rem; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.flash-success { background: var(--good-50); border-color: #a7f3d0; color: #065f46; }
.flash-error { background: var(--bad-50); border-color: #fecaca; color: #991b1b; }
.flash-info { background: var(--primary-50); border-color: var(--primary-100); color: #3730a3; }

/* =====================================================================
   Login / PIN pages
   ===================================================================== */
body.plain {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #ede9fe 0%, transparent 55%), var(--bg);
}
.plain-wrap { width: 100%; max-width: 420px; }
.plain-brand { display: flex; justify-content: center; margin-bottom: 1.2rem; }
.plain-logo { max-height: 64px; }
.plain-box { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 2rem; box-shadow: var(--shadow-lg); }
.plain-box h1 { font-size: 1.4rem; justify-content: center; text-align: center; margin-bottom: .35rem; }
.plain-box > p.muted { text-align: center; }
.plain-foot { text-align: center; color: var(--faint); font-size: .78rem; margin-top: 1.2rem; }
.pin-input { font-size: 1.5rem; letter-spacing: .45em; text-align: center; font-variant-numeric: tabular-nums; }
.cf-turnstile { min-height: 65px; }
.otp-links { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }

/* =====================================================================
   Client portal
   ===================================================================== */
.portalbar { background: linear-gradient(90deg, #0f172a, #1e1b4b); color: #fff; }
.portalbar-inner { max-width: 1040px; margin: 0 auto; padding: .8rem 28px; display: flex; align-items: center; gap: 1rem; }
.portal-client { flex: 1; color: #c7d2fe; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.portalbar .btn-ghost { color: #c7d2fe; }
.portalbar .btn-ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; border-color: transparent; }
.logout { margin: 0; }
.portal-footer { margin-top: 2.4rem; text-align: center; color: var(--muted); font-size: .85rem; }

/* =====================================================================
   Analytics
   ===================================================================== */
.filters { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 1rem 1.2rem; }
.period-nav { display: flex; align-items: center; gap: .5rem; }
.period-label { min-width: 150px; text-align: center; color: var(--ink); font-size: 1.02rem; }
.filter-form { display: flex; gap: .7rem; align-items: flex-end; flex-wrap: wrap; }
.filter-form label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.filter-form input, .filter-form select { min-width: 150px; margin-top: .25rem; min-height: 38px; padding-top: .45rem; padding-bottom: .45rem; font-size: .9rem; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .84rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.lg { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.lg-worked { background: #cbd5e1; }
.lg-invoiced { background: #fbbf24; }
.lg-received { background: var(--primary); }
.chart-wrap { width: 100%; overflow: hidden; }
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: #eef0f5; stroke-width: 1; }
.chart-axis { fill: #94a3b8; font-size: 12px; font-family: var(--font); }
.bar { transition: opacity .15s; }
.bar:hover { opacity: .75; }
.s-worked { fill: #cbd5e1; }
.s-invoiced { fill: #fbbf24; }
.s-received { fill: var(--primary); }
.share { display: flex; align-items: center; gap: .6rem; min-width: 150px; }
.share-bar { flex: 1; height: 8px; background: #eef0f5; border-radius: 99px; overflow: hidden; }
.share-bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--violet)); }
.share-bar-alt span { background: linear-gradient(90deg, #10b981, #059669); }
.share-pct { font-size: .8rem; font-weight: 600; color: var(--muted); width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .95rem; }
.rank-top { display: flex; justify-content: space-between; gap: 1rem; }
.rank-top a { color: var(--ink); }
.rank-sub { margin: .1rem 0 .4rem; }

/* =====================================================================
   Logs & settings extras
   ===================================================================== */
.log-levels { margin-bottom: .9rem; }
.log-msg { word-break: break-word; max-width: 560px; }
.log-msg pre { white-space: pre-wrap; font-size: .75rem; background: var(--surface-2); border: 1px solid var(--border); padding: .7rem; border-radius: 8px; max-height: 260px; overflow: auto; }
.log-table td { font-size: .87rem; }
.steps { padding-left: 1.2rem; margin: 0 0 1rem; }
.steps li { margin-bottom: .6rem; }
.test-mail { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* =====================================================================
   Invoice document (screen + A4 print)
   ===================================================================== */
.invoice-doc {
  --inv-ink: #111827; --inv-soft: #6b7280; --inv-line: #e7e9f0; --inv-accent: #4f46e5; --inv-accent-2: #7c3aed; --inv-tint: #f5f6fb;
  position: relative; background: #fff; color: var(--inv-ink); max-width: 820px; margin: 0 auto;
  padding: 0 52px 40px; font: 13px/1.55 var(--font); overflow: hidden;
}
.inv-band { height: 8px; margin: 0 -52px 38px; background: linear-gradient(90deg, var(--inv-accent), var(--inv-accent-2) 60%, #c084fc); }
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem; margin-bottom: 34px; }
.inv-brand { display: flex; gap: 14px; align-items: flex-start; max-width: 60%; }
.inv-logo { max-height: 60px; max-width: 180px; display: block; }
.inv-monogram {
  display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--inv-accent), var(--inv-accent-2)); color: #fff;
  font: 600 18px/1 var(--serif); letter-spacing: .04em;
}
.inv-biz-name { font: 600 19px/1.25 var(--serif); color: var(--inv-ink); margin-bottom: 4px; letter-spacing: -.005em; }
.inv-biz { color: var(--inv-soft); font-size: 12px; line-height: 1.5; }
.inv-title-block { text-align: right; }
.inv-title { font: 400 44px/1 var(--serif); letter-spacing: -.02em; color: var(--inv-ink); }
.inv-number { margin-top: 8px; font-size: 13px; font-weight: 600; letter-spacing: .14em; color: var(--inv-accent); text-transform: uppercase; }
.draft-mark { color: #9333ea; letter-spacing: .2em; }
.inv-pill { display: inline-block; margin-top: 10px; font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; padding: 3px 10px; border-radius: 99px; border: 1px solid currentColor; }
.inv-pill-paid { color: #047857; }
.inv-pill-unpaid, .inv-pill-partial { color: #b45309; }
.inv-pill-overdue { color: #b91c1c; }

.inv-meta { display: grid; grid-template-columns: 1.4fr 1fr 1.15fr; gap: 22px; margin-bottom: 30px; align-items: stretch; }
.inv-label { font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--inv-soft); margin-bottom: 5px; }
.inv-client { font: 600 16px/1.3 var(--serif); color: var(--inv-ink); margin-bottom: 2px; }
.inv-soft { color: var(--inv-soft); }
.inv-strong { font-weight: 600; color: var(--inv-ink); }
.inv-dates { display: grid; gap: 10px; align-content: start; }
.inv-due-card { background: linear-gradient(135deg, #111827, #1e1b4b); color: #fff; border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; justify-content: center; }
.inv-due-card .inv-label { color: #a5b4fc; }
.inv-due-amount { font: 500 26px/1.15 var(--serif); letter-spacing: -.01em; overflow-wrap: anywhere; }
.inv-due-sub { font-size: 11.5px; color: #c7d2fe; margin-top: 4px; }

.inv-lines { width: 100%; border-collapse: collapse; }
.inv-lines th { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--inv-soft); text-align: left; padding: 10px 10px; border-bottom: 1.5px solid var(--inv-ink); }
.inv-lines td { padding: 10px; border-bottom: 1px solid var(--inv-line); vertical-align: top; }
.inv-lines .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-lines .c-date { white-space: nowrap; width: 92px; color: var(--inv-soft); }
.inv-lines .c-qty { width: 62px; }
.inv-lines .c-rate { width: 96px; }
.inv-lines .c-amt { width: 116px; }
.inv-amt { font-weight: 600; }
.inv-fixed { font-size: 10.5px; color: var(--inv-soft); letter-spacing: .06em; text-transform: uppercase; }
.inv-project td { padding-top: 16px; padding-bottom: 8px; font: 600 14px/1.3 var(--serif); color: var(--inv-ink); border-bottom: 1px solid var(--inv-line); }
.inv-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--inv-accent); margin-right: 8px; vertical-align: middle; position: relative; top: -1px; }
.inv-end-client { font: italic 400 12.5px var(--serif); color: var(--inv-soft); }
.inv-subtotal td { font-size: 12px; font-weight: 600; color: var(--inv-soft); background: var(--inv-tint); border-bottom: 0; }
.inv-subtotal td:first-child { text-align: right; }
.inv-subtotal .num { color: var(--inv-ink); }

.inv-summary { display: grid; grid-template-columns: 1fr 300px; gap: 30px; margin-top: 24px; align-items: start; }
.inv-notes { display: grid; gap: 16px; font-size: 12.5px; color: #374151; }
.inv-block { page-break-inside: avoid; }
.inv-pay { background: var(--inv-tint); border-left: 3px solid var(--inv-accent); border-radius: 0 10px 10px 0; padding: 12px 14px; }
.inv-totals { font-variant-numeric: tabular-nums; }
.inv-trow { display: flex; justify-content: space-between; gap: 1rem; padding: 7px 2px; font-size: 12.5px; }
.inv-trow.inv-soft { color: var(--inv-soft); }
.inv-total { border-top: 1px solid var(--inv-line); font-weight: 600; font-size: 13.5px; padding-top: 10px; }
.inv-paid { color: #047857; }
.inv-balance { margin-top: 8px; padding: 12px 14px; border-radius: 10px; background: linear-gradient(135deg, var(--inv-accent), var(--inv-accent-2)); color: #fff; font-weight: 700; font-size: 15px; }
.inv-terms { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--inv-line); font-size: 11.5px; color: var(--inv-soft); page-break-inside: avoid; }
.inv-footer { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--inv-line); display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; font-size: 11.5px; }
.inv-thanks { font: italic 400 16px/1.2 var(--serif); color: var(--inv-ink); }
.inv-stamp {
  position: absolute; top: 150px; right: 40px; transform: rotate(-14deg);
  font: 700 38px/1 var(--serif); letter-spacing: .18em; text-transform: uppercase;
  color: rgba(5, 150, 105, .16); border: 4px solid rgba(5, 150, 105, .16); border-radius: 12px; padding: 8px 20px; pointer-events: none;
}
.inv-stamp-draft { color: rgba(147, 51, 234, .12); border-color: rgba(147, 51, 234, .12); }

/* Print page (standalone) */
body.print-page { background: #e6e8ef; }
.print-toolbar { position: sticky; top: 0; z-index: 10; display: flex; gap: .7rem; align-items: center; padding: .7rem max(16px, calc((100% - 820px) / 2)); background: rgba(230, 232, 239, .9); backdrop-filter: blur(8px); border-bottom: 1px solid #d6d9e3; }
.print-sheet { padding: 28px 16px 60px; overflow-x: auto; }
.print-sheet .invoice-doc { box-shadow: var(--shadow-lg); border-radius: 6px; min-width: 640px; }

@page { size: A4; margin: 10mm 0 12mm; }
@media print {
  html, body, body.print-page { background: #fff !important; }
  .no-print, .print-toolbar, .sidebar, .mobilebar, .portalbar { display: none !important; }
  .print-sheet { padding: 0; overflow: visible; }
  .invoice-doc { max-width: none; min-width: 0 !important; width: 210mm; box-shadow: none !important; border-radius: 0 !important; padding: 0 16mm 14mm; font-size: 11.5px; }
  .inv-band { margin: 0 -16mm 10mm; height: 2.5mm; }
  .inv-lines tr, .inv-summary, .inv-footer { page-break-inside: avoid; }
  .inv-lines thead { display: table-header-group; }
  a { color: inherit; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .invoice-layout { grid-template-columns: 1fr; }
  .invoice-layout aside { position: static; }
  .cost-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .f-desc { grid-column: span 2; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open { overflow: hidden; }
  .sidebar-close { display: inline-grid; }
  .nav-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; display: block; }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .mobilebar {
    display: flex; align-items: center; gap: .7rem; position: sticky; top: 0; z-index: 20;
    padding: .6rem 16px; padding-top: max(.6rem, env(safe-area-inset-top));
    background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
  }
  .mobilebar-brand { flex: 1; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .container { padding: 1.2rem 16px 3rem; }
  .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { flex-direction: column; align-items: stretch; }
  .segmented-tabs { overflow-x: auto; }
  .period-nav { justify-content: space-between; }
  .filter-form > label { flex: 1; }
  .filter-form input, .filter-form select { min-width: 0; }
}

@media (max-width: 720px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 1.05rem 1rem; border-radius: 12px; }
  .grid-2, .form-grid, .row-2, .due-row { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .stats { grid-template-columns: 1fr; gap: .7rem; }
  .stats-4, .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
  .stat-value, .kpi-value { font-size: 1.2rem; }
  .page-head { align-items: stretch; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .hide-sm { display: none; }
  .portalbar-inner { padding: .7rem 16px; }
  .cost-fields { grid-template-columns: 1fr 1fr; }
  .doc-frame { padding: 10px; margin: 0 -4px; }
  .print-sheet { padding: 12px 8px 40px; }
  .inline-form label { min-width: 0; flex-basis: 100%; }
  .copy-row { flex-wrap: wrap; }

  /* Tables become stacked cards */
  .table:not(.no-stack) thead { display: none; }
  .table:not(.no-stack), .table:not(.no-stack) tbody, .table:not(.no-stack) tfoot, .table:not(.no-stack) tr, .table:not(.no-stack) td { display: block; width: 100%; }
  .table:not(.no-stack) tr { border: 1px solid var(--border); border-radius: 12px; padding: .35rem .8rem; margin-bottom: .7rem; background: var(--surface); }
  .table:not(.no-stack) tbody tr:hover { background: var(--surface); }
  .table:not(.no-stack) td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed var(--border); text-align: right; }
  .table:not(.no-stack) tr td:last-child { border-bottom: 0; }
  .table:not(.no-stack) td::before { content: attr(data-label); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left; flex-shrink: 0; }
  .table:not(.no-stack) td[data-label=""]::before { display: none; }
  .table:not(.no-stack) td[data-label=""] { justify-content: flex-end; }
  .table:not(.no-stack) td:first-child { font-weight: 600; }
  .table:not(.no-stack) .num { white-space: normal; }
  .table:not(.no-stack) tfoot tr { background: var(--surface-2); }
  .share { min-width: 0; flex: 1; max-width: 60%; }
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
  .sticky-actions .btn { flex: 1; }
}

@media (max-width: 420px) {
  .kpis, .stats-4 { grid-template-columns: 1fr; }
  .cost-fields { grid-template-columns: 1fr; }
  .f-desc { grid-column: auto; }
  .plain-box { padding: 1.5rem 1.2rem; }
  .segmented-tabs a { padding: .4rem .65rem; font-size: .82rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* =====================================================================
   Due countdown, read receipts, messages, receipts
   ===================================================================== */
.due-pill { display: inline-flex; align-items: center; font: 600 .72rem/1 var(--font); padding: .32rem .6rem; border-radius: 99px; white-space: nowrap; letter-spacing: .01em; }
.due-ok { background: #eef2ff; color: #3730a3; }
.due-soon { background: #fff4e0; color: #9a5b00; }
.due-late { background: #fde8e6; color: #b42318; }
.viewed { display: inline-block; margin-left: .35rem; font-size: .7rem; font-weight: 600; padding: .1rem .45rem; border-radius: 6px; background: #f1f5f9; color: var(--faint); }
.viewed.is-viewed { background: #ecfdf5; color: var(--good); }
.issue-form { display: inline-flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.card-accent { border-left: 4px solid var(--primary); }
.msg-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.msg-list li { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.activity { list-style: none; margin: 0 0 1rem; padding: 0; }
.activity li { position: relative; display: flex; gap: .75rem; padding: 0 0 .9rem; }
.activity li::before { content: ""; position: absolute; left: 5px; top: 14px; bottom: 0; width: 2px; background: var(--border); }
.activity li:last-child::before { display: none; }
.act-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); margin-top: 4px; flex-shrink: 0; position: relative; z-index: 1; }
.activity li.done .act-dot { border-color: var(--good); background: var(--good); box-shadow: 0 0 0 3px var(--good-50); }
.pay-links { margin-top: .25rem; }

.thread { display: grid; gap: .8rem; margin-bottom: 1rem; max-height: 420px; overflow-y: auto; padding-right: .2rem; }
.msg { max-width: 88%; }
.msg-mine { margin-left: auto; text-align: right; }
.msg-bubble { display: inline-block; text-align: left; padding: .65rem .85rem; border-radius: 14px 14px 14px 4px; background: var(--surface-2); border: 1px solid var(--border); font-size: .92rem; overflow-wrap: anywhere; }
.msg-mine .msg-bubble { background: var(--primary); border-color: var(--primary); color: #fff; border-radius: 14px 14px 4px 14px; }
.msg-meta { font-size: .72rem; color: var(--muted); margin-top: .25rem; }
.thread-empty { margin-bottom: .8rem; }
.thread-form textarea { min-height: 80px; }

.doc-messages { max-width: 820px; margin: 0 auto 60px; background: #fff; border-radius: 14px; padding: 1.4rem 1.5rem; box-shadow: var(--shadow); }
.doc-messages-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.doc-messages h2 { font: 500 1.2rem/1.2 var(--serif); margin: 0; }

.devices-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .8rem 0 .4rem; padding: .6rem .75rem; border-radius: 10px; background: var(--surface-2); }
label.remember { font-weight: 500; font-size: .88rem; color: var(--muted); }

/* Receipt document (shares the invoice styles) */
.inv-band-green { background: linear-gradient(90deg, #059669, #10b981 60%, #6ee7b7); }
.rcpt-hero { display: flex; align-items: center; gap: 18px; padding: 22px 24px; margin-bottom: 28px; border-radius: 14px; background: linear-gradient(135deg, #ecfdf5, #f0fdf9); border: 1px solid #c9f0dc; }
.rcpt-check { width: 52px; height: 52px; border-radius: 50%; background: #059669; color: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 700; flex-shrink: 0; }
.rcpt-amount { font: 400 34px/1.1 var(--serif); color: var(--inv-ink); margin: 2px 0; }
.rcpt-meta { grid-template-columns: 1fr 1fr; }
.rcpt-rows > div { display: flex; justify-content: space-between; gap: 1rem; padding: 6px 0; border-bottom: 1px solid var(--inv-line); }
.rcpt-rows .inv-label { margin: 0; }
.inv-balance-green { background: linear-gradient(135deg, #059669, #10b981) !important; }

/* Dark mode: PIN/login pages follow the device setting */
@media (prefers-color-scheme: dark) {
  body.plain {
    --surface: #1a1b1f; --surface-2: #16171a; --ink: #f2f0ea; --text: #d4d2cc; --muted: #9a99a1; --border: #2a2b31; --border-strong: #3a3b43;
    color-scheme: dark; color: var(--text);
    background: radial-gradient(1000px 520px at 10% -10%, #1e1d3d 0%, transparent 60%), radial-gradient(800px 460px at 110% 110%, #2a1f3d 0%, transparent 55%), #0f1012;
  }
  body.plain input { background: #111214; color: var(--ink); }
  body.plain .plain-box { box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .7); }
  body.plain .flash-error { background: #2c1414; border-color: #5a2323; color: #ffb4a8; }
  body.plain .flash-success { background: #10261c; border-color: #1f4d36; color: #9be3bd; }
}

/* =====================================================================
   Dashboard: quick add cost
   ===================================================================== */
.quick-cost { border-top: 3px solid var(--primary); position: relative; }
.qc-head h2 { margin-bottom: .2rem; }
.qc-head p { margin-bottom: 1rem; }
kbd { font: 600 .75rem var(--mono); padding: .1rem .4rem; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); color: var(--ink); }
.qc-search { position: relative; }
.qc-search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.qc-search input { margin: 0; padding-left: 2.6rem; min-height: 48px; font-size: 1rem; border-radius: 12px; }
.qc-results { list-style: none; margin: .5rem 0 0; padding: .35rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-lg); max-height: 380px; overflow-y: auto; }
.qc-label { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: .45rem .7rem .3rem; }
.qc-item { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: .6rem .75rem; border-radius: 9px; cursor: pointer; }
.qc-item.active { background: var(--primary-50); }
.qc-item-main { min-width: 0; }
.qc-item-name { font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: .5rem; overflow-wrap: anywhere; }
.qc-item-sub { font-size: .8rem; color: var(--muted); }
.qc-item-side { text-align: right; flex-shrink: 0; }
.qc-item-amt { font-weight: 600; font-size: .88rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.qc-empty { padding: .8rem; color: var(--muted); font-size: .9rem; }
.qc-selected { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .8rem 1rem; margin-bottom: 1rem; border-radius: 12px; background: var(--primary-50); border: 1px solid var(--primary-100); }
.qc-proj { font-weight: 700; color: var(--ink); font-size: 1.02rem; }
.qc-selected-actions { display: flex; gap: .4rem; }
@media (max-width: 720px) {
  .qc-item { flex-direction: column; align-items: flex-start; gap: .2rem; }
  .qc-item-side { text-align: left; }
  .qc-head p kbd, .qc-head p { font-size: .82rem; }
}

/* Cancelled costs */
.badge-cancelled { background: #f1f5f9; color: #64748b; text-decoration: none; }
.is-cancelled td { color: var(--faint); }
.is-cancelled td.num { text-decoration: line-through; }
.is-cancelled td:nth-child(2) { text-decoration: line-through; text-decoration-color: rgba(100, 116, 139, .5); }
.cancel-check { display: flex; align-items: flex-start; gap: .2rem; margin-top: 1rem; padding: .8rem 1rem; border: 1px dashed var(--border-strong); border-radius: 12px; background: var(--surface-2); }
.cancel-check input { margin-top: .2rem; }
.cancel-check .hint { display: block; }
.p-btn-csv { font-size: .76rem; letter-spacing: .04em; padding: .5rem .7rem; }

/* =====================================================================
   Client portal (v3): modern, airy, bento layout
   ===================================================================== */
body.portal {
  --m-bg: #f5f6fb; --m-card: #ffffff; --m-ink: #0b1020; --m-text: #334155; --m-soft: #64748b; --m-faint: #94a3b8;
  --m-line: #e8eaf2; --m-hover: #f8f9fd; --m-accent: #5b5bf6; --m-accent-soft: #eef0ff;
  --m-radius: 22px; --m-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px -12px rgba(15, 23, 42, .10);
  background: var(--m-bg); color: var(--m-text); font-size: 15px;
  background-image:
    radial-gradient(600px 300px at 12% -60px, rgba(91, 91, 246, .16), transparent 70%),
    radial-gradient(520px 280px at 88% -40px, rgba(219, 39, 119, .10), transparent 70%),
    radial-gradient(520px 320px at 60% 0, rgba(6, 182, 212, .08), transparent 70%);
  background-repeat: no-repeat;
}
body.portal .flash { border-radius: 16px; }

/* Floating glass header */
.m-top { position: sticky; top: 12px; z-index: 30; padding: 0 16px; }
.m-top-inner {
  max-width: 1120px; margin: 12px auto 0; display: flex; align-items: center; gap: 1rem;
  padding: .55rem .6rem .55rem .9rem; border-radius: 999px;
  background: rgba(255, 255, 255, .72); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border: 1px solid rgba(232, 234, 242, .9); box-shadow: 0 8px 30px -14px rgba(15, 23, 42, .25);
}
.p-brand { display: flex; align-items: center; gap: .65rem; flex: 1; min-width: 0; }
.p-brand-logo { height: 30px; width: auto; max-width: 130px; }
.p-brand-name { font-weight: 700; color: var(--m-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.m-mono { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; color: #fff; font-weight: 800; font-size: .8rem; background: linear-gradient(135deg, #4f46e5, #7c3aed 60%, #db2777); box-shadow: 0 6px 16px -6px rgba(124, 58, 237, .6); }
.m-user { display: flex; align-items: center; gap: .55rem; min-width: 0; padding: .25rem .8rem .25rem .3rem; border-radius: 999px; background: var(--m-bg); }
.m-avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--m-accent-soft); color: var(--m-accent); font-weight: 800; font-size: .72rem; flex-shrink: 0; }
.m-user-name { font-size: .86rem; font-weight: 600; color: var(--m-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.m-icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--m-line); background: var(--m-card); color: var(--m-soft); cursor: pointer; transition: all .15s; }
.m-icon-btn:hover { color: var(--m-ink); border-color: var(--m-ink); }
.p-main { max-width: 1120px; margin: 0 auto; padding: 2rem 16px 3rem; }

/* Bento hero */
.m-bento { display: grid; grid-template-columns: 1.25fr 1fr; grid-template-areas: "welcome balance" "tiles tiles"; gap: 1rem; margin-bottom: 1.25rem; }
.m-welcome { grid-area: welcome; background: var(--m-card); border: 1px solid var(--m-line); border-radius: var(--m-radius); padding: 1.8rem 1.9rem; box-shadow: var(--m-shadow); display: flex; flex-direction: column; justify-content: center; }
.m-eyebrow { font-size: .78rem; font-weight: 700; color: var(--m-accent); text-transform: uppercase; letter-spacing: .1em; }
.m-title { font: 800 clamp(1.8rem, 3.6vw, 2.5rem)/1.1 var(--font); letter-spacing: -.035em; color: var(--m-ink); margin: .45rem 0 .55rem; display: block; }
.m-lead { color: var(--m-soft); margin: 0 0 1.1rem; font-size: 1rem; max-width: 42ch; }
.m-chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.m-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .42rem .8rem; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--m-bg); color: var(--m-text); border: 1px solid var(--m-line); }
.m-chip-bad { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.m-chip-good { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.m-chip-accent { background: var(--m-accent-soft); color: var(--m-accent); border-color: #d9dcff; }

.m-balance {
  grid-area: balance; position: relative; overflow: hidden; border-radius: var(--m-radius); padding: 1.6rem 1.7rem; color: #fff;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #db2777 115%);
  box-shadow: 0 24px 50px -22px rgba(124, 58, 237, .7); display: flex; flex-direction: column; justify-content: space-between; min-height: 200px;
}
.m-balance::before { content: ""; position: absolute; width: 320px; height: 320px; right: -110px; top: -150px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .28), transparent 62%); }
.m-balance::after { content: ""; position: absolute; width: 220px; height: 220px; left: -80px; bottom: -120px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .14), transparent 65%); }
.m-balance.is-overdue { background: linear-gradient(135deg, #e11d48 0%, #be123c 55%, #7f1d1d 120%); box-shadow: 0 24px 50px -22px rgba(225, 29, 72, .6); }
.m-balance.is-clear { background: linear-gradient(135deg, #059669 0%, #0d9488 60%, #0891b2 120%); box-shadow: 0 24px 50px -22px rgba(5, 150, 105, .6); }
.m-balance > * { position: relative; z-index: 1; }
.m-balance-top { display: flex; justify-content: space-between; align-items: center; }
.m-balance-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; opacity: .9; }
.m-balance-icon { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: rgba(255, 255, 255, .18); backdrop-filter: blur(6px); }
.m-balance-amount { font: 800 clamp(2.2rem, 4.6vw, 3.1rem)/1.05 var(--font); letter-spacing: -.035em; margin: 1.1rem 0 .4rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.m-balance-sub { font-size: .92rem; opacity: .9; }

.m-tiles { grid-area: tiles; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.m-tile { background: var(--m-card); border: 1px solid var(--m-line); border-radius: 18px; padding: 1rem 1.1rem; box-shadow: var(--m-shadow); display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: .8rem; align-items: center; }
.m-tile-icon { grid-row: span 2; display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; }
.m-tile-value { font: 800 1.35rem/1.1 var(--font); color: var(--m-ink); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.m-tile-money { font-size: 1.1rem; }
.m-tile-label { font-size: .8rem; color: var(--m-soft); font-weight: 500; }
.t-indigo { background: #eef0ff; color: #4f46e5; }
.t-green { background: #e7f8f0; color: #059669; }
.t-amber { background: #fff4e0; color: #d97706; }
.t-violet { background: #f3ecff; color: #7c3aed; }

/* Cards */
.m-card { background: var(--m-card); border: 1px solid var(--m-line); border-radius: var(--m-radius); padding: 1.5rem 1.6rem; margin-bottom: 1.25rem; box-shadow: var(--m-shadow); }
.m-card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.m-head-title { display: flex; align-items: center; gap: .85rem; }
.m-card-icon { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0; }
.m-h2 { font: 700 1.1rem/1.25 var(--font); letter-spacing: -.015em; color: var(--m-ink); margin: 0; }
.m-sub { color: var(--m-soft); font-size: .84rem; margin: .15rem 0 0; }
.m-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.25rem; align-items: start; }
.m-grid > .m-card { margin-bottom: 1.25rem; }

.m-pay { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; background: linear-gradient(90deg, #f0fdf7, var(--m-card) 60%); border-color: #d1f2e2; }
.m-pay-body { flex: 1; min-width: 220px; }
.m-pay .m-h2 { font-size: 1rem; margin-bottom: .25rem; }
.m-pay-details { font-size: .95rem; color: var(--m-ink); font-weight: 500; }
.m-pay-hint { font-size: .85rem; color: var(--m-soft); max-width: 320px; padding: .7rem .9rem; border-radius: 14px; background: var(--m-card); border: 1px dashed #bfe9d4; }
.m-pay-hint b { color: var(--m-ink); }

/* Search + sort */
.p-toolbar { display: flex; gap: .7rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.p-search { position: relative; flex: 1; min-width: 220px; margin: 0; }
.p-search .icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--m-faint); pointer-events: none; }
.p-search input { margin: 0; padding-left: 2.8rem; border-radius: 16px; border-color: var(--m-line); background: var(--m-bg); min-height: 48px; font-size: .95rem; }
.p-search input:focus { background: var(--m-card); border-color: var(--m-accent); box-shadow: 0 0 0 4px rgba(91, 91, 246, .12); }
.p-sort { margin: 0; }
.p-sort select { margin: 0; border-radius: 16px; border-color: var(--m-line); background-color: var(--m-bg); min-height: 48px; padding-left: 1rem; font-weight: 600; font-size: .9rem; }
.p-results { transition: opacity .15s; }
.p-results.is-loading { opacity: .45; }
.p-empty { text-align: center; color: var(--m-soft); padding: 2rem 1rem; border: 1.5px dashed var(--m-line); border-radius: 18px; background: var(--m-bg); line-height: 1.7; font-size: .92rem; }
.p-empty strong { color: var(--m-ink); font-size: 1.02rem; }

/* Project accordions */
.p-accordions { display: grid; gap: .7rem; }
.p-acc { border: 1px solid var(--m-line); border-radius: 18px; background: var(--m-card); transition: border-color .15s, box-shadow .15s, transform .15s; overflow: hidden; }
.p-acc:hover { border-color: #d6d9ea; box-shadow: 0 8px 22px -16px rgba(15, 23, 42, .3); }
.p-acc[open] { border-color: #c9ccfb; box-shadow: 0 14px 34px -20px rgba(91, 91, 246, .45); }
.p-acc summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto 28px; gap: 1rem; align-items: center; padding: .95rem 1.1rem; }
.p-acc summary::-webkit-details-marker { display: none; }
.p-acc summary:focus-visible { outline: 3px solid rgba(91, 91, 246, .3); outline-offset: -3px; border-radius: 18px; }
.m-proj-avatar { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; font-weight: 800; font-size: .85rem; letter-spacing: .02em; }
.m-proj-avatar.c0 { background: #eef0ff; color: #4f46e5; }
.m-proj-avatar.c1 { background: #fff4e0; color: #d97706; }
.m-proj-avatar.c2 { background: #e7f8f0; color: #059669; }
.m-proj-avatar.c3 { background: #fdeef6; color: #db2777; }
.m-proj-avatar.c4 { background: #e6f7fb; color: #0891b2; }
.m-proj-avatar.c5 { background: #f3ecff; color: #7c3aed; }
.p-acc-title { min-width: 0; }
.p-acc-name { display: block; font-weight: 700; font-size: 1rem; color: var(--m-ink); letter-spacing: -.01em; overflow-wrap: anywhere; }
.p-acc-meta { display: block; font-size: .8rem; color: var(--m-soft); margin-top: .12rem; }
.p-acc-figures { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.p-chip { display: inline-flex; gap: .35rem; align-items: baseline; font-size: .74rem; font-weight: 600; padding: .3rem .65rem; border-radius: 999px; white-space: nowrap; }
.p-chip b { font-weight: 800; }
.p-chip-due { background: #fff1e6; color: #c2410c; }
.p-chip-soft { background: #f1f3f9; color: #475569; }
.p-acc-amount { font-weight: 800; font-size: 1.12rem; color: var(--m-ink); white-space: nowrap; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.p-acc-chevron { width: 28px; height: 28px; border-radius: 50%; background: var(--m-bg); color: var(--m-soft); transition: transform .2s, background .2s, color .2s; display: grid; place-items: center; }
.p-acc[open] .p-acc-chevron { transform: rotate(90deg); background: var(--m-accent); color: #fff; }
.p-acc-body { border-top: 1px solid var(--m-line); padding: .3rem 1.1rem 1rem 1.1rem; background: #fbfbfe; }
.p-items { display: grid; }
.p-item { display: grid; grid-template-columns: 100px minmax(0, 1fr) auto; gap: 1rem; padding: .85rem 0; border-bottom: 1px dashed var(--m-line); align-items: start; }
.p-item:last-child { border-bottom: 0; }
.p-item-date { font-size: .8rem; color: var(--m-soft); padding-top: .1rem; white-space: nowrap; font-weight: 500; }
.p-item-desc { color: var(--m-ink); font-size: .93rem; overflow-wrap: anywhere; }
.p-item-sub { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .35rem; font-size: .77rem; color: var(--m-soft); }
.p-item-amt { font-weight: 700; color: var(--m-ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.p-acc-foot { margin-top: .6rem; padding: .6rem .85rem; border-radius: 12px; background: #ecfdf5; color: #047857; font-size: .84rem; font-weight: 500; }

/* Pagination */
.p-pager { display: flex; justify-content: center; align-items: center; gap: .35rem; margin-top: 1.2rem; flex-wrap: wrap; }
.p-page { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 .6rem; border-radius: 12px; border: 1px solid var(--m-line); background: var(--m-card); color: var(--m-ink); font-weight: 700; font-size: .86rem; }
.p-page:hover { border-color: var(--m-accent); color: var(--m-accent); }
.p-page.active { background: var(--m-accent); border-color: var(--m-accent); color: #fff; box-shadow: 0 6px 16px -8px rgba(91, 91, 246, .7); }
.p-page-gap { color: var(--m-faint); padding: 0 .2rem; }
.p-count { text-align: center; color: var(--m-faint); font-size: .8rem; margin: .9rem 0 0; }

/* Invoices */
.m-invoices { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.m-inv { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 1rem; align-items: center; padding: .9rem 1rem; border: 1px solid var(--m-line); border-radius: 16px; transition: background .15s, border-color .15s; }
.m-inv:hover { background: var(--m-hover); border-color: #d6d9ea; }
.m-inv.is-paid { opacity: .85; }
.m-inv-top { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.m-inv-no { color: var(--m-ink); font-weight: 800; letter-spacing: -.01em; }
.m-inv-sub { font-size: .79rem; color: var(--m-soft); margin-top: .15rem; }
.m-inv-amt { text-align: right; white-space: nowrap; }
.m-inv-money { font-weight: 800; color: var(--m-ink); font-variant-numeric: tabular-nums; font-size: 1.02rem; letter-spacing: -.01em; }
.m-inv-actions { display: flex; gap: .35rem; }
.m-act { display: inline-flex; align-items: center; gap: .35rem; height: 36px; padding: 0 .7rem; border-radius: 11px; border: 1px solid var(--m-line); background: var(--m-card); color: var(--m-text); font-size: .8rem; font-weight: 700; transition: all .15s; }
.m-act:hover { border-color: var(--m-accent); color: var(--m-accent); }
.m-act-primary { background: var(--m-ink); border-color: var(--m-ink); color: #fff; }
.m-act-primary:hover { background: var(--m-accent); border-color: var(--m-accent); color: #fff; }
.m-inv .due-pill { font-size: .68rem; padding: .26rem .55rem; }

/* Payments timeline */
.m-timeline { list-style: none; margin: 0; padding: 0; }
.m-timeline li { position: relative; display: flex; gap: .85rem; padding: 0 0 1.1rem; }
.m-timeline li::before { content: ""; position: absolute; left: 11px; top: 26px; bottom: 2px; width: 2px; background: var(--m-line); }
.m-timeline li:last-child::before { display: none; }
.m-tl-dot { width: 24px; height: 24px; border-radius: 50%; background: #e7f8f0; color: #059669; display: grid; place-items: center; flex-shrink: 0; position: relative; z-index: 1; }
.m-tl-main { flex: 1; min-width: 0; }
.m-tl-top { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.m-tl-top b { color: var(--m-ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.m-link { display: inline-block; margin-top: .3rem; font-size: .78rem; font-weight: 700; color: var(--m-accent); }

/* Spend chart */
.m-spend { display: flex; gap: 1.6rem; }
.m-spend div { display: flex; flex-direction: column; align-items: flex-end; }
.m-spend span { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--m-soft); font-weight: 700; }
.m-spend b { font-weight: 800; font-size: 1.25rem; color: var(--m-ink); letter-spacing: -.02em; }
.s-portal { fill: #6d6af8; }
.p-chart .bar.s-portal:hover { fill: #db2777; opacity: 1; }
.p-footer { margin-top: 2.2rem; padding: 1.2rem 0 0; border-top: 1px solid var(--m-line); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--m-soft); }
.p-footer a { color: var(--m-accent); font-weight: 600; }
.p-btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .95rem; min-height: 38px; border-radius: 12px; border: 1px solid var(--m-line); background: var(--m-card); color: var(--m-ink); font-weight: 700; font-size: .85rem; cursor: pointer; }

/* Responsive */
@media (max-width: 900px) {
  .m-bento { grid-template-columns: 1fr; grid-template-areas: "welcome" "balance" "tiles"; }
  .m-grid { grid-template-columns: 1fr; }
  .p-acc summary { grid-template-columns: 44px minmax(0, 1fr) auto 28px; }
  .p-acc-figures { grid-column: 2 / -1; grid-row: 2; justify-content: flex-start; }
}
@media (max-width: 600px) {
  .m-top { top: 8px; padding: 0 10px; }
  .m-top-inner { margin-top: 8px; }
  .p-main { padding: 1.4rem 12px 2.4rem; }
  .m-welcome, .m-card { padding: 1.2rem 1.1rem; border-radius: 18px; }
  .m-balance { padding: 1.3rem 1.3rem; border-radius: 18px; min-height: 0; }
  .m-tiles { grid-template-columns: 1fr 1fr; gap: .7rem; }
  .m-tile { grid-template-columns: 1fr; row-gap: .35rem; }
  .m-tile-icon { grid-row: auto; width: 36px; height: 36px; }
  .p-acc summary { padding: .85rem .9rem; gap: .7rem; grid-template-columns: 38px minmax(0, 1fr) 24px; }
  .m-proj-avatar { width: 38px; height: 38px; border-radius: 12px; font-size: .78rem; }
  .p-acc-amount { grid-column: 2; grid-row: 3; font-size: 1rem; }
  .p-acc-chevron { grid-column: 3; grid-row: 1; }
  .p-acc-body { padding: .2rem .9rem .9rem; }
  .p-item { grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .8rem; }
  .p-item-date { grid-column: 1 / -1; }
  .m-inv { grid-template-columns: minmax(0, 1fr) auto; padding: .85rem .9rem; }
  .m-inv-actions { grid-column: 1 / -1; }
  .m-act { flex: 1; justify-content: center; }
  .p-sort, .p-sort select { width: 100%; }
  .p-footer { flex-direction: column; }
  .m-spend b { font-size: 1.05rem; }
}

/* Dark mode for the client portal */
@media (prefers-color-scheme: dark) {
  body.portal {
    --m-bg: #0b0d14; --m-card: #13161f; --m-ink: #f1f3fa; --m-text: #c6cbd8; --m-soft: #8b93a7; --m-faint: #5f6780;
    --m-line: #232838; --m-hover: #181c27; --m-accent: #8b8cff; --m-accent-soft: #1e2046;
    --m-shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
    background-image:
      radial-gradient(600px 300px at 12% -60px, rgba(91, 91, 246, .22), transparent 70%),
      radial-gradient(520px 280px at 88% -40px, rgba(219, 39, 119, .14), transparent 70%);
  }
  body.portal .m-top-inner { background: rgba(19, 22, 31, .72); border-color: rgba(35, 40, 56, .9); }
  body.portal .m-chip-bad { background: #2a1215; color: #fda4af; border-color: #4c1d24; }
  body.portal .m-chip-good { background: #0f241c; color: #6ee7b7; border-color: #1c4636; }
  body.portal .m-chip-accent { border-color: #2f3270; }
  body.portal .t-indigo, body.portal .m-proj-avatar.c0 { background: #1e2046; color: #a5a6ff; }
  body.portal .t-green, body.portal .m-proj-avatar.c2, body.portal .m-tl-dot { background: #0f241c; color: #6ee7b7; }
  body.portal .t-amber, body.portal .m-proj-avatar.c1 { background: #2a1f0c; color: #fbbf24; }
  body.portal .t-violet, body.portal .m-proj-avatar.c5 { background: #221638; color: #c4b5fd; }
  body.portal .m-proj-avatar.c3 { background: #2c1222; color: #f9a8d4; }
  body.portal .m-proj-avatar.c4 { background: #0c2530; color: #67e8f9; }
  body.portal .m-pay { background: linear-gradient(90deg, #0f1f19, var(--m-card) 60%); border-color: #1c4636; }
  body.portal .m-pay-hint { border-color: #1c4636; }
  body.portal .p-acc-body { background: #10131b; }
  body.portal .p-chip-due { background: #2a1a0e; color: #fdba74; }
  body.portal .p-chip-soft { background: #1c2130; color: #aab2c5; }
  body.portal .p-acc-foot { background: #0f241c; color: #6ee7b7; }
  body.portal .m-act-primary { background: var(--m-ink); color: #0b0d14; border-color: var(--m-ink); }
  body.portal .m-act-primary:hover { background: var(--m-accent); color: #0b0d14; }
  body.portal .s-portal { fill: #8b8cff; }
  body.portal .chart-grid { stroke: #1f2433; }
  body.portal .flash-success { background: #0f241c; border-color: #1c4636; color: #9be3bd; }
  body.portal .flash-error { background: #2a1215; border-color: #4c1d24; color: #fda4af; }
  body.portal .badge-unbilled, body.portal .badge-muted { background: #1c2130; color: #aab2c5; }
  body.portal .badge-invoiced, body.portal .badge-unpaid { background: #2a1f0c; color: #fbbf24; }
  body.portal .badge-partial { background: #2a260c; color: #fde047; }
  body.portal .badge-paid { background: #0f241c; color: #6ee7b7; }
  body.portal .badge-overdue { background: #2a1215; color: #fda4af; }
  body.portal .due-ok { background: #1e2046; color: #c7c8ff; }
  body.portal .due-soon { background: #2a1f0c; color: #fbbf24; }
  body.portal .due-late { background: #2a1215; color: #fda4af; }
  body.portal .p-search input, body.portal .p-sort select { color: var(--m-ink); }
}

/* Passkeys */
.btn-lg { min-height: 52px; font-size: 1rem; border-radius: 14px; }
.passkey-btn .icon { margin-right: .2rem; }
.login-fallback { border-top: 1px solid var(--border); padding-top: .9rem; }
.login-fallback summary { cursor: pointer; color: var(--muted); font-size: .88rem; font-weight: 600; text-align: center; list-style: none; }
.login-fallback summary::-webkit-details-marker { display: none; }
.login-fallback summary:hover { color: var(--primary); }
.login-fallback[open] summary { margin-bottom: 1rem; }
.passkey-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .6rem; }
.passkey-list li { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: 12px; flex-wrap: wrap; }
.pk-icon { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--good-50); color: var(--good); }
.pk-main { flex: 1; min-width: 180px; }
.pk-delete { display: flex; gap: .4rem; align-items: center; margin: 0; }
.pk-delete input { margin: 0; min-height: 34px; padding: .3rem .6rem; font-size: .85rem; width: 170px; }

/* Dashboard: unbilled work by client */
.ub-grand { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.ub-grand div { display: flex; flex-direction: column; align-items: flex-end; }
.ub-grand span { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ub-grand b { font-size: 1.3rem; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.ub-list { display: grid; gap: .6rem; }
.ub-client { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.ub-client[open] { border-color: var(--primary-100); box-shadow: var(--shadow); }
.ub-client summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto auto 22px; gap: 1rem; align-items: center; padding: .8rem 1rem; }
.ub-client summary::-webkit-details-marker { display: none; }
.ub-client summary:hover { background: var(--surface-2); }
.ub-name { min-width: 0; overflow-wrap: anywhere; }
.ub-name b { color: var(--ink); }
.ub-total { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ub-chevron { color: var(--muted); transition: transform .2s; display: grid; place-items: center; }
.ub-client[open] .ub-chevron { transform: rotate(90deg); color: var(--primary); }
.ub-body { border-top: 1px solid var(--border); padding: .6rem 1rem 1rem; background: #fbfbfe; }
.ub-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .8rem; flex-wrap: wrap; }
@media (max-width: 720px) {
  .ub-client summary { grid-template-columns: minmax(0, 1fr) auto 18px; }
  .ub-meta { grid-column: 1 / -1; grid-row: 2; }
  .ub-grand { width: 100%; justify-content: space-between; }
  .ub-grand div { align-items: flex-start; }
}
