/* =========================================================
   Office CRM — design tokens
   ========================================================= */
:root {
  color-scheme: light;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --page: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --surface-3: #e9e7e1;
  --sidebar: #15161a;
  --sidebar-ink: #c9c8c2;
  --sidebar-ink-strong: #ffffff;
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: rgba(255,255,255,.1);

  --ink: #141413;
  --ink-2: #52514e;
  --ink-3: #898781;
  --line: #e4e2db;
  --line-strong: #c3c2b7;
  --grid: #e9e8e2;

  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --on-accent: #ffffff;

  --good: #0ca30c;     --good-ink: #006300;   --good-soft: #e5f5e5;
  --warn: #fab219;     --warn-ink: #8a5a00;   --warn-soft: #fdf3dc;
  --bad: #d03b3b;      --bad-ink: #a92b2b;    --bad-soft: #fbe9e9;

  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(20,20,19,.05);
  --shadow: 0 1px 2px rgba(20,20,19,.04), 0 4px 16px rgba(20,20,19,.06);
  --shadow-lg: 0 10px 40px rgba(20,20,19,.16), 0 2px 6px rgba(20,20,19,.06);
  --ring: 0 0 0 3px rgba(42,120,214,.25);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
    --sidebar: #0b0b0a; --sidebar-hover: rgba(255,255,255,.05); --sidebar-active: rgba(255,255,255,.09);
    --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #898781;
    --line: #2c2c2a; --line-strong: #44443f; --grid: #262624;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #172a42;
    --good-ink: #3fcf3f; --good-soft: #13281a; --warn-ink: #fab219; --warn-soft: #2e2510; --bad-ink: #f08080; --bad-soft: #341818;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --sidebar: #0b0b0a; --sidebar-hover: rgba(255,255,255,.05); --sidebar-active: rgba(255,255,255,.09);
  --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #898781;
  --line: #2c2c2a; --line-strong: #44443f; --grid: #262624;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #172a42;
  --good-ink: #3fcf3f; --good-soft: #13281a; --warn-ink: #fab219; --warn-soft: #2e2510; --bad-ink: #f08080; --bad-soft: #341818;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
}

/* =========================================================
   Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.hidden, [hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
::selection { background: var(--accent-soft); }

/* =========================================================
   App shell
   ========================================================= */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; color: var(--sidebar-ink-strong); padding: 4px 8px 18px; letter-spacing: -0.01em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3987e5, #6250d6); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand-sub { display: block; font-size: 11px; font-weight: 500; color: var(--sidebar-ink); opacity: .7; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-ink); opacity: .5; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-ink); font-weight: 500; text-decoration: none; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-strong); }
.nav a.active { background: var(--sidebar-active); color: var(--sidebar-ink-strong); }
.nav a.active svg { color: #86b6ef; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.1); padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .who { flex: 1; min-width: 0; }
.sidebar-foot .who b { display: block; color: var(--sidebar-ink-strong); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .who span { font-size: 12px; opacity: .7; }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px;
  border: 0; background: transparent; color: inherit; cursor: pointer; transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.sidebar .icon-btn:hover { background: var(--sidebar-hover); color: #fff; }
.icon-btn svg { width: 18px; height: 18px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line);
}
.search-trigger {
  display: flex; align-items: center; gap: 10px; flex: 0 1 420px; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink-3); cursor: text;
}
.search-trigger svg { width: 16px; height: 16px; }
.search-trigger kbd { margin-left: auto; }
kbd { font: 500 11px var(--font); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }

.view { padding: 26px 28px 60px; max-width: 1400px; width: 100%; animation: fade-in .25s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* =========================================================
   Controls
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
  box-shadow: var(--shadow-sm); text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-ink); }
:root[data-theme="dark"] .btn-primary:hover { background: #2a78d6; }
.btn-danger { color: var(--bad-ink); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=url], input[type=tel], input:not([type]), select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
select { appearance: none; padding-right: 32px; 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='%23898781' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid .span-2 { grid-column: 1 / -1; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; }
legend { font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 10px; gap: 2px; border: 1px solid var(--line); }
.seg label, .seg button {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 7px; border: 0; background: transparent;
  cursor: pointer; font-weight: 550; font-size: 13px; color: var(--ink-2);
}
.seg input { display: none; }
.seg label:has(input:checked), .seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { position: relative; flex: 0 1 300px; }
.toolbar .search svg { position: absolute; left: 11px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--ink-3); }
.toolbar .search input { padding-left: 34px; }
.toolbar select { width: auto; min-width: 150px; }

/* =========================================================
   Cards, KPIs, tables
   ========================================================= */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 0; }
