/* ==========================================================================
   Rayven CRM — design system
   One file, no build step. Tokens first, then layout, then components.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Neutrals */
  --plane:        #f6f7f9;
  --surface:      #ffffff;
  --surface-2:    #fbfbfc;
  --surface-3:    #f1f3f5;
  --surface-sunk: #eceef1;
  --ink:          #16181d;
  --ink-2:        #5b6472;
  --ink-3:        #8a929e;
  --line:         #e4e7ec;
  --line-2:       #d3d8e0;
  --ring:         rgba(11, 11, 11, .10);

  /* Brand — the same blue family the charts use, so the app reads as one system */
  --brand:        #1b64be;
  --brand-hover:  #16579f;
  --brand-ink:    #ffffff;
  --brand-soft:   #e8f1fd;
  --brand-soft-2: #d2e4fb;
  --brand-text:   #14538f;

  /* Data hues (validated: see docs/design-notes.md) */
  --series-1:     #257de0;
  --series-2:     #f47230;
  --series-3:     #00b894;
  --series-track: #e8f1fd;

  /* Status — fixed, never themed, always paired with an icon or label */
  --good:         #0aac23;
  --good-text:    #006c10;
  --good-soft:    #e6f8e9;
  --warning:      #fbb315;
  --warning-text: #8a5a00;
  --warning-soft: #fef5e2;
  --serious:      #f18a59;
  --critical:     #dc3c3d;
  --critical-text:#b32526;
  --critical-soft:#fdeaea;

  /* Chart chrome */
  --grid:         #e7e9ec;
  --axis:         #c2c7cf;

  /* Shape */
  --r-sm: 6px;
  --r:    9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;

  /* Elevation — low and soft; the data is the loud thing */
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 2px 4px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-3: 0 10px 24px rgba(16, 24, 40, .10), 0 2px 6px rgba(16, 24, 40, .06);
  --shadow-pop: 0 16px 40px rgba(16, 24, 40, .16), 0 2px 8px rgba(16, 24, 40, .08);

  /* Type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Metrics */
  --sidebar: 244px;
  --topbar: 60px;
  --gutter: 20px;

  --speed: 150ms;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* Dark mode. Selected steps, not an automatic flip. Declared twice so the
   viewer's own choice wins over the OS setting in both directions. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --plane:        #0b0c0f;
    --surface:      #16181d;
    --surface-2:    #1b1e24;
    --surface-3:    #22262e;
    --surface-sunk: #101216;
    --ink:          #e9ecf1;
    --ink-2:        #9aa3b2;
    --ink-3:        #6f7886;
    --line:         #272b33;
    --line-2:       #333945;
    --ring:         rgba(255, 255, 255, .10);

    --brand:        #3b82e8;
    --brand-hover:  #5a97ee;
    --brand-ink:    #0b0c0f;
    --brand-soft:   #17273c;
    --brand-soft-2: #1d3450;
    --brand-text:   #8ab8f2;

    --series-1:     #338ced;
    --series-2:     #e76624;
    --series-3:     #00a888;
    --series-track: #1d3450;

    --good-text:    #53c556;
    --good-soft:    #15301a;
    --warning-text: #e8b45c;
    --warning-soft: #2e2413;
    --critical-text:#f08886;
    --critical-soft:#301618;

    --grid:         #2a2e36;
    --axis:         #434a56;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, .45);
    --shadow-3: 0 12px 28px rgba(0, 0, 0, .55);
    --shadow-pop: 0 18px 44px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --plane:        #0b0c0f;
  --surface:      #16181d;
  --surface-2:    #1b1e24;
  --surface-3:    #22262e;
  --surface-sunk: #101216;
  --ink:          #e9ecf1;
  --ink-2:        #9aa3b2;
  --ink-3:        #6f7886;
  --line:         #272b33;
  --line-2:       #333945;
  --ring:         rgba(255, 255, 255, .10);

  --brand:        #3b82e8;
  --brand-hover:  #5a97ee;
  --brand-ink:    #0b0c0f;
  --brand-soft:   #17273c;
  --brand-soft-2: #1d3450;
  --brand-text:   #8ab8f2;

  --series-1:     #338ced;
  --series-2:     #e76624;
  --series-3:     #00a888;
  --series-track: #1d3450;

  --good-text:    #53c556;
  --good-soft:    #15301a;
  --warning-text: #e8b45c;
  --warning-soft: #2e2413;
  --critical-text:#f08886;
  --critical-soft:#301618;

  --grid:         #2a2e36;
  --axis:         #434a56;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .45);
  --shadow-3: 0 12px 28px rgba(0, 0, 0, .55);
  --shadow-pop: 0 18px 44px rgba(0, 0, 0, .6);
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.011em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
h4 { font-size: .9rem; }

