/* ==========================================================================
   MyTaxConsultant Tasks — UI
   Mobile-first · Light / Dark / Auto themes via CSS custom properties
   ========================================================================== */

:root {
  --brand: #0f766e;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --info: #1d4ed8;
  --focus: color-mix(in srgb, var(--brand) 55%, transparent);
  --brand-soft: color-mix(in srgb, var(--brand) 12%, var(--surface));
  --brand-ink: #ffffff;
  --link: var(--brand);
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 1px 3px rgb(15 23 42 / .08);
  --shadow-lg: 0 10px 30px rgb(15 23 42 / .16);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 248px;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --surface-3: #1e293b;
    --border: #1f2937; --border-strong: #334155; --text: #e5e7eb; --text-2: #cbd5e1; --text-3: #94a3b8;
    --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --info: #60a5fa;
    --brand-soft: color-mix(in srgb, var(--brand) 22%, var(--surface));
    --link: color-mix(in srgb, var(--brand) 55%, #fff);
    --shadow: 0 1px 2px rgb(0 0 0 / .4); --shadow-lg: 0 10px 30px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --surface-3: #1e293b;
  --border: #1f2937; --border-strong: #334155; --text: #e5e7eb; --text-2: #cbd5e1; --text-3: #94a3b8;
  --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --info: #60a5fa;
  --brand-soft: color-mix(in srgb, var(--brand) 22%, var(--surface));
  --link: color-mix(in srgb, var(--brand) 55%, #fff);
  --shadow: 0 1px 2px rgb(0 0 0 / .4); --shadow-lg: 0 10px 30px rgb(0 0 0 / .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; font-weight: 650; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin-top: 1rem; }
code, .mono, kbd { font-family: var(--mono); font-size: .9em; }
kbd { padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); font-size: .78em; }
hr { border: 0; border-top: 1px solid var(--border); margin: .4rem 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 6px; }
.skip-link:focus { left: 8px; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-3); }
.small { font-size: .85em; }
.strong { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
.clamp { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tone-bad { color: var(--bad); }
.tone-warn { color: var(--warn); }
.tone-ok { color: var(--ok); }
.empty { text-align: center; padding: 2rem !important; }
.selectable { user-select: all; }
.only-desktop { display: none; }
.row-gap { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.w-xs { width: 70px; } .w-sm { width: 110px; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .2s ease; overflow-y: auto;
  padding: 14px 10px calc(14px + env(safe-area-inset-bottom));
}
body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
.sidebar-backdrop { display: none; }
body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgb(15 23 42 / .45); z-index: 35; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 700; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); font-weight: 800; }
.brand-name { font-size: .98rem; line-height: 1.2; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 4px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2) !important; font-weight: 500; }
.nav-link:hover { background: var(--surface-3); text-decoration: none; }
.nav-link.is-active { background: var(--brand-soft); color: var(--brand) !important; }
.nav-link.is-active { color: var(--link) !important; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 1.05rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.content { padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); width: 100%; max-width: 1600px; margin: 0 auto; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); text-decoration: none; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }
.icon-btn.is-done { color: var(--ok); }

[data-theme-toggle] .ic { display: none; }
:root[data-theme="light"] [data-theme-toggle] .theme-ic-light,
:root[data-theme="dark"] [data-theme-toggle] .theme-ic-dark,
:root[data-theme="auto"] [data-theme-toggle] .theme-ic-auto,
:root:not([data-theme]) [data-theme-toggle] .theme-ic-auto { display: block; }

.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 0; }
.lang-btn { border: 0; background: transparent; color: var(--text-3); padding: 5px 8px; font: 600 .75rem var(--font); cursor: pointer; }
.lang-btn.is-active { background: var(--brand); color: var(--brand-ink); }
.bare-lang { display: flex; justify-content: center; margin-bottom: 12px; }

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .8rem; }
.avatar.xs { width: 22px; height: 22px; font-size: .65rem; }
.menu-pop { position: absolute; right: 0; top: 44px; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; }
.menu-head { padding: 8px 10px; display: flex; flex-direction: column; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-pop a, .menu-pop button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-3); text-decoration: none; }
.menu-pop form { margin: 0; }