.card-head .sub { font-size: 12.5px; color: var(--ink-3); }
.card-body { padding: 16px 18px 18px; }
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid-2e { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); font-weight: 550; display: flex; align-items: center; gap: 7px; }
.kpi .label svg { width: 15px; height: 15px; color: var(--ink-3); }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -0.03em; margin-top: 6px; line-height: 1.15; }
.kpi .foot { margin-top: 6px; font-size: 12.5px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.delta.up { color: var(--good-ink); background: var(--good-soft); }
.delta.down { color: var(--bad-ink); background: var(--bad-soft); }
.delta.flat { color: var(--ink-2); background: var(--surface-2); }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface);
  position: sticky; top: 0; cursor: default;
}
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--ink); }
.table th.sorted::after { content: " ↓"; }
.table th.sorted.asc::after { content: " ↑"; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background .1s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .right { text-align: right; }
.cell-person { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.cell-person b { font-weight: 600; display: block; }
.cell-person small { color: var(--ink-3); font-size: 12.5px; }

.avatar {
  --c: var(--s1); width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  font-size: 11.5px; font-weight: 650; color: #fff; background: var(--c); letter-spacing: .02em;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9.5px; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }
.avatar.soft { background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: color-mix(in srgb, var(--c) 75%, var(--ink)); }
.avatar-stack { display: flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); margin-left: -6px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.plain::before { display: none; }
.pill.blue { background: var(--accent-soft); color: var(--accent-ink); }
.pill.green { background: var(--good-soft); color: var(--good-ink); }
.pill.amber { background: var(--warn-soft); color: var(--warn-ink); }
.pill.red { background: var(--bad-soft); color: var(--bad-ink); }
.pill.violet { background: color-mix(in srgb, var(--s7) 14%, var(--surface)); color: color-mix(in srgb, var(--s7) 80%, var(--ink)); }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--ink-2); margin: 1px 3px 1px 0; white-space: nowrap; }

.score { display: inline-flex; align-items: center; gap: 8px; }
.score-bar { width: 54px; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.empty svg { width: 34px; height: 34px; margin-bottom: 8px; opacity: .6; }
.empty b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

/* =========================================================
   Lists (tasks, activity)
   ========================================================= */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 550; }
.list .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 1px; }
.list .meta a { color: inherit; }
.list .when { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.list .when.overdue { color: var(--bad-ink); font-weight: 600; }
.type-icon {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2);
}
.type-icon svg { width: 15px; height: 15px; }
.type-icon.call { background: color-mix(in srgb, var(--s3) 14%, var(--surface)); color: var(--s3); }
.type-icon.email { background: var(--accent-soft); color: var(--accent); }
.type-icon.meeting { background: color-mix(in srgb, var(--s7) 14%, var(--surface)); color: var(--s7); }
.type-icon.task { background: color-mix(in srgb, var(--s2) 14%, var(--surface)); color: var(--s2); }
.done-toggle {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--line-strong); background: var(--surface);
  flex: none; cursor: pointer; display: grid; place-items: center; margin-top: 5px; color: transparent; transition: all .15s;
}
.done-toggle:hover { border-color: var(--accent); }
.done-toggle.on { background: var(--good); border-color: var(--good); color: #fff; }
.done-toggle svg { width: 13px; height: 13px; }
li.is-done .title { text-decoration: line-through; color: var(--ink-3); }

.timeline { position: relative; }
.timeline li { position: relative; }

/* =========================================================
   Pipeline board
   ========================================================= */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.column { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 210px); }
.column-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.column-head .row { display: flex; align-items: center; gap: 8px; }
.column-head h3 { font-size: 13.5px; }
.column-head .n { font-size: 12px; color: var(--ink-3); background: var(--surface); border: 1px solid var(--line); padding: 0 7px; border-radius: 99px; }
.column-head .total { margin-left: auto; font-weight: 600; font-size: 13px; }
.column-head .prob { height: 3px; border-radius: 99px; background: var(--surface-3); margin-top: 10px; overflow: hidden; }
.column-head .prob i { display: block; height: 100%; background: var(--accent); }
.column.won .prob i { background: var(--good); }
.column.lost .prob i { background: var(--ink-3); }
.column-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 80px; flex: 1; transition: background .15s; }
.column-body.drop-over { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.deal-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; cursor: grab;
  box-shadow: var(--shadow-sm); transition: box-shadow .15s, border-color .15s, transform .15s;
}
.deal-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.deal-card.dragging { opacity: .45; transform: rotate(1.5deg); }
.deal-card .t { font-weight: 600; font-size: 13.5px; line-height: 1.35; }
.deal-card .c { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deal-card .b { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.deal-card .v { font-weight: 650; font-size: 13.5px; }
.deal-card .d { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 4px; }
.deal-card .d.late { color: var(--bad-ink); }
.deal-card .d svg { width: 13px; height: 13px; }
.column-add { margin: 0 10px 10px; border: 1px dashed var(--line-strong); background: transparent; border-radius: 9px; padding: 7px; color: var(--ink-3); cursor: pointer; font-weight: 550; }
.column-add:hover { color: var(--accent-ink); border-color: var(--accent); background: var(--surface); }

/* =========================================================
   Charts
   ========================================================= */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { transition: opacity .15s; }
.chart .hit { fill: transparent; cursor: default; }
.chart.hovering .bar:not(.hl) { opacity: .45; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .12; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--line-strong); stroke-dasharray: 3 3; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--ink); color: var(--surface);
  padding: 7px 10px; border-radius: 8px; font-size: 12.5px; box-shadow: var(--shadow-lg); white-space: nowrap;
  translate: -50% calc(-100% - 10px); opacity: 0; transition: opacity .12s;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 650; }
