/* ==========================================================================
   Simple Tracker — design system
   Philosophy: Dieter Rams functionalism + Swiss rigor for data-dense ops UI.
   Colour is information: green = result (install), amber = intent (download),
   blue = traffic. Everything else is neutral ink on paper / graphite.
   ========================================================================== */

/* ---------- Tokens: light ---------- */
:root {
  --font-body: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --bg-app: #f4f3ef;
  --bg-surface: #ffffff;
  --bg-subtle: #f9f8f5;
  --bg-sunken: #efede8;
  --bg-hover: #f2f1ec;
  --bg-sidebar: #151619;
  --bg-inverse: #151619;

  --text-primary: #17181b;
  --text-secondary: #5d5f66;
  --text-tertiary: #95979e;
  --text-inverse: #f4f3ef;
  --text-sidebar: #a5a7ad;
  --text-sidebar-active: #ffffff;

  --border: #e4e2dc;
  --border-strong: #d3d0c8;
  --border-focus: #1f9d55;

  --accent: #1f9d55;
  --accent-hover: #188548;
  --accent-soft: #e5f4eb;
  --accent-text: #146c3b;

  --amber: #b7791f;
  --amber-soft: #fbf1df;
  --blue: #2f6fd6;
  --blue-soft: #e8effb;
  --red: #c8372d;
  --red-soft: #fbe9e7;
  --violet: #7354c7;
  --violet-soft: #efeafb;

  --overlay: rgba(21, 22, 25, .45);

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-full: 999px;

  --shadow-sm: 0 1px 2px rgba(23, 24, 27, .05);
  --shadow-md: 0 1px 2px rgba(23, 24, 27, .04), 0 4px 16px rgba(23, 24, 27, .06);
  --shadow-lg: 0 12px 48px rgba(23, 24, 27, .18);
  --ring: 0 0 0 3px rgba(31, 157, 85, .22);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px; --s9: 56px;

  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 15px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;

  --ease: cubic-bezier(.4, 0, .2, 1);
  --fast: 140ms;
  --sidebar-w: 240px;

  color-scheme: light;
}

/* ---------- Tokens: dark (cool graphite) ---------- */
[data-theme="dark"] {
  --bg-app: #101113;
  --bg-surface: #17181b;
  --bg-subtle: #1c1d21;
  --bg-sunken: #0c0d0f;
  --bg-hover: #202126;
  --bg-sidebar: #0b0c0e;
  --bg-inverse: #ececea;

  --text-primary: #e8e8e6;
  --text-secondary: #a2a4ab;
  --text-tertiary: #6d7078;
  --text-inverse: #151619;

  --border: #26282d;
  --border-strong: #33363c;
  --border-focus: #3ecf7a;

  --accent: #2fb866;
  --accent-hover: #3ecf7a;
  --accent-soft: rgba(47, 184, 102, .14);
  --accent-text: #5fdb92;

  --amber: #e0a645;
  --amber-soft: rgba(224, 166, 69, .14);
  --blue: #6c9ef0;
  --blue-soft: rgba(108, 158, 240, .14);
  --red: #f0756b;
  --red-soft: rgba(240, 117, 107, .14);
  --violet: #a68cf0;
  --violet-soft: rgba(166, 140, 240, .14);

  --overlay: rgba(0, 0, 0, .6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --shadow-lg: 0 16px 56px rgba(0, 0, 0, .55);
  --ring: 0 0 0 3px rgba(62, 207, 122, .25);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
a { color: inherit; text-decoration: none; }
a.link { color: var(--accent-text); }
a.link:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); font-size: .92em; }
code { background: var(--bg-sunken); padding: 1px 6px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 15px; height: 15px; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--text-secondary); }
.faint { color: var(--text-tertiary); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* ---------- App shell ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--bg-sidebar); color: var(--text-sidebar);
  display: flex; flex-direction: column; padding: var(--s5) var(--s3);
  transform: translateX(-100%); transition: transform 220ms var(--ease);
}
.sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--s3) var(--s6); color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 16px; height: 16px; stroke: #fff; stroke-width: 2.25; }
.nav-section { margin-top: var(--s4); }
.nav-label { padding: 0 var(--s3) var(--s2); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #5f6168; }
.nav a {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 var(--s3);
  border-radius: var(--r-md); font-weight: 500; font-size: var(--fs-md);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav a:hover { background: rgba(255, 255, 255, .05); color: #e6e6e6; }
.nav a.active { background: rgba(255, 255, 255, .08); color: var(--text-sidebar-active); }
.nav a.active svg { stroke: var(--accent-hover); }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .07); padding: var(--s4) var(--s3) 0; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: var(--r-full); background: #2a2c31; color: #e6e6e6; display: grid; place-items: center; font-weight: 650; font-size: 13px; text-transform: uppercase; flex: none; }
.who { min-width: 0; flex: 1; line-height: 1.25; }
.who b { display: block; color: #ececea; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { display: block; font-size: 12px; color: #6d7078; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-md); color: inherit; background: none; border: 0; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, .07); color: #fff; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s4); background: var(--bg-sidebar); color: #fff;
}
.topbar .brand { padding: 0; }
.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 35; opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease); }
.scrim.open { opacity: 1; pointer-events: auto; }

