:root {
  --bg: #faf9f6;
  --bg-raised: #ffffff;
  --ink: #1b1d1c;
  --ink-soft: #55534c;
  --line: #e4e0d6;
  --line-strong: #cfc9ba;
  --accent: #4636e3;
  --accent-ink: #ffffff;
  --accent-soft: #eae6fc;
  --status-contacted: #5b7db1;
  --status-proposal: #b8862b;
  --status-won: #1f8a5c;
  --status-lost: #9a938a;
  --status-critical: #c0392b;
  --status-warn: #b8862b;
  --status-ok: #1f8a5c;
  --shadow: 0 1px 2px rgba(27, 29, 28, 0.04), 0 8px 24px rgba(27, 29, 28, 0.06);
  --radius: 10px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-doc: Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181a;
    --bg-raised: #1e2123;
    --ink: #ecebe6;
    --ink-soft: #a8a49a;
    --line: #33362f;
    --line-strong: #46493f;
    --accent: #8d82ff;
    --accent-ink: #15102e;
    --accent-soft: #262048;
    --status-contacted: #7fa0d6;
    --status-proposal: #d9a748;
    --status-won: #34d399;
    --status-lost: #7c766c;
    --status-critical: #e5766a;
    --status-warn: #d9a748;
    --status-ok: #34d399;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #16181a; --bg-raised: #1e2123; --ink: #ecebe6; --ink-soft: #a8a49a;
  --line: #33362f; --line-strong: #46493f; --accent: #8d82ff; --accent-ink: #15102e;
  --accent-soft: #262048; --status-contacted: #7fa0d6; --status-proposal: #d9a748;
  --status-won: #34d399; --status-lost: #7c766c;
  --status-critical: #e5766a; --status-warn: #d9a748; --status-ok: #34d399;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}
:root[data-theme="light"] {
  --bg: #faf9f6; --bg-raised: #ffffff; --ink: #1b1d1c; --ink-soft: #55534c;
  --line: #e4e0d6; --line-strong: #cfc9ba; --accent: #4636e3; --accent-ink: #ffffff;
  --accent-soft: #eae6fc; --status-contacted: #5b7db1; --status-proposal: #b8862b;
  --status-won: #1f8a5c; --status-lost: #9a938a;
  --status-critical: #c0392b; --status-warn: #b8862b; --status-ok: #1f8a5c;
  --shadow: 0 1px 2px rgba(27,29,28,.04), 0 8px 24px rgba(27,29,28,.06);
}

/* Solid, theme-tuned pill colors — NOT translucent tints. A translucent
   status-color-on-page-background pairing (color-mix/rgba tricks) measures
   fine by eye but computes to dangerously low WCAG contrast once the page
   background varies (card vs. page). Each pair below is picked so the ink
   clears 4.5:1 against its solid bg in the theme it's defined for — verified
   by hand (see contrast audit) rather than assumed from the base status hue. */
:root {
  --pill-ok-bg: #2ea36f; --pill-ok-ink: #000000;
  --pill-warn-bg: #b8862b; --pill-warn-ink: #000000;
  --pill-critical-bg: #c0392b; --pill-critical-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pill-ok-bg: #34d399; --pill-ok-ink: #000000;
    --pill-warn-bg: #d9a748; --pill-warn-ink: #000000;
    --pill-critical-bg: #e5766a; --pill-critical-ink: #000000;
  }
}
:root[data-theme="dark"] {
  --pill-ok-bg: #34d399; --pill-ok-ink: #000000;
  --pill-warn-bg: #d9a748; --pill-warn-ink: #000000;
  --pill-critical-bg: #e5766a; --pill-critical-ink: #000000;
}
:root[data-theme="light"] {
  --pill-ok-bg: #2ea36f; --pill-ok-ink: #000000;
  --pill-warn-bg: #b8862b; --pill-warn-ink: #000000;
  --pill-critical-bg: #c0392b; --pill-critical-ink: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
h1, h2, h3 { text-wrap: balance; margin: 0; }
button { font-family: inherit; }
textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { max-width: 1080px; margin: 0 auto; padding: 32px 24px 80px; }
.panel { display: none; }
.panel.is-active { display: block; }
.panel-head { max-width: 680px; margin-bottom: 28px; }
.panel-head h1 { font-size: 24px; letter-spacing: -0.01em; margin-bottom: 8px; }
.panel-head p { color: var(--ink-soft); font-size: 14.5px; line-height: 1.55; margin: 0; }

.workspace { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) { .workspace { grid-template-columns: 1fr; } }

.tool-block { margin-bottom: 44px; }
.tool-block:last-child { margin-bottom: 0; }
.tool-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.tool-head h2 { font-size: 18px; letter-spacing: -0.01em; }
.tool-num {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.tool-desc { color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; margin: 0 0 16px; max-width: 640px; }

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

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--bg-raised);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { display: flex; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-tag { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }

.powered-by {
  display: flex; align-items: baseline; gap: 5px; text-decoration: none;
  font-size: 11px; color: var(--ink-soft); white-space: nowrap; margin-right: 8px;
}
.powered-by strong { color: var(--ink); font-weight: 700; }
.powered-by:hover strong { color: var(--accent); }
@media (max-width: 900px) { .powered-by { display: none; } }

.tabs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; flex-wrap: wrap; }
.tab-btn {
  border: none; background: transparent; color: var(--ink-soft);
  padding: 8px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s; white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.is-active { background: var(--accent); color: var(--accent-ink); }

.theme-toggle {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--bg-raised); color: var(--ink-soft); cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
#themeIconSun, #themeIconMoon { display: none; }
:root[data-theme="dark"] #themeIconSun { display: block; }
:root:not([data-theme="dark"]) #themeIconMoon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #themeIconSun { display: block; }
  :root:not([data-theme="light"]) #themeIconMoon { display: none; }
}

/* Gate */
.gate {
  position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.gate.is-unlocked { display: none; }
.gate-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.gate-mark { display: inline-flex; margin-bottom: 14px; }
.gate-card h1 { font-size: 20px; margin-bottom: 6px; }
.gate-card p { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 18px; }
.gate-card input[type="password"] {
  width: 100%; padding: 11px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--ink); font-size: 14px; text-align: center; margin-bottom: 12px;
}
.gate-card input[type="password"]:focus { border-color: var(--accent); }
.gate-card .primary-btn { width: 100%; padding: 11px 14px; font-size: 14px; }
.gate-error { color: #c0392b; margin: 12px 0 0; display: none; }
.gate-error.is-visible { display: block; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 200;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Form / output */
.form-card, .output-card {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 6px; color: var(--ink); }
.field .optional { font-weight: 400; color: var(--ink-soft); }
.field .hint { display: block; font-weight: 400; font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }
.field input[type="text"], .field input[type="number"], .field input[type="date"],
.field input[type="datetime-local"], .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--ink); font-size: 14px; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-size: 13px; font-weight: 600; }

.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg-btn {
  flex: 1; padding: 8px 10px; border: none; background: var(--bg); color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600; cursor: pointer; border-right: 1px solid var(--line-strong);
  min-width: 80px;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.is-active { background: var(--accent); color: var(--accent-ink); }

.output-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.output-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.output-actions { display: flex; gap: 8px; }
.ghost-btn {
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  padding: 7px 13px; border-radius: 7px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.primary-btn {
  border: none; background: var(--accent); color: var(--accent-ink);
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.07); }
.full-btn { width: 100%; }

.output-placeholder { color: var(--ink-soft); font-size: 13.5px; margin: 0; }

/* Saved list */
.saved-card { margin-top: 18px; }
.saved-list { display: flex; flex-direction: column; gap: 10px; }
.saved-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  flex-wrap: wrap;
}
.saved-item-main { min-width: 0; }
.saved-item-name { font-size: 13.5px; font-weight: 700; color: var(--ink); }
.saved-item-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.saved-actions { display: flex; gap: 8px; flex-shrink: 0; }
.saved-empty { font-size: 13.5px; color: var(--ink-soft); margin: 0; }

/* Score bar */
.score-total { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.score-total .num { font-size: 34px; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; }
.score-total .of { font-size: 14px; color: var(--ink-soft); }
.score-row { margin-bottom: 12px; }
.score-row:last-child { margin-bottom: 0; }
.score-row-head { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.score-row-head .pct { color: var(--ink-soft); font-weight: 700; }
.score-bar-track { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 999px; background: var(--status-ok); transition: width .25s; }
.score-bar-fill.is-low { background: var(--status-critical); }
.score-bar-fill.is-mid { background: var(--status-warn); }
.score-note { font-size: 12.5px; color: var(--ink-soft); margin: 4px 0 0; line-height: 1.5; }
.score-note.is-flag { color: var(--status-critical); font-weight: 600; }

/* Badge / pill */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill-ok { background: var(--pill-ok-bg); color: var(--pill-ok-ink); }
.pill-warn { background: var(--pill-warn-bg); color: var(--pill-warn-ink); }
.pill-critical { background: var(--pill-critical-bg); color: var(--pill-critical-ink); }
.pill-neutral { background: var(--accent); color: var(--accent-ink); }

/* Rule check list (Compliance) */
.rule-list { display: flex; flex-direction: column; gap: 10px; margin: 0 0 4px; }
.rule-item { display: flex; gap: 10px; padding: 10px 12px; border-radius: 9px; background: var(--bg); border: 1px solid var(--line); }
.rule-icon { flex-shrink: 0; font-size: 15px; line-height: 1.3; }
.rule-body { min-width: 0; }
.rule-title { font-size: 13px; font-weight: 700; }
.rule-detail { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; line-height: 1.5; }
.rule-quote { font-size: 12px; color: var(--ink-soft); font-style: italic; margin-top: 4px; border-left: 2px solid var(--line-strong); padding-left: 8px; }

/* Generated text block */
.gen-block { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 10px; }
.gen-block:last-child { margin-bottom: 0; }
.gen-block h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin: 0 0 6px; }
.gen-block p { font-size: 13.5px; line-height: 1.6; margin: 0; white-space: pre-wrap; }

/* Simple data table (Pulse) */
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-soft); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.data-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }

/* Guide */
.guide { display: flex; flex-direction: column; gap: 22px; max-width: 760px; }
.guide-section {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
.guide-section h2 { display: flex; align-items: center; gap: 10px; font-size: 16px; margin-bottom: 8px; }
.guide-section h3 { font-size: 14px; margin: 16px 0 8px; color: var(--accent); }
.guide-number {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 700; flex-shrink: 0;
}
.guide-section > p { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 12px; }
.guide-section ol, .guide-section ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.guide-section li { font-size: 13.5px; line-height: 1.55; }
.guide-note { background: var(--accent-soft); border-color: transparent; }
.ui-ref {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 12.5px; padding: 1px 7px; border-radius: 5px;
}
