/* Project Obsidian - warm-toned design system (dark "obsidian" default, parchment light theme) */
:root {
  --bg: #141413;
  --bg-2: #1c1b18;
  --surface: #252420;
  --surface-2: #2d2c28;
  --line: #34332e;
  --line-2: #45443e;
  --text: #ece9df;
  --text-2: #b0aea5;
  --text-3: #87867f;
  --accent: #d97757;
  --accent-strong: #c96442;
  --accent-ink: #1a0f0a;
  --ok: #7fa37a;
  --ok-bg: rgba(127, 163, 122, .14);
  --warn: #d4a24c;
  --warn-bg: rgba(212, 162, 76, .14);
  --bad: #d0605a;
  --bad-bg: rgba(208, 96, 90, .15);
  --info: #8fa6c4;
  --info-bg: rgba(143, 166, 196, .14);
  --muted-bg: rgba(176, 174, 165, .12);
  --focus: #3898ec;
  --ring: 0 0 0 1px var(--line);
  --ring-2: 0 0 0 1px var(--line-2);
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Roboto Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f4ed; --bg-2: #efede4; --surface: #faf9f5; --surface-2: #f0eee6; --line: #e8e6dc; --line-2: #d1cfc5;
    --text: #141413; --text-2: #4d4c48; --text-3: #87867f; --accent: #c96442; --accent-strong: #b5573a; --accent-ink: #fff;
    --ok: #4f7a4a; --warn: #9a6b12; --bad: #b53333; --info: #3f5f86; --shadow: 0 8px 28px rgba(20, 20, 19, .08);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f4ed; --bg-2: #efede4; --surface: #faf9f5; --surface-2: #f0eee6; --line: #e8e6dc; --line-2: #d1cfc5;
  --text: #141413; --text-2: #4d4c48; --text-3: #87867f; --accent: #c96442; --accent-strong: #b5573a; --accent-ink: #fff;
  --ok: #4f7a4a; --warn: #9a6b12; --bad: #b53333; --info: #3f5f86; --shadow: 0 8px 28px rgba(20, 20, 19, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14.5px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
code, pre, .mono { font-family: var(--mono); font-size: .86em; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--bg-2); padding: 14px; border-radius: var(--r-sm);
      box-shadow: var(--ring); max-height: 480px; overflow: auto; margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--bg-2); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0;
        height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; flex: none; }
.brand b { font-family: var(--serif); font-weight: 500; font-size: 1.25rem; letter-spacing: .01em; }
.brand small { display: block; color: var(--text-3); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.nav-label { color: var(--text-3); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-sm); color: var(--text-2); }
.nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--surface); color: var(--text); box-shadow: var(--ring); }
.nav a svg { width: 17px; height: 17px; opacity: .8; flex: none; }
.nav .count { margin-left: auto; font-size: .72rem; background: var(--surface-2); padding: 0 7px; border-radius: 99px; color: var(--text-2); }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); color: var(--text-3); font-size: .8rem; }
.side-foot .who { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .row { display: flex; gap: 12px; margin-top: 6px; }
main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 32px; border-bottom: 1px solid var(--line);
          background: color-mix(in srgb, var(--bg) 88%, transparent); position: sticky; top: 0; z-index: 5;
          backdrop-filter: blur(6px); }
.topbar .crumbs { color: var(--text-3); font-size: .88rem; }
.topbar .crumbs a { color: var(--text-2); }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 28px 32px 64px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { color: var(--text-2); margin: 0; max-width: 70ch; }