.main { padding: var(--s5) var(--s4) var(--s9); max-width: 1440px; }

@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .topbar, .scrim { display: none; }
  .main { margin-left: var(--sidebar-w); padding: var(--s7) var(--s8) var(--s9); }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); }
.page-head h1 { font-size: var(--fs-2xl); line-height: 1.15; letter-spacing: -.02em; }
.page-head .sub { margin-top: 6px; color: var(--text-secondary); font-size: var(--fs-md); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-secondary); font-size: var(--fs-sm); margin-bottom: var(--s2); }
.back:hover { color: var(--text-primary); }

/* ---------- Cards & sections ---------- */
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card + .card { margin-top: var(--s5); }
.card-pad { padding: var(--s5); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: var(--fs-md); font-weight: 650; display: flex; align-items: center; gap: var(--s2); }
.card-head .count { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-tertiary); background: var(--bg-sunken); padding: 2px 8px; border-radius: var(--r-full); }
.stack > * + * { margin-top: var(--s5); }
.grid { display: grid; gap: var(--s5); }
@media (min-width: 1024px) { .grid-3-1 { grid-template-columns: 2fr 1fr; } .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: var(--s4); grid-template-columns: 1fr; }
@media (min-width: 768px) { .form-grid { grid-template-columns: repeat(12, 1fr); align-items: end; } .col-2 { grid-column: span 2; } .col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; } .col-6 { grid-column: span 6; } .col-12 { grid-column: span 12; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary); letter-spacing: .01em; }
.hint { font-size: var(--fs-xs); color: var(--text-tertiary); }
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 0 12px;
  font: inherit; font-size: 16px; color: var(--text-primary);
  background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