/* ---------- Cards & layout grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 14px; align-items: start; }
.dash-grid > .card { margin: 0; }
.grid-2, .grid-3 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.form-card { max-width: 980px; }
.form-card h2 { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.form-card h2:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar-left, .toolbar-right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar form { margin: 0; }
.filters select, .filters input[type="search"], .filters input:not([type]), .filters input[type="date"] { width: auto; min-width: 0; max-width: 100%; }
.summary-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; color: var(--text-2); }
.summary-line form { margin: 0; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; color: var(--text-2); }
.chip strong { color: var(--text); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 3px; gap: 2px; }
.seg-btn { padding: 5px 12px; border-radius: 6px; color: var(--text-2) !important; font-weight: 500; border: 0; background: transparent; font: inherit; cursor: pointer; }
.seg-btn:hover { text-decoration: none; color: var(--text) !important; }
.seg-btn.is-active { background: var(--surface); color: var(--text) !important; box-shadow: var(--shadow); }

/* ---------- Forms ---------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; min-height: 38px;
}
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); padding: 0; }
input[type="color"] { width: 48px; padding: 2px; height: 34px; }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--brand); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-weight: 550; font-size: .85rem; color: var(--text-2); }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; cursor: pointer; }
.check.inline { margin: 0; white-space: nowrap; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.inline-form { margin: 0 0 4px; max-width: 320px; }
.otp-input { font-family: var(--mono); font-size: 1.4rem; letter-spacing: .3em; text-align: center; }
.is-invalid { border-color: var(--bad) !important; }
.is-saving { opacity: .6; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px;
  padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text) !important; font: 550 .9rem var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink) !important; }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff !important; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2) !important; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: .82rem; }
.btn-block { width: 100%; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; }

/* ---------- Badges & pills ---------- */
.badge {
  --c: #64748b; display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: color-mix(in srgb, var(--c) 78%, var(--text));
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.badge.xs { font-size: .68rem; padding: 0 6px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-3); color: var(--text-2); }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, var(--bad) 16%, var(--surface)); color: var(--bad); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c, #64748b); flex: none; }