.tooltip .tt-label { opacity: .7; font-size: 11.5px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.hbar-row { display: grid; grid-template-columns: 120px 1fr 90px; gap: 12px; align-items: center; padding: 7px 0; }
.hbar-row .lbl { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-row .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar-row .fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .6s cubic-bezier(.2,.8,.2,1); }
.hbar-row .val { text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hbar-row .val small { color: var(--ink-3); font-weight: 500; }

.funnel { display: flex; flex-direction: column; gap: 6px; }
.funnel-step { display: grid; grid-template-columns: 110px 1fr 70px; gap: 12px; align-items: center; }
.funnel-step .bar-wrap { display: flex; justify-content: center; }
.funnel-step .fbar { height: 34px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 650; font-size: 13px; min-width: 36px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.funnel-step .lbl { font-size: 13px; color: var(--ink-2); font-weight: 550; }
.funnel-step .rate { text-align: right; font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* =========================================================
   Drawer, modal, toast, palette
   ========================================================= */
.scrim { position: fixed; inset: 0; background: rgba(15,15,14,.38); z-index: 40; animation: fade .2s ease; backdrop-filter: blur(2px); }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 41;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide-in .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { padding: 20px 22px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 14px; align-items: flex-start; }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-head h2 { font-size: 19px; }
.drawer-body { padding: 18px 22px 30px; overflow-y: auto; flex: 1; }
.drawer-section { margin-bottom: 22px; }
.drawer-section > h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.props { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13.5px; }
.props dt { color: var(--ink-3); }
.props dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-row > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat-row small { display: block; color: var(--ink-3); font-size: 12px; }
.stat-row b { font-size: 16px; }
.quick-note { display: flex; gap: 8px; margin-bottom: 8px; }
.quick-note select { width: 120px; flex: none; }

.modal-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal {
  background: var(--surface); border-radius: 16px; width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: pop .22s cubic-bezier(.2,.8,.2,1); border: 1px solid var(--line);
}
@keyframes pop { from { transform: scale(.97) translateY(6px); opacity: 0; } }
.modal-head { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.modal-foot .left { margin-right: auto; }

.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-weight: 500; display: flex; gap: 10px; align-items: center; animation: pop .2s ease; max-width: 360px;
}
.toast.error { background: var(--bad); color: #fff; }
.toast svg { width: 16px; height: 16px; flex: none; }

.palette { position: fixed; inset: 0; z-index: 55; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.palette-box { width: min(600px, calc(100vw - 32px)); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); overflow: hidden; animation: pop .18s ease; }
.palette-box input { height: 54px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-size: 16px; padding: 0 18px; box-shadow: none !important; }
.palette-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; cursor: pointer; }
.palette-item.on, .palette-item:hover { background: var(--surface-2); }
.palette-item small { color: var(--ink-3); }
.palette-item .kind { margin-left: auto; font-size: 11.5px; color: var(--ink-3); text-transform: capitalize; }
.palette-hint { padding: 16px 18px; color: var(--ink-3); font-size: 13px; }

/* =========================================================
   Auth / installer
   ========================================================= */
.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--s1) 18%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--s7) 16%, transparent), transparent 60%),
    var(--page);
}
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow-lg); display: grid; gap: 16px; }
.install-card { width: min(520px, 100%); }
.auth-card .brand { color: var(--ink); padding: 0 0 6px; }
.auth-card h1 { font-size: 22px; }
.alert { background: var(--bad-soft); color: var(--bad-ink); padding: 10px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 500; }

.loading { display: grid; place-items: center; min-height: 50vh; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1100px) {
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 45; left: 0; width: 260px; transform: translateX(-100%); transition: transform .25s ease; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .view { padding: 18px 16px 50px; }
  .grid-2e { grid-template-columns: minmax(0, 1fr); }
  .form-grid.two { grid-template-columns: 1fr; }
  .search-trigger kbd { display: none; }
  .hide-sm { display: none; }
  .hbar-row { grid-template-columns: 90px 1fr 70px; }
  .funnel-step { grid-template-columns: 80px 1fr 50px; }
}
@media (max-width: 520px) {
  .grid-kpi { grid-template-columns: minmax(0, 1fr); }
  .kpi .value { font-size: 24px; }
  .props { grid-template-columns: 100px 1fr; }
}

.mysql-fields { display: grid; gap: 12px; }
.search-trigger span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