@media (min-width: 768px) { .input, .select, .textarea { font-size: var(--fs-base); min-height: 38px; } }
.textarea { padding: 9px 12px; min-height: 84px; resize: vertical; line-height: 1.45; }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  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='%2395979e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-tertiary); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--ring); }
.input:disabled { background: var(--bg-sunken); color: var(--text-tertiary); cursor: not-allowed; }
input[type="file"].input { padding: 6px; font-size: var(--fs-sm); }
input[type="file"]::file-selector-button { font: inherit; font-weight: 600; font-size: var(--fs-sm); border: 0; border-radius: var(--r-sm); background: var(--bg-sunken); color: var(--text-primary); padding: 6px 12px; margin-right: 10px; cursor: pointer; }
input[type="date"].input { font-family: var(--font-mono); font-size: var(--fs-sm); }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 32px; padding: 4px 0; cursor: pointer; user-select: none; font-size: var(--fs-base); }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; cursor: pointer; }
.check-list .check { display: flex; align-items: flex-start; }
.check-list .check input { margin-top: 2px; }
.check-list { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-subtle); max-height: 260px; overflow: auto; padding: var(--s2) var(--s3); }
.check-group + .check-group { border-top: 1px dashed var(--border); margin-top: var(--s2); padding-top: var(--s2); }
.check-group-title { font-size: var(--fs-xs); font-weight: 650; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; }
.check-group .check:not(.check-group-title) { padding-left: 26px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px; border-radius: var(--r-md); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: var(--fs-base); line-height: 1; white-space: nowrap; cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform 60ms;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-tertiary); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); gap: 6px; }
.btn-icon { width: 32px; min-height: 32px; padding: 0; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
@media (max-width: 767px) { .btn { min-height: 44px; } .btn-sm, .btn-icon { min-height: 36px; } .btn-icon { width: 36px; } }
.row-actions { display: inline-flex; gap: 2px; justify-content: flex-end; }
.row-actions form { display: inline; margin: 0; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-sunken); border-radius: var(--r-md); flex-wrap: wrap; }
.seg a, .seg button {
  font: inherit; font-size: var(--fs-sm); font-weight: 550; color: var(--text-secondary);
  padding: 0 12px; min-height: 32px; display: inline-flex; align-items: center; border: 0; background: none; border-radius: 6px; cursor: pointer;
}
.seg a:hover, .seg button:hover { color: var(--text-primary); }
.seg .on { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 600; line-height: 18px; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-green { background: var(--accent-soft); color: var(--accent-text); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-violet { background: var(--violet-soft); color: var(--violet); }
.b-gray { background: var(--bg-sunken); color: var(--text-secondary); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--text-tertiary); }

/* ---------- Copy chip ---------- */
.copy {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 4px 6px 4px 10px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--bg-subtle);
  font-family: var(--font-mono); font-size: 12px; color: var(--text-primary); cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.copy:hover { border-color: var(--accent); background: var(--accent-soft); }
.copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy .host { color: var(--text-tertiary); }
.copy svg { color: var(--text-tertiary); }
.copy.done { border-color: var(--accent); color: var(--accent-text); }
.copy-block { display: flex; width: 100%; padding: 10px 12px; font-size: 13px; }

table.t-fixed { table-layout: fixed; }
.t-fixed td { overflow: hidden; text-overflow: ellipsis; }
.t .wrap { white-space: normal; min-width: 160px; }

@media (max-width: 767px) {
  .t-cards thead, .t-cards colgroup { display: none; }
  .t-cards, .t-cards tbody { display: block; }
  .t-cards tbody tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .t-cards tbody tr:last-child { border-bottom: 0; }
  .t-cards td { display: block; padding: 0; border: 0 !important; min-width: 0; text-align: left !important; white-space: normal; overflow: visible; }
  .t-cards td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font-family: var(--font-body); font-size: 10px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-tertiary); }
  .t-cards td.full { grid-column: 1 / -1; }
  .t-cards td.half { grid-column: span 2; }
  .t-cards td.w-actions { grid-column: 1 / -1; width: auto; border-top: 1px dashed var(--border) !important; padding-top: 8px; }
  .t-cards td.w-actions .row-actions { justify-content: flex-start; }
  .t-cards tr.dim td { opacity: .55; }
  .t-cards .copy { max-width: 100%; }
}

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; margin-bottom: var(--s5); }
@media (min-width: 768px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .kpis { grid-template-columns: repeat(6, 1fr); } }
.kpi { background: var(--bg-surface); padding: var(--s4) var(--s5); }
.kpi-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.kpi-label .sw { width: 8px; height: 8px; border-radius: 2px; }
.kpi-value { margin-top: 6px; font-family: var(--font-mono); font-size: 26px; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-value small { font-size: 15px; color: var(--text-tertiary); margin-left: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.t th {
  position: sticky; top: 0; z-index: 1; background: var(--bg-subtle);
  text-align: left; font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-tertiary);
  padding: 10px var(--s4); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.t td { padding: 12px var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tbody tr:last-child td { border-bottom: 0; }
.t tbody tr { transition: background var(--fast) var(--ease); }
.t tbody tr:hover { background: var(--bg-hover); }
.t .r { text-align: right; }
.t td.r, .t td.n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.t th.r { text-align: right; }
.t .w-actions { width: 1%; white-space: nowrap; text-align: right; }
.t tfoot td { background: var(--bg-subtle); font-weight: 650; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.t tr.dim td { opacity: .5; }
.t tr.dim td.w-actions { opacity: 1; }
.cell-title { font-weight: 600; color: var(--text-primary); }
.cell-title a:hover { text-decoration: underline; }
.cell-sub { font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: 2px; display: flex; align-items: center; gap: 4px; }
.v-green { color: var(--accent-text); }
.v-amber { color: var(--amber); }
.v-zero { color: var(--text-tertiary); }
.bar { height: 4px; border-radius: 2px; background: var(--bg-sunken); overflow: hidden; margin-top: 6px; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.empty { padding: var(--s9) var(--s5); text-align: center; color: var(--text-secondary); }
.empty svg { width: 32px; height: 32px; stroke: var(--text-tertiary); margin-bottom: var(--s3); }
.empty b { display: block; color: var(--text-primary); font-size: var(--fs-md); margin-bottom: 4px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end; }
.toolbar .field { min-width: 150px; flex: 1 1 150px; }
@media (min-width: 1024px) { .toolbar .field { flex: 0 1 200px; } }
.filters { padding: var(--s4) var(--s5); }
.filters-row + .filters-row { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border); }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); pointer-events: none; }
.search .input { padding-left: 34px; }

/* ---------- Alerts / toast ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); font-size: var(--fs-base); margin-bottom: var(--s5); border: 1px solid; }
.alert svg { margin-top: 1px; }
.alert-ok { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.alert-err { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.alert-warn { background: var(--amber-soft); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.toast { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 60; animation: toast-in 240ms var(--ease), toast-out 300ms var(--ease) 4.2s forwards; box-shadow: var(--shadow-md); margin: 0; max-width: min(420px, calc(100vw - 40px)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); visibility: hidden; } }

/* ---------- Dialog ---------- */
dialog.modal {
  white-space: normal; text-align: left; font-weight: 400;
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 0; width: min(640px, calc(100vw - 24px));
  background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-lg); max-height: calc(100vh - 48px);
}
dialog.modal[open] { animation: modal-in 180ms var(--ease); }
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: var(--fs-md); }
.modal-body { padding: var(--s5); display: grid; gap: var(--s4); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--border); background: var(--bg-subtle); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.modal .icon-btn { color: var(--text-secondary); }
.modal .icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ---------- Groups (funnels) ---------- */
.group-head { display: flex; align-items: center; gap: var(--s3); }
.group-icon { width: 30px; height: 30px; border-radius: var(--r-md); background: var(--bg-sunken); display: grid; place-items: center; color: var(--text-secondary); flex: none; }
.group-icon.on { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- File list ---------- */
.files { border: 1px solid var(--border); border-radius: var(--r-md); max-height: 300px; overflow: auto; }
.files a { display: flex; justify-content: space-between; gap: var(--s3); padding: 8px 12px; font-family: var(--font-mono); font-size: 12px; border-bottom: 1px solid var(--border); }
.files a:last-child { border-bottom: 0; }
.files a:hover { background: var(--bg-hover); }
.files .sz { color: var(--text-tertiary); flex: none; }

/* ---------- Docs blocks ---------- */
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.steps li { counter-increment: s; position: relative; padding-left: 36px; color: var(--text-secondary); line-height: 1.55; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--bg-sunken); color: var(--text-primary); font-family: var(--font-mono); font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.steps b { color: var(--text-primary); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: var(--fs-base); }
.kv dt { font-family: var(--font-mono); font-size: 13px; color: var(--text-primary); }
.kv dd { margin: 0; color: var(--text-secondary); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr; background: var(--bg-app); }
@media (min-width: 1024px) { .auth { grid-template-columns: 1.1fr 1fr; } }
.auth-art { display: none; position: relative; overflow: hidden; background: var(--bg-sidebar); color: #ececea; padding: var(--s8); }
@media (min-width: 1024px) { .auth-art { display: flex; flex-direction: column; justify-content: space-between; } }
.auth-art .brand { padding: 0; }
.auth-art h2 { font-size: 40px; line-height: 1.1; letter-spacing: -.03em; max-width: 12ch; font-weight: 650; }
.auth-art p { color: #8b8d94; margin-top: var(--s4); max-width: 40ch; font-size: var(--fs-md); }
.auth-bars { position: absolute; right: -40px; bottom: -20px; display: flex; align-items: flex-end; gap: 14px; opacity: .9; }
.auth-bars i { width: 46px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg, var(--accent-hover), rgba(47, 184, 102, .15)); }
.auth-form { display: grid; place-items: center; padding: var(--s6); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: var(--fs-2xl); letter-spacing: -.02em; }
.auth-card .sub { color: var(--text-secondary); margin: 6px 0 var(--s6); }

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

.modal .form-grid, .card-pad .form-grid { align-items: start; }
.modal .form-grid .check { min-height: 38px; }