/* ---------- Alerts & toasts ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; border: 1px solid; }
.alert-success { background: color-mix(in srgb, var(--ok) 10%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert-error { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.alert-warning { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-info { background: color-mix(in srgb, var(--info) 10%, var(--surface)); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.toast-host { position: fixed; bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: .2s; font-weight: 500; }
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--bad); color: #fff; }
.toast-success { background: var(--ok); color: #fff; }
.toast-warning { background: var(--warn); color: #fff; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap.scroll-y { max-height: 420px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 650; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.table tbody tr:hover { background: var(--surface-2); }
.table.compact th, .table.compact td { padding: 6px 10px; }
.table td input, .table td select { min-height: 32px; padding: 4px 8px; }
.sortable-th { cursor: pointer; user-select: none; }
.sortable-th[data-dir="asc"]::after { content: " ▲"; font-size: .7em; }
.sortable-th[data-dir="desc"]::after { content: " ▼"; font-size: .7em; }
.row-actions { white-space: nowrap; text-align: right; }
.row-done td { color: var(--text-3); }
.row-new td { background: var(--surface-2); }
.matrix td:first-child { min-width: 240px; }

/* Responsive tables: stack rows into cards on phones */
@media (max-width: 719px) {
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { border-bottom: 1px solid var(--border); padding: 8px 4px; }
  .table.responsive td { border: 0; padding: 3px 10px; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  .table.responsive td[data-label]::before { content: attr(data-label); color: var(--text-3); font-size: .8rem; text-align: left; flex: none; }
  .table.responsive td.row-actions { justify-content: flex-end; }
  .clamp { max-width: 60vw; }
}

/* ---------- KPIs & dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi-hero { grid-column: 1 / -1; }
.kpi-label { font-size: .78rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.7rem; font-weight: 750; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-value.small { font-size: 1rem; }
.kpi-hero .kpi-value { font-size: 2.3rem; color: var(--link); }

.kpi-sub { font-size: .82rem; color: var(--text-3); }
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .4s; }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }
.stat-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-list > div { display: flex; justify-content: space-between; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 85vw); gap: 12px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory; }
.kanban-col { --c: #64748b; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 210px); scroll-snap-align: start; }
.kanban-col.drop-hover { outline: 2px dashed var(--c); }
.kanban-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 650; border-bottom: 3px solid var(--c); }
.kanban-head .dot { background: var(--c); }
.kanban-head .count { margin-left: auto; font-size: .8rem; color: var(--text-3); background: var(--surface); border-radius: 999px; padding: 0 8px; }
.kanban-list { padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 80px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; box-shadow: var(--shadow); cursor: grab; }
.kcard.is-dragging { opacity: .5; }
.kcard-title { font-weight: 650; color: var(--text) !important; display: block; }
.kcard-sub { font-size: .85rem; color: var(--text-2); }
.kcard-note { font-size: .8rem; color: var(--text-3); margin-top: 4px; border-left: 2px solid var(--border-strong); padding-left: 6px; }
.kcard-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.kcard-foot .avatar { margin-left: auto; }
.kcard-move { margin-top: 8px; min-height: 30px; font-size: .8rem; padding: 3px 6px; }

/* ---------- Sheets (spreadsheet grid) ---------- */
.grid-bar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; align-items: center; }
.sheet-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); outline: none; -webkit-overflow-scrolling: touch; }
.sheet-wrap:focus-visible { outline: 2px solid var(--focus); }
.sheet { border-collapse: separate; border-spacing: 0; table-layout: fixed; min-width: 100%; font-size: .88rem; }
.sheet th { position: sticky; top: 0; z-index: 2; background: var(--surface-3); color: var(--text-2); font-weight: 650; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; padding: 7px 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border-strong); }
.sheet td { height: 34px; padding: 0 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: cell; position: relative; }
.sheet td.ro { color: var(--text-2); }
.sheet td.ro:not(.sel-col) { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.sheet .sel-col { text-align: center; position: sticky; left: 0; z-index: 1; background: var(--surface-2); }
.sheet th.sel-col { z-index: 3; }
.sheet tr.row-selected td { background: var(--brand-soft) !important; }
.sheet td.in-range { background: color-mix(in srgb, var(--info) 12%, var(--surface)) !important; }
.sheet td.is-active { box-shadow: inset 0 0 0 2px var(--brand); }
.sheet td.is-editing { padding: 0; overflow: visible; }
.sheet td.is-saving { opacity: .55; }
.sheet .cell-editor { width: 100%; height: 34px; min-height: 0; border: 0; border-radius: 0; box-shadow: inset 0 0 0 2px var(--brand); padding: 0 8px; outline: none; }
.sheet tr.row-done td:not(.sel-col) { color: var(--text-3); }
.bulkbar { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20; margin: 10px auto 0; width: fit-content; max-width: 100%; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); }
.bulkbar select { width: auto; min-height: 32px; padding: 3px 8px; }