/* ---------- cards & grid */
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--ring); padding: 20px; min-width: 0; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card h2, .card h3 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }
.kpi { padding: 18px 20px; }
.kpi .label { color: var(--text-3); font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
.kpi .value { font-family: var(--serif); font-size: 2rem; line-height: 1.15; margin-top: 4px; }
.kpi .sub { color: var(--text-2); font-size: .84rem; }
.kpi.accent .value { color: var(--accent); }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }
.muted { color: var(--text-3); }
.dim { color: var(--text-2); }
.small { font-size: .84rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.gap-lg { gap: 18px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--text-3); font-size: .76rem; letter-spacing: .06em; text-transform: uppercase;
     padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
tr.clickable { cursor: pointer; }
td .sub { display: block; color: var(--text-3); font-size: .8rem; }
.kv { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 6px 16px; }
.kv dt { color: var(--text-3); font-size: .86rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .76rem; font-weight: 500; white-space: nowrap;
         background: var(--muted-bg); color: var(--text-2); text-transform: capitalize; }
.tone-ok { background: var(--ok-bg); color: var(--ok); }
.tone-warn { background: var(--warn-bg); color: var(--warn); }
.tone-bad { background: var(--bad-bg); color: var(--bad); }
.tone-info { background: var(--info-bg); color: var(--info); }
.tone-muted { background: var(--muted-bg); color: var(--text-2); }
.score { font-family: var(--mono); font-size: .85rem; padding: 1px 8px; border-radius: 6px; }
.score.bad { background: var(--bad-bg); color: var(--bad); }
.score.warn { background: var(--warn-bg); color: var(--warn); }
.score.ok { background: var(--ok-bg); color: var(--ok); }
.score.muted { background: var(--muted-bg); color: var(--text-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--text-3); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

/* ---------- forms */
label { display: block; font-size: .86rem; color: var(--text-2); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field .help { color: var(--text-3); font-size: .8rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=file],
select, textarea {
  width: 100%; background: var(--bg-2); color: var(--text); border: 0; box-shadow: var(--ring-2); border-radius: var(--r-sm);
  padding: 9px 12px; font: inherit; font-size: .93rem;
}
textarea { min-height: 90px; resize: vertical; font-family: var(--mono); font-size: .85rem; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 2px var(--focus); }
.check { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: .92rem; margin-bottom: 10px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 130px; }
.filters .grow { flex: 1; min-width: 220px; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 0; cursor: pointer; font: inherit; font-size: .9rem;
       padding: 8px 15px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text); box-shadow: var(--ring-2);
       text-decoration: none; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.primary { background: var(--accent-strong); color: #fff; box-shadow: none; }
.btn.danger { background: var(--bad-bg); color: var(--bad); box-shadow: 0 0 0 1px color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--text-2); }
.btn.sm { padding: 4px 10px; font-size: .82rem; }
.btn svg { width: 15px; height: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- flash */
.flashes { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 10px 14px; border-radius: var(--r-sm); background: var(--ok-bg); color: var(--ok); overflow-wrap: anywhere; }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- misc */
.hit-list { display: grid; gap: 6px; }
.hit { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 8px 10px;
       border-radius: var(--r-sm); background: var(--bg-2); }
.hit .rule { font-family: var(--mono); font-size: .78rem; color: var(--text-3); }
.ai-box { border-radius: var(--r); padding: 16px 18px; background: linear-gradient(0deg, var(--surface), var(--surface)); box-shadow: 0 0 0 1px var(--accent-strong); }
.ai-box .head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.stage { border-radius: var(--r-sm); background: var(--bg-2); padding: 12px 14px; }
.stage + .stage { margin-top: 8px; }
.stage summary { cursor: pointer; display: flex; gap: 10px; align-items: center; list-style: none; }
.stage summary::-webkit-details-marker { display: none; }
.empty { text-align: center; padding: 42px 20px; color: var(--text-3); }
.empty h3 { color: var(--text-2); }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.chart-box { position: relative; height: 260px; }
.bar { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; position: relative; padding: 0 0 16px 40px; }
.steps li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%;
                    background: var(--surface-2); box-shadow: var(--ring-2); display: grid; place-items: center; font-size: .8rem; }
.copy { font-family: var(--mono); font-size: .82rem; background: var(--bg-2); padding: 6px 10px; border-radius: 6px;
        box-shadow: var(--ring); overflow-wrap: anywhere; display: block; }
.preview-text { white-space: pre-wrap; font-size: .9rem; color: var(--text-2); max-height: 360px; overflow: auto;
                background: var(--bg-2); border-radius: var(--r-sm); padding: 14px; }
.theme-toggle { background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 0; font: inherit; font-size: .8rem; }
.theme-toggle:hover { color: var(--text); }

/* ---------- auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
        background: radial-gradient(1200px 600px at 20% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--ring), var(--shadow); padding: 32px; }
.auth-card .brand { justify-content: center; padding-bottom: 22px; }
.auth-card h1 { font-size: 1.5rem; text-align: center; }
.auth-card .lead { color: var(--text-2); text-align: center; margin-bottom: 22px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 10px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: .8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- responsive */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-side { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open .side { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 16px 48px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .trunc { max-width: 200px; }
  .hide-sm { display: none; }
}
/* phone: tables marked .cards become one card per row (user quarantine / recent mail) */
@media (max-width: 640px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.cards td { border: 0; padding: 3px 0; white-space: normal; text-align: left; }
  table.cards td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; letter-spacing: .08em;
                                       text-transform: uppercase; color: var(--text-3); }
  table.cards td .trunc { max-width: 100% !important; white-space: normal; }
  table.cards td.cell-actions .btn-row { justify-content: flex-start !important; margin-top: 6px; }
  table.cards tbody tr:hover td { background: none; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr; } h1 { font-size: 1.5rem; } }

/* ---------- documentation */
.docs { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 32px; align-items: start; }
.docs-toc { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.docs-toc a { color: var(--text-2); padding: 5px 10px; border-radius: var(--r-sm); font-size: .88rem; }
.docs-toc a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.docs-toc a.on { background: var(--surface); color: var(--text); box-shadow: var(--ring); }
.doc { max-width: 880px; min-width: 0; }
.doc h1 { margin-bottom: 18px; }
.doc [id] { scroll-margin-top: 84px; }
.doc h2 { margin-top: 38px; padding-top: 6px; border-top: 1px solid var(--line); }
.doc h3 { margin-top: 26px; }
.doc p, .doc li { color: var(--text); line-height: 1.7; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li + li { margin-top: 4px; }
.doc code { background: var(--bg-2); padding: 1px 6px; border-radius: 5px; box-shadow: var(--ring); overflow-wrap: anywhere; }
.doc pre code { background: none; box-shadow: none; padding: 0; }
.doc pre { margin: 12px 0; }
.doc table { margin: 12px 0 18px; font-size: .9rem; }
.doc td, .doc th { vertical-align: top; }
.doc .lead { font-size: 1.05rem; color: var(--text-2); }
.doc .shot { border-radius: var(--r); box-shadow: var(--ring); padding: 14px 18px; background: var(--surface); margin: 12px 0; }
.note, .warn, .tip { border-radius: var(--r-sm); padding: 12px 16px; margin: 14px 0; box-shadow: 0 0 0 1px var(--line); }
.note { background: var(--info-bg); }
.warn { background: var(--warn-bg); }
.tip { background: var(--ok-bg); }
.note b:first-child, .warn b:first-child, .tip b:first-child { display: block; margin-bottom: 2px; }
.fields { display: grid; grid-template-columns: minmax(150px, 230px) minmax(0, 1fr); gap: 0; margin: 12px 0 18px;
          border-radius: var(--r-sm); box-shadow: var(--ring); overflow: hidden; }
.fields > dt, .fields > dd { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.fields > dt { font-weight: 500; background: var(--bg-2); }
.fields > dt .mono { font-weight: 400; color: var(--text-3); display: block; font-size: .78rem; }
.fields > dd .def { color: var(--text-3); font-size: .82rem; display: block; margin-top: 3px; }
.fields > dt:nth-last-of-type(1), .fields > dd:last-child { border-bottom: 0; }
.doc-pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.doc-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.doc-cards a { display: block; padding: 14px 16px; border-radius: var(--r); background: var(--surface); box-shadow: var(--ring); color: var(--text); }
.doc-cards a:hover { text-decoration: none; box-shadow: 0 0 0 1px var(--accent-strong); }
.doc-cards a span { display: block; color: var(--text-2); font-size: .86rem; margin-top: 2px; }
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 12px 0; font-size: .86rem; }
.flow span { background: var(--surface); box-shadow: var(--ring); border-radius: 99px; padding: 3px 11px; }
.flow i { color: var(--text-3); font-style: normal; }
.docs-public .docs-top { display: flex; align-items: center; gap: 12px; padding: 12px 32px; border-bottom: 1px solid var(--line);
                         position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(6px); }
.docs-public .docs-top .brand { padding: 0; }
.docs-public .spacer { flex: 1; }
.docs-public .content { max-width: 1240px; margin: 0 auto; }
@media (max-width: 960px) {
  .docs { grid-template-columns: 1fr; }
  .docs-toc { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .docs-toc .nav-label { width: 100%; }
  .fields { grid-template-columns: 1fr; }
  .fields > dt { border-bottom: 0; padding-bottom: 2px; }
  .doc-cards { grid-template-columns: 1fr; }
  .docs-public .docs-top { padding: 10px 16px; }
}