p { margin: 0 0 .8em; }
p:last-child { margin-bottom: 0; }

a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }

small { font-size: .82rem; }

hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

blockquote {
  margin: 0 0 .8em;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--line-2);
  color: var(--ink-2);
}

code, pre { font-family: var(--mono); font-size: .86em; }

pre {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

img { max-width: 100%; height: auto; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--brand-soft-2); }

.icon { width: 18px; height: 18px; flex: none; }
.icon-sm { width: 15px; height: 15px; flex: none; }
.icon-lg { width: 22px; height: 22px; flex: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tnum { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: .84em; }
.grow { flex: 1 1 auto; min-width: 0; }

.row { display: flex; align-items: center; gap: 10px; }
.row-tight { display: flex; align-items: center; gap: 6px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.stack-lg > * + * { margin-top: 24px; }

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar);
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  flex: none;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--brand), #0f4a96);
  color: #fff;
  box-shadow: var(--shadow-1);
}
.brand-mark .icon { width: 18px; height: 18px; }

.brand-name { font-weight: 650; letter-spacing: -.015em; font-size: .97rem; }
.brand-sub { font-size: .7rem; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; }

.nav { flex: 1 1 auto; overflow-y: auto; padding: 12px 10px 20px; }
.nav-label {
  padding: 14px 10px 6px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 1px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 500;
  font-size: .9rem;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav-item .icon { color: var(--ink-3); transition: color var(--speed) var(--ease); }
.nav-item:hover .icon { color: var(--ink-2); }

.nav-item.is-active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav-item.is-active .icon { color: var(--brand-text); }

.nav-count {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: .72rem;
  font-weight: 650;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-item.is-active .nav-count { background: var(--brand); color: #fff; }
.nav-count.is-alert { background: var(--critical); color: #fff; }

.sidebar-foot { flex: none; padding: 10px; border-top: 1px solid var(--line); }

.main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar);
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.page { padding: var(--gutter); flex: 1 1 auto; min-width: 0; }
.page-wide { max-width: none; }
.page-narrow { max-width: 820px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-title h1 { font-size: 1.32rem; }
.page-title .sub { color: var(--ink-2); font-size: .88rem; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.menu-toggle { display: none; }

/* --------------------------------------------------------------------------
   4. Buttons
   -------------------------------------------------------------------------- */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--line-2);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 13px;
  min-height: 36px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: .89rem;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: filter var(--speed) var(--ease), background var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.btn:hover { text-decoration: none; filter: brightness(.975); }
.btn:active { transform: translateY(.5px); }
.btn[disabled], .btn.is-disabled { opacity: .55; pointer-events: none; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { --btn-bg: var(--brand); --btn-fg: var(--brand-ink); --btn-bd: transparent; box-shadow: var(--shadow-2); }
.btn-primary:hover { --btn-bg: var(--brand-hover); filter: none; }

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--ink-2); box-shadow: none; }
.btn-ghost:hover { --btn-bg: var(--surface-3); --btn-fg: var(--ink); filter: none; }

.btn-soft { --btn-bg: var(--brand-soft); --btn-fg: var(--brand-text); --btn-bd: transparent; box-shadow: none; }
.btn-soft:hover { --btn-bg: var(--brand-soft-2); filter: none; }

.btn-danger { --btn-bg: var(--critical); --btn-fg: #fff; --btn-bd: transparent; }
.btn-danger-soft { --btn-bg: var(--critical-soft); --btn-fg: var(--critical-text); --btn-bd: transparent; box-shadow: none; }

.btn-sm { padding: 4px 9px; min-height: 29px; font-size: .82rem; border-radius: var(--r-sm); }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { padding: 10px 18px; min-height: 42px; font-size: .95rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 36px; min-height: 36px; }
.btn-icon.btn-sm { width: 29px; min-height: 29px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; box-shadow: none; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

/* --------------------------------------------------------------------------
   5. Forms
   -------------------------------------------------------------------------- */

label { display: block; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field > .label,
.label {
  display: block;
  margin-bottom: 5px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink);
}
.label .req { color: var(--critical-text); }

.hint { margin-top: 5px; font-size: .79rem; color: var(--ink-2); line-height: 1.45; }
.hint a { text-decoration: underline; }

.input, .select, .textarea {
  display: block;
  width: 100%;
  padding: 8px 11px;
  min-height: 38px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.input[readonly] { background: var(--surface-3); color: var(--ink-2); }
.input.is-error, .select.is-error { border-color: var(--critical); }

.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.textarea-lg { min-height: 200px; }
.textarea-code { font-family: var(--mono); font-size: .83rem; }

.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a929e' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 15px;
}

.input-group { display: flex; }
.input-group .input { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-group .btn { border-radius: 0 var(--r-sm) var(--r-sm) 0; margin-left: -1px; }

.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-3); pointer-events: none; }
.input-icon .input { padding-left: 34px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.span-2 { grid-column: 1 / -1; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 2px 0;
  cursor: pointer;
  font-size: .89rem;
}
.check input[type="checkbox"], .check input[type="radio"] {
  flex: none;
  width: 16px; height: 16px;
  margin: 2px 0 0;
  accent-color: var(--brand);
  cursor: pointer;
}
.check-text { min-width: 0; }
.check-text b { display: block; font-weight: 600; }
.check-text span { display: block; color: var(--ink-2); font-size: .81rem; line-height: 1.45; }

/* A switch row: label and explanation on the left, control on the right */
.toggle {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.toggle:last-child { border-bottom: 0; }
.toggle-text { min-width: 0; }
.toggle-text b { display: block; font-weight: 600; font-size: .9rem; }
.toggle-text span { display: block; margin-top: 2px; color: var(--ink-2); font-size: .81rem; line-height: 1.5; }

.switch { position: relative; flex: none; width: 40px; height: 23px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute; inset: 0;
  background: var(--line-2);
  border-radius: var(--r-full);
  transition: background var(--speed) var(--ease);
  pointer-events: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 17px; height: 17px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform var(--speed) var(--ease);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   6. Cards & panels
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head h3 { font-size: .95rem; }
.card-head .sub { font-size: .8rem; color: var(--ink-2); }
.card-body { padding: 16px; }
.card-body-flush { padding: 0; }
.card-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-md) var(--r-md);
}

.grid { display: grid; gap: var(--gutter); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); align-items: start; }
.grid-aside { grid-template-columns: minmax(0, 320px) minmax(0, 1fr); align-items: start; }

/* --------------------------------------------------------------------------
   7. Stat tiles & figures
   -------------------------------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

.tile {
  position: relative;
  padding: 15px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.tile-label {
  display: flex; align-items: center; gap: 6px;
  font-size: .79rem; font-weight: 600; color: var(--ink-2);
}
.tile-label .icon { width: 14px; height: 14px; color: var(--ink-3); }
.tile-value { font-size: 1.72rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
.tile-foot { display: flex; align-items: center; gap: 7px; font-size: .79rem; color: var(--ink-2); margin-top: 2px; }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.delta .icon { width: 13px; height: 13px; }
.delta-up { color: var(--good-text); }
.delta-down { color: var(--critical-text); }
.delta-flat { color: var(--ink-3); }

.hero-figure { font-size: 3rem; font-weight: 650; letter-spacing: -.03em; line-height: 1; }

/* --------------------------------------------------------------------------
   8. Charts
   -------------------------------------------------------------------------- */

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-axis { font-size: 10.5px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart-base { stroke: var(--axis); stroke-width: 1; }
.chart-bar { fill: var(--series-1); }
.chart-bar-track { fill: var(--series-track); }
.chart-label { font-size: 11px; font-weight: 600; fill: var(--ink); font-variant-numeric: tabular-nums; }

/* Hover affordance on a column: the hit area is wider than the mark */
.chart-col { cursor: default; }
.chart-col rect.hit { fill: transparent; }
.chart-col:hover rect.hit { fill: var(--surface-3); }
.chart-col:hover .chart-bar { fill: var(--brand); }

/* A labelled horizontal bar list — the form for ranked magnitudes */
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: minmax(84px, 34%) 1fr auto; align-items: center; gap: 10px; }
.bar-name { font-size: .84rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { position: relative; height: 8px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--series-1); border-radius: var(--r-full); min-width: 3px; }
.bar-value { font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 28px; text-align: right; }

/* Sparkline inside a tile */
.spark { display: block; width: 100%; height: 30px; overflow: visible; }
.spark-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--series-1); opacity: .1; }
.spark-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }

/* --------------------------------------------------------------------------
   9. Badges, pills, avatars
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: .76rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.badge .icon { width: 12px; height: 12px; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

.badge-good { background: var(--good-soft); color: var(--good-text); }
.badge-warn { background: var(--warning-soft); color: var(--warning-text); }
.badge-bad { background: var(--critical-soft); color: var(--critical-text); }
.badge-info { background: var(--brand-soft); color: var(--brand-text); }
.badge-outline { background: transparent; border: 1px solid var(--line-2); }

/* Contact status, one hue family per state so the list scans */
.status-new { background: var(--brand-soft); color: var(--brand-text); }
.status-contacted { background: var(--warning-soft); color: var(--warning-text); }
.status-qualified { background: #eceaff; color: #4b35b3; }
.status-customer { background: var(--good-soft); color: var(--good-text); }
.status-unqualified, .status-closed { background: var(--surface-3); color: var(--ink-2); }
:root[data-theme="dark"] .status-qualified { background: #241f45; color: #b5a8ff; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .status-qualified { background: #241f45; color: #b5a8ff; }
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  flex: none;
  border-radius: 50%;
  font-size: .78rem;
  font-weight: 650;
  letter-spacing: .01em;
  background: var(--surface-3);
  color: var(--ink-2);
  text-transform: uppercase;
  user-select: none;
}
.avatar-sm { width: 26px; height: 26px; font-size: .67rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.05rem; }

/* Eight stable tints so the same person keeps the same bubble */
.hue-1 { background: #e3effd; color: #14538f; }
.hue-2 { background: #fdeadf; color: #8f3f12; }
.hue-3 { background: #d9f5ee; color: #04624f; }
.hue-4 { background: #fdf0d6; color: #7a5300; }
.hue-5 { background: #fde8ef; color: #973058; }
.hue-6 { background: #e0f3e2; color: #1a6b24; }
.hue-7 { background: #eae6fd; color: #4b35b3; }
.hue-8 { background: #fde8e8; color: #a32a2b; }
:root[data-theme="dark"] .hue-1 { background: #16293d; color: #8cbcf5; }
:root[data-theme="dark"] .hue-2 { background: #351e12; color: #f0a079; }
:root[data-theme="dark"] .hue-3 { background: #0f2b26; color: #5bd3ba; }
:root[data-theme="dark"] .hue-4 { background: #332814; color: #e5b85f; }
:root[data-theme="dark"] .hue-5 { background: #351c26; color: #f095b4; }
:root[data-theme="dark"] .hue-6 { background: #162e1a; color: #7ad182; }
:root[data-theme="dark"] .hue-7 { background: #241f45; color: #b5a8ff; }
:root[data-theme="dark"] .hue-8 { background: #351a1b; color: #f09593; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .hue-1 { background: #16293d; color: #8cbcf5; }
  :root:where(:not([data-theme="light"])) .hue-2 { background: #351e12; color: #f0a079; }
  :root:where(:not([data-theme="light"])) .hue-3 { background: #0f2b26; color: #5bd3ba; }
  :root:where(:not([data-theme="light"])) .hue-4 { background: #332814; color: #e5b85f; }
  :root:where(:not([data-theme="light"])) .hue-5 { background: #351c26; color: #f095b4; }
  :root:where(:not([data-theme="light"])) .hue-6 { background: #162e1a; color: #7ad182; }
  :root:where(:not([data-theme="light"])) .hue-7 { background: #241f45; color: #b5a8ff; }
  :root:where(:not([data-theme="light"])) .hue-8 { background: #351a1b; color: #f09593; }
}

/* --------------------------------------------------------------------------
   10. Tables
   -------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: .89rem; }
.table th {
  padding: 9px 14px;
  text-align: left;
  font-size: .74rem;
  font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table th a:hover { color: var(--ink); text-decoration: none; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--speed) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table-tight td, .table-tight th { padding: 7px 10px; }
.table .col-shrink { width: 1%; white-space: nowrap; }

.cell-person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-person .name { font-weight: 600; color: var(--ink); display: block; }
.cell-person .meta { font-size: .79rem; color: var(--ink-2); display: block; }

.row-link { color: inherit; }
.row-link:hover { text-decoration: none; }

/* --------------------------------------------------------------------------
   11. Tabs, filters, pagination
   -------------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 13px;
  border-bottom: 2px solid transparent;
  color: var(--ink-2);
  font-size: .89rem;
  font-weight: 550;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.is-active { color: var(--brand-text); border-bottom-color: var(--brand); font-weight: 650; }
.tab .count { margin-left: 5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tab.is-active .count { color: var(--brand-text); }

/* Segmented control, for a small set of mutually exclusive views */
.segment { display: inline-flex; padding: 2px; background: var(--surface-3); border-radius: var(--r-sm); gap: 2px; }
.segment a, .segment button {
  padding: 5px 11px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: .83rem;
  font-weight: 550;
  cursor: pointer;
}
.segment a:hover, .segment button:hover { color: var(--ink); text-decoration: none; }
.segment .is-active { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: var(--shadow-1); }

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters .input, .filters .select { min-height: 34px; padding-top: 5px; padding-bottom: 5px; font-size: .86rem; }
.filters .search { min-width: 240px; flex: 1 1 240px; max-width: 360px; }
.filters .select { width: auto; min-width: 128px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pagination .pages { display: flex; align-items: center; gap: 4px; }
.page-num {
  display: grid; place-items: center;
  min-width: 31px; height: 31px;
  padding: 0 7px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: .85rem;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}
.page-num:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.page-num.is-active { background: var(--brand); color: #fff; font-weight: 650; }
.page-num.is-gap { pointer-events: none; color: var(--ink-3); }

/* --------------------------------------------------------------------------
   12. Flash messages & empty states
   -------------------------------------------------------------------------- */

.flashes { position: fixed; top: 14px; right: 14px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 28px)); }

.flash {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  font-size: .88rem;
  animation: flash-in 220ms var(--ease);
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.flash .icon { flex: none; margin-top: 1px; }
.flash-success { border-left: 3px solid var(--good); }
.flash-success .icon { color: var(--good-text); }
.flash-error { border-left: 3px solid var(--critical); }
.flash-error .icon { color: var(--critical-text); }
.flash-warn { border-left: 3px solid var(--warning); }
.flash-warn .icon { color: var(--warning-text); }
.flash-info { border-left: 3px solid var(--brand); }
.flash-info .icon { color: var(--brand-text); }
.flash-close { margin-left: auto; border: 0; background: none; color: var(--ink-3); cursor: pointer; padding: 0; line-height: 1; }

/* An inline note, for guidance that belongs next to a field */
.note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border-radius: var(--r);
  background: var(--brand-soft);
  color: var(--ink);
  font-size: .85rem;
  line-height: 1.55;
}
.note .icon { flex: none; margin-top: 2px; color: var(--brand-text); }
.note-warn { background: var(--warning-soft); }
.note-warn .icon { color: var(--warning-text); }
.note-bad { background: var(--critical-soft); }
.note-bad .icon { color: var(--critical-text); }
.note-good { background: var(--good-soft); }
.note-good .icon { color: var(--good-text); }
.note-plain { background: var(--surface-3); }
.note-plain .icon { color: var(--ink-3); }
.note code { background: color-mix(in srgb, var(--ink) 8%, transparent); padding: 1px 4px; border-radius: 4px; }

.empty { padding: 44px 24px; text-align: center; }
.empty .icon-wrap {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-3);
}
.empty h3 { margin-bottom: 5px; }
.empty p { color: var(--ink-2); max-width: 420px; margin: 0 auto 16px; font-size: .89rem; }

/* --------------------------------------------------------------------------
   13. Dropdown menus
   -------------------------------------------------------------------------- */

.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 196px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop);
  display: none;
}
.dropdown.is-open .dropdown-panel { display: block; }
.dropdown-panel.to-left { right: auto; left: 0; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: .87rem;
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-3); text-decoration: none; }
.dropdown-item .icon { width: 15px; height: 15px; color: var(--ink-3); }
.dropdown-item.is-danger { color: var(--critical-text); }
.dropdown-item.is-danger .icon { color: var(--critical-text); }
.dropdown-sep { height: 1px; margin: 5px 0; background: var(--line); }
.dropdown-label { padding: 7px 9px 4px; font-size: .72rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }

.user-button {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.user-button:hover { background: var(--surface-3); }
.user-button .who { min-width: 0; flex: 1; }
.user-button .who b { display: block; font-size: .86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-button .who span { display: block; font-size: .75rem; color: var(--ink-3); }

/* --------------------------------------------------------------------------
   14. Global search
   -------------------------------------------------------------------------- */

.search-shell { position: relative; flex: 1 1 180px; min-width: 0; max-width: 440px; }
.search-shell .input { padding-left: 34px; min-height: 36px; background: var(--surface-3); border-color: transparent; }
.search-shell .input:focus { background: var(--surface); border-color: var(--brand); }
.search-shell > svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-3); pointer-events: none; }
.search-kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  padding: 1px 5px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  font-size: .7rem;
  color: var(--ink-3);
  font-family: var(--mono);
  pointer-events: none;
}
.search-shell:focus-within .search-kbd { display: none; }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  z-index: 70;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop);
  max-height: 60vh;
  overflow-y: auto;
  display: none;
}
.search-results.is-open { display: block; }
.search-hit { display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: var(--r-sm); color: var(--ink); }
.search-hit:hover, .search-hit.is-cursor { background: var(--surface-3); text-decoration: none; }
.search-hit .who { min-width: 0; }
.search-hit .who b { display: block; font-size: .88rem; font-weight: 600; }
.search-hit .who span { display: block; font-size: .78rem; color: var(--ink-2); }
.search-note { padding: 14px 10px; text-align: center; color: var(--ink-2); font-size: .85rem; }

/* --------------------------------------------------------------------------
   15. Pipeline board
   -------------------------------------------------------------------------- */

.board {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 12px;
  min-height: 60vh;
}

.board-col {
  flex: 0 0 272px;
  width: 272px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 190px);
}
.board-col.is-over { border-color: var(--brand); background: var(--brand-soft); }

.board-head { padding: 11px 13px 9px; border-bottom: 1px solid var(--line); flex: none; }
.board-head .title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.board-head h3 { font-size: .86rem; font-weight: 650; }
.board-head .count {
  min-width: 20px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: .73rem; font-weight: 650; text-align: center;
  font-variant-numeric: tabular-nums;
}
.board-head .total { margin-top: 2px; font-size: .78rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.board-col.is-won .board-head { border-bottom-color: var(--good); }
.board-col.is-lost .board-head { border-bottom-color: var(--line-2); }

.board-list { flex: 1 1 auto; overflow-y: auto; padding: 9px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }

.deal-card {
  display: block;
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  color: inherit;
  cursor: grab;
  transition: box-shadow var(--speed) var(--ease), transform var(--speed) var(--ease);
}
.deal-card:hover { text-decoration: none; box-shadow: var(--shadow-2); }
.deal-card.is-dragging { opacity: .45; }
.deal-card .deal-title { font-weight: 600; font-size: .89rem; line-height: 1.4; margin-bottom: 5px; }
.deal-card .deal-who { display: flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: .8rem; margin-bottom: 7px; }
.deal-card .deal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.deal-card .deal-value { font-size: .88rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.deal-card .deal-date { font-size: .76rem; color: var(--ink-3); display: inline-flex; align-items: center; gap: 4px; }
.deal-card .deal-date.is-late { color: var(--critical-text); font-weight: 600; }

.board-drop-hint { padding: 16px 10px; text-align: center; color: var(--ink-3); font-size: .8rem; border: 1px dashed var(--line-2); border-radius: var(--r); }

/* --------------------------------------------------------------------------
   16. Contact detail
   -------------------------------------------------------------------------- */

.profile-head { display: flex; align-items: flex-start; gap: 14px; }
.profile-head .who h1 { font-size: 1.3rem; }
.profile-head .who .meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 5px; color: var(--ink-2); font-size: .85rem; }

.fact-list { display: flex; flex-direction: column; }
.fact {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: .87rem;
  align-items: start;
}
.fact:last-child { border-bottom: 0; }
.fact dt { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.fact dt .icon { width: 14px; height: 14px; color: var(--ink-3); }
.fact dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ""; position: absolute; left: 11px; top: 6px; bottom: 6px; width: 2px; background: var(--line); border-radius: 2px; }

.event { position: relative; padding: 0 0 20px; }
.event:last-child { padding-bottom: 2px; }
.event-dot {
  position: absolute;
  left: -28px; top: 1px;
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-3);
}
.event-dot .icon { width: 13px; height: 13px; }
.event-dot.is-in { background: var(--brand-soft); border-color: transparent; color: var(--brand-text); }
.event-dot.is-out { background: var(--good-soft); border-color: transparent; color: var(--good-text); }
.event-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.event-head b { font-size: .88rem; font-weight: 600; }
.event-head time { font-size: .76rem; color: var(--ink-3); white-space: nowrap; }
.event-body {
  margin-top: 5px;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: .86rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.event-body.is-html { white-space: normal; }
.event-body.is-html img { max-width: 100%; }

.composer { display: flex; flex-direction: column; gap: 10px; }
.composer-tabs { display: flex; gap: 2px; }

.tag-list { display: flex; gap: 5px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: .76rem;
  font-weight: 550;
}

/* --------------------------------------------------------------------------
   17. Inbox
   -------------------------------------------------------------------------- */

.inbox {
  display: grid;
  grid-template-columns: minmax(0, 330px) minmax(0, 1fr);
  gap: var(--gutter);
  align-items: start;
}

.thread-list { max-height: calc(100vh - 170px); overflow-y: auto; }
.thread-item {
  display: flex;
  gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  color: inherit;
}
.thread-item:hover { background: var(--surface-2); text-decoration: none; }
.thread-item.is-active { background: var(--brand-soft); }
.thread-item.is-unread .thread-who { font-weight: 700; }
.thread-main { min-width: 0; flex: 1; }
.thread-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.thread-who { font-size: .88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-when { font-size: .73rem; color: var(--ink-3); white-space: nowrap; flex: none; }
.thread-preview { font-size: .81rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thread-badges { display: flex; align-items: center; gap: 5px; margin-top: 4px; }
.unread-pip { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); flex: none; }

.conversation { display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.conversation-body { flex: 1 1 auto; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.bubble { max-width: min(76%, 600px); }
.bubble-in { align-self: flex-start; }
.bubble-out { align-self: flex-end; }
.bubble-text {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble-in .bubble-text { background: var(--surface-3); border-bottom-left-radius: 4px; }
.bubble-out .bubble-text { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.bubble-out .bubble-text a { color: #fff; text-decoration: underline; }
.bubble-meta { margin-top: 4px; font-size: .72rem; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.bubble-out .bubble-meta { justify-content: flex-end; }
.bubble-subject { font-size: .78rem; font-weight: 650; color: var(--ink-2); margin-bottom: 3px; }
.bubble-failed .bubble-text { background: var(--critical-soft); color: var(--critical-text); }

.reply-box { flex: none; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-md) var(--r-md); }

/* --------------------------------------------------------------------------
   18. Settings
   -------------------------------------------------------------------------- */

.settings-layout { display: grid; grid-template-columns: minmax(0, 214px) minmax(0, 1fr); gap: var(--gutter); align-items: start; }

.settings-nav { display: flex; flex-direction: column; gap: 1px; position: sticky; top: calc(var(--topbar) + var(--gutter)); }
.settings-nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: .88rem;
  font-weight: 550;
}
.settings-nav a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.settings-nav a.is-active { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: var(--shadow-1); border: 1px solid var(--line); }
.settings-nav a .icon { width: 15px; height: 15px; color: var(--ink-3); }
.settings-nav a.is-active .icon { color: var(--brand-text); }

.section { margin-bottom: 26px; }
.section:last-child { margin-bottom: 0; }
.section-head { margin-bottom: 12px; }
.section-head h2 { font-size: 1rem; }
.section-head p { margin: 3px 0 0; color: var(--ink-2); font-size: .86rem; }

.copy-field { display: flex; gap: 0; }
.copy-field .input { border-radius: var(--r-sm) 0 0 var(--r-sm); font-family: var(--mono); font-size: .8rem; background: var(--surface-3); }
.copy-field .btn { border-radius: 0 var(--r-sm) var(--r-sm) 0; margin-left: -1px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: .87rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 550; }

.log-level { display: inline-flex; padding: 1px 7px; border-radius: 4px; font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
.log-debug { background: var(--surface-3); color: var(--ink-3); }
.log-info { background: var(--brand-soft); color: var(--brand-text); }
.log-warn { background: var(--warning-soft); color: var(--warning-text); }
.log-error { background: var(--critical-soft); color: var(--critical-text); }

/* --------------------------------------------------------------------------
   19. Dialogs
   -------------------------------------------------------------------------- */

dialog.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: min(84vh, 900px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
dialog.modal::backdrop { background: rgba(11, 13, 18, .55); backdrop-filter: blur(2px); }
dialog.modal-wide { width: min(760px, calc(100vw - 32px)); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1rem; }
.modal-body { padding: 18px; overflow-y: auto; max-height: 62vh; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }

/* --------------------------------------------------------------------------
   20. Auth & install
   -------------------------------------------------------------------------- */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--brand-soft), transparent 70%),
    var(--plane);
}
.auth-card { width: 100%; max-width: 404px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; }
.auth-brand .brand-mark { width: 34px; height: 34px; }
.auth-brand .name { font-size: 1.08rem; font-weight: 650; letter-spacing: -.015em; }
.auth-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-3); padding: 26px; }
.auth-box h1 { font-size: 1.2rem; margin-bottom: 4px; }
.auth-box .lead { color: var(--ink-2); font-size: .89rem; margin-bottom: 20px; }
.auth-foot { margin-top: 16px; text-align: center; font-size: .82rem; color: var(--ink-3); }

.install-page { min-height: 100vh; padding: 32px 16px 56px; background: var(--plane); }
.install-shell { max-width: 680px; margin: 0 auto; }
.install-head { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.install-head .brand-mark { width: 36px; height: 36px; }
.install-head h1 { font-size: 1.22rem; }
.install-head p { margin: 1px 0 0; color: var(--ink-2); font-size: .86rem; }

.steps { display: flex; align-items: center; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 7px; font-size: .83rem; color: var(--ink-3); }
.step-num {
  display: grid; place-items: center;
  width: 23px; height: 23px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-3);
  font-size: .76rem;
  font-weight: 650;
}
.step.is-current { color: var(--ink); font-weight: 600; }
.step.is-current .step-num { background: var(--brand); color: #fff; }
.step.is-done .step-num { background: var(--good-soft); color: var(--good-text); }
.step.is-done { color: var(--ink-2); }
.step-sep { width: 18px; height: 1px; background: var(--line-2); }

.check-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: .88rem;
}
.check-row:last-child { border-bottom: 0; }
.check-row .state { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; flex: none; }
.check-row .state.ok { background: var(--good-soft); color: var(--good-text); }
.check-row .state.bad { background: var(--critical-soft); color: var(--critical-text); }
.check-row .state.meh { background: var(--warning-soft); color: var(--warning-text); }
.check-row .state .icon { width: 13px; height: 13px; }
.check-row .what { flex: 1; min-width: 0; }
.check-row .what b { display: block; font-weight: 600; }
.check-row .what span { display: block; font-size: .8rem; color: var(--ink-2); }

/* --------------------------------------------------------------------------
   21. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  :root { --gutter: 16px; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 220ms var(--ease);
    box-shadow: var(--shadow-pop);
    width: 268px;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(11, 13, 18, .45);
    z-index: 35;
  }

  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }

  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox.has-thread .thread-panel { display: none; }
  .thread-list, .conversation { max-height: none; }

  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .settings-nav a { white-space: nowrap; }

  .grid-2, .grid-3, .grid-aside { grid-template-columns: minmax(0, 1fr); }
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .tiles, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-actions { justify-content: flex-start; }
  .search-shell { max-width: none; }
  .filters .search { max-width: none; }
  .table th, .table td { padding: 9px 10px; }
  .hide-sm { display: none !important; }
  .fact { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .board-col { flex-basis: 84vw; width: 84vw; }
  .bubble { max-width: 90%; }
  .tabs { margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .sidebar, .topbar, .page-actions, .filters, .flashes { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