.ctx-menu { position: fixed; z-index: 80; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; }
.ctx-menu button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 6px; font: inherit; color: var(--text); cursor: pointer; }
.ctx-menu button:hover, .ctx-menu button:focus { background: var(--surface-3); }
.ctx-menu kbd { margin-left: auto; }
.ctx-head { padding: 6px 10px; font-size: .78rem; color: var(--text-3); font-weight: 650; border-bottom: 1px solid var(--border); margin-bottom: 4px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-sub { position: relative; }
.ctx-subpanel { display: none; position: absolute; left: 100%; top: -5px; min-width: 200px; max-height: 60vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; }
.ctx-sub:hover > .ctx-subpanel, .ctx-sub:focus-within > .ctx-subpanel { display: block; }
@media (max-width: 719px) { .ctx-subpanel { position: static; box-shadow: none; border: 0; padding-left: 12px; } }

/* ---------- Dialogs & comments ---------- */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 18px; width: min(560px, 94vw); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.dialog.wide { width: min(760px, 96vw); }
.dialog::backdrop { background: rgb(15 23 42 / .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.comments { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-height: 50vh; overflow-y: auto; }
.comment { --depth: 0; margin-left: calc(var(--depth) * 18px); padding: 8px 10px; border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.comment .comment { margin-top: 8px; }
.comment-body { margin: 4px 0; white-space: normal; overflow-wrap: anywhere; }
.cm-form textarea { margin-bottom: 4px; }
.history summary { cursor: pointer; color: var(--text-2); font-weight: 600; padding: 4px 0; }
details.card.history { padding: 12px 16px; }

/* ---------- VAT ---------- */
.summary-chips { gap: 6px; }
.vat-sheet td, .vat-sheet th { white-space: nowrap; }
.vat-sheet .cell-input { min-height: 30px; padding: 3px 6px; width: 110px; border-color: var(--border); }
.vat-sheet .cell-input.mono { width: 170px; }
.vat-sheet .sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 200px; }
.vat-sheet thead .sticky-col { background: var(--surface-2); z-index: 2; }
.stepper { list-style: none; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; counter-reset: s; }
.stepper li { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: .78rem; color: var(--text-3); position: relative; }
.stepper li::before { content: ""; position: absolute; top: 15px; left: -50%; width: 100%; height: 2px; background: var(--border-strong); z-index: 0; }
.stepper li:first-child::before { display: none; }
.stepper li.is-done::before, .stepper li.is-current::before { background: var(--brand); }
.step-num { position: relative; z-index: 1; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-weight: 700; border: 2px solid var(--border-strong); }
.stepper li.is-done .step-num, .wizard-step.is-done .step-num { background: var(--brand); border-color: var(--brand); color: #fff; }
.stepper li.is-current .step-num, .wizard-step.is-current .step-num { border-color: var(--brand); color: var(--brand); background: var(--surface); }
.stepper li.is-current { color: var(--text); font-weight: 600; }
.wizard-step h2 { display: flex; align-items: center; gap: 10px; }
.wizard-step .step-num { width: 26px; height: 26px; font-size: .8rem; }
.wizard-step.is-current { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand), var(--shadow); }
.wizard-step.is-locked { opacity: .65; }
.wizard-step.is-done { background: var(--surface-2); }
.xcheck input { width: 140px; }
.result-box { padding: 14px; border-radius: 8px; background: var(--surface-2); border: 1px dashed var(--border-strong); margin-top: 4px; }
.big { font-size: 1.6rem; }

/* ---------- Email editor ---------- */
.editor-toolbar { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--border-strong); border-bottom: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface-2); }
.editor-toolbar button { border: 1px solid transparent; background: none; border-radius: 4px; min-width: 30px; height: 28px; cursor: pointer; color: var(--text); }
.editor-toolbar button:hover { background: var(--surface-3); }
.editor { min-height: 220px; padding: 12px; border: 1px solid var(--border-strong); border-radius: 0 0 var(--radius-sm) var(--radius-sm); background: var(--surface); overflow-wrap: anywhere; }
.editor.tall { min-height: 320px; }
.editor:focus { outline: 2px solid var(--focus); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font: 500 .78rem var(--mono); padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); cursor: pointer; }
.tag:hover { border-color: var(--brand); color: var(--brand); }
.tabs .seg { margin-bottom: 10px; }
.preview-box { margin-top: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.preview-frame { width: 100%; height: 360px; border: 1px solid var(--border); border-radius: 6px; background: #fff; margin-top: 8px; }

/* ---------- Profile / 2FA ---------- */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 10px; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.qr { width: 200px; max-width: 100%; aspect-ratio: 1; margin: 8px 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.steps-list { padding-left: 1.2rem; color: var(--text-2); }
.pager { display: flex; justify-content: center; gap: 8px; margin: 10px 0; }

/* ---------- Bare (login / setup) ---------- */
body.bare { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.bare-wrap { width: min(440px, 94vw); padding: 24px 0; }
.bare-wrap:has(.wide) { width: min(760px, 94vw); }
.bare-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 1.1rem; margin-bottom: 14px; }
.bare-card { padding: 24px; }
.bare-card h1 { font-size: 1.3rem; }
.err-code { font-size: 3rem; color: var(--brand); margin: 0; }
pre.keys { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: .82rem; user-select: all; }

/* ---------- Breakpoints (mobile-first) ---------- */
@media (min-width: 560px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .stat-list { grid-template-columns: repeat(4, 1fr); }
  .content { padding: 18px 18px 32px; }
}
@media (min-width: 900px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: 2fr repeat(4, 1fr); }
  .kpi-hero { grid-column: auto; }
  .dash-grid { grid-template-columns: repeat(3, 1fr); }
  .span-2 { grid-column: span 2; }
  .span-3 { grid-column: 1 / -1; }
  .kanban { grid-auto-columns: minmax(260px, 1fr); }
  .stat-list { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
  .sidebar { transform: none; position: sticky; top: 0; height: 100vh; flex: none; }
  .only-mobile { display: none !important; }
  .only-desktop { display: block; }
  .content { padding: 22px 26px 40px; }
  .topbar { padding: 0 22px; }
}
@media (max-width: 559px) {
  .toolbar-left.filters > * { flex: 1 1 140px; }
  .stepper li .step-title { font-size: .7rem; }
  .btn { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media print {
  .sidebar, .topbar, .toolbar, .bulkbar, .toast-host, .form-actions { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ==========================================================================
   v2 additions: month navigation, notes, matrix, history, portal, deletes
   ========================================================================== */
.mt { margin-top: 1.4rem; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: -4px 0 12px; }
.filter-bar select, .filter-bar input[type="search"] { width: auto; max-width: 100%; min-height: 34px; padding: 5px 8px; }
@media (max-width: 559px) { .filter-bar > * { flex: 1 1 140px; } }

.month-nav { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.month-jump { margin: 0; }
.month-label { position: relative; display: inline-flex; align-items: center; padding: 4px 10px; min-width: 150px; justify-content: center; font-weight: 650; cursor: pointer; border-radius: 6px; }
.month-label:hover { background: var(--surface-3); }
.month-label input[type="month"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; min-height: 0; }

.notes-panel { padding: 0; }
.notes-panel > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notes-panel > summary::-webkit-details-marker { display: none; }
.notes-panel > summary::after { content: "▾"; margin-left: auto; color: var(--text-3); }
.notes-panel[open] > summary::after { content: "▴"; }
.note-form { padding: 0 16px 12px; display: grid; gap: 8px; }
.note-form select { width: auto; max-width: 100%; min-height: 32px; padding: 3px 8px; }
.notes-list { list-style: none; margin: 0; padding: 0 16px 12px; display: grid; gap: 8px; }
.note { border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.note.is-resolved { border-left-color: var(--ok); opacity: .75; }
.note-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.note-body { overflow-wrap: anywhere; }
.note-actions { display: flex; gap: 6px; margin-top: 6px; }
.note-actions form { margin: 0; }
.resolved-notes { padding: 0 16px 12px; }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.pill.pin { background: color-mix(in srgb, var(--info) 14%, var(--surface)); color: var(--info); }
.pill.portal { background: color-mix(in srgb, var(--info) 14%, var(--surface)); color: var(--info); }
.empty-month { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.empty-month form { margin: 0; }

.comment.is-resolved { opacity: .7; border-left-color: var(--ok); }
.comment-actions { display: flex; gap: 12px; align-items: center; }
.comment-actions form { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); display: grid; gap: 8px; }
.timeline li { position: relative; display: flex; flex-direction: column; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.timeline .tl-text { font-size: .9rem; }
.history-tip { position: fixed; z-index: 95; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 10px 12px; max-height: 60vh; overflow: auto; pointer-events: none; }
.history-tip .tip-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; margin-bottom: 6px; }
.history-tip .timeline { gap: 6px; }
.history-tip .tl-text { font-size: .82rem; }
[data-history] { cursor: help; }
.kcard[data-history] { cursor: grab; }

.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.danger-zone h2 { color: var(--bad); }
form.danger-zone:not(.card) { margin: 0 0 14px; }
.btn.tone-bad, .icon-btn.tone-bad { color: var(--bad) !important; }
.ctx-menu button.tone-bad { color: var(--bad); }
.inline-form { display: inline; margin: 0; }

/* Client matrix */
.sheet.matrix th.mx-client, .sheet.matrix td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 200px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-weight: 600; padding: 0 10px; border-right: 1px solid var(--border-strong); text-transform: none; letter-spacing: 0; font-size: .88rem; }
.sheet.matrix thead th.mx-client { z-index: 3; background: var(--surface-3); }
.sheet.matrix th.mx-col { min-width: 120px; max-width: 160px; white-space: normal; line-height: 1.2; vertical-align: bottom; text-transform: none; letter-spacing: 0; font-size: .78rem; cursor: context-menu; }
.sheet.matrix th.mx-col span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sheet.matrix td.mx-cell { text-align: center; cursor: pointer; }
.sheet.matrix td.mx-cell.empty { background: var(--surface-2); cursor: default; }
.sheet.matrix tfoot td, .sheet.matrix tfoot th { background: var(--surface-3); font-weight: 600; height: 30px; }
.mx-chip { --c: #64748b; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; padding: 2px 8px; border-radius: 6px; font-size: .75rem; font-weight: 650;
  background: color-mix(in srgb, var(--c) 22%, var(--surface)); color: color-mix(in srgb, var(--c) 80%, var(--text)); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.mx-chip.is-overdue { box-shadow: inset 0 -2px 0 var(--bad); }
.note-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: 4px; vertical-align: middle; }
.mx-comments { font-size: .7rem; margin-left: 3px; color: var(--text-2); }
.mx-pct { font-weight: 650; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; font-size: .8rem; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

/* New task form target switch */
.target-seg { margin-bottom: 12px; flex-wrap: wrap; }
.target-seg input { position: absolute; opacity: 0; pointer-events: none; }
.target-seg .seg-btn { cursor: pointer; }

/* VAT steps admin */
.step-edit.is-inactive { opacity: .6; }
.sticky-actions { position: sticky; bottom: 10px; background: var(--surface); padding: 8px; border-radius: 10px; box-shadow: var(--shadow-lg); width: fit-content; }
.step-th { min-width: 90px; white-space: normal !important; line-height: 1.2; font-size: .7rem; }

/* Client portal */
body.portal .portal-bar { position: sticky; }
.portal-bar .brand { padding: 0; margin-right: auto; }
.portal-content { max-width: 900px; }
.portal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.portal-head h1 { margin: 0; font-size: 1.3rem; }
.portal-tasks { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.portal-tasks li { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.portal-task-title { flex: 1 1 220px; font-weight: 600; }
.linklike.tone-bad { color: var(--bad); }
.portal-bar { height: auto; min-height: var(--topbar-h); flex-wrap: wrap; padding: 8px 12px; }
.portal-bar .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
.portal-bar .topbar-actions form { margin: 0; }
@media (max-width: 559px) { .portal-bar .brand-name { display: none; } .portal-bar .btn { padding: 4px 8px; } }
.app-version { padding: 16px 10px 0; font-size: .72rem; }
.history-body { max-height: 60vh; overflow-y: auto; padding: 4px 4px 4px 8px; }
.ui-prefs { display: block; max-width: 420px; margin-top: 8px; }
