:root {
  --bg: #faf9f6; --bg-raised: #ffffff; --ink: #1b1d1c; --ink-soft: #55534c;
  --line: #e4e0d6; --line-strong: #cfc9ba; --accent: #4636e3; --accent-ink: #ffffff;
  --accent-soft: #eae6fc; --ok: #16694a; --warn: #8a5a00; --danger: #b3261e;
  --shadow: 0 1px 2px rgba(27,29,28,.04), 0 8px 24px rgba(27,29,28,.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 {
    --bg: #16181a; --bg-raised: #1e2123; --ink: #ecebe6; --ink-soft: #a8a49a;
    --line: #33362f; --line-strong: #46493f; --accent: #8d82ff; --accent-ink: #15102e;
    --accent-soft: #262048; --ok: #34d399; --warn: #e0b04a; --danger: #ff8a7a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(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; --ok: #34d399; --warn: #e0b04a; --danger: #ff8a7a;
  --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; --ok: #16694a; --warn: #8a5a00; --danger: #b3261e;
  --shadow: 0 1px 2px rgba(27,29,28,.04), 0 8px 24px rgba(27,29,28,.06);
}

* { 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 { text-wrap: balance; margin: 0; }
button { 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: 640px; margin-bottom: 20px; }
.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(260px, 360px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) { .workspace { grid-template-columns: 1fr; } .app { padding: 24px 16px 80px; } }
@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: .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; } .topbar { gap: 12px; padding: 12px 16px; } }
.tabs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; max-width: 100%; overflow-x: auto; }
.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: 340px; 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-card p.gate-error { color: var(--danger); margin: 12px 0 0; display: none; }
.gate-card p.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); }

/* sub tabs */
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.subtab-btn { border: 1px solid var(--line-strong); background: var(--bg-raised); color: var(--ink-soft); padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.subtab-btn:hover { border-color: var(--accent); color: var(--ink); }
.subtab-btn.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tool { display: none; }
.tool.is-active { display: block; }
.tool-intro { font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; margin: 0 0 16px; max-width: 700px; }

/* forms + outputs */
.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: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink); }
.field label .lab { display: block; margin-bottom: 6px; }
.field .optional { font-weight: 400; color: var(--ink-soft); }
.field input[type="text"], .field input[type="number"], .field input[type="date"], .field select, .field textarea, .mini-input {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); font-size: 14px; font-family: inherit; }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.client-row input { width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); font-size: 14px; font-family: inherit; min-width: 0; }
.client-row input:focus { border-color: var(--accent); }
.field input:focus, .field select:focus, .field textarea:focus, .mini-input:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: stretch; margin-bottom: 14px; }
.field-row > .field { margin-bottom: 0; display: flex; min-width: 0; }
.field-row > .field > label { display: flex; flex-direction: column; width: 100%; min-width: 0; }
.field-row > .field > label .lab { flex: 1; }
.field input[type="text"], .field input[type="number"], .field input[type="date"], .field select { height: 40px; }
.field-hint { font-size: 12px; color: var(--ink-soft); margin: 6px 0 0; line-height: 1.45; }
.sec-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); margin: 18px 0 10px; }
.sec-title:first-child { margin-top: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; margin-bottom: 6px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.job-row { display: grid; grid-template-columns: 1fr 78px 64px; gap: 8px; align-items: center; margin-bottom: 8px; }
.job-row .jn { font-size: 13px; font-weight: 600; }
.job-row .est { font-weight: 400; color: var(--ink-soft); font-size: 11.5px; }
.job-head { display: grid; grid-template-columns: 1fr 78px 64px; gap: 8px; font-size: 11.5px; color: var(--ink-soft); margin-bottom: 4px; }
.client-row { display: grid; grid-template-columns: 1fr 80px; gap: 8px; margin-bottom: 8px; }
.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.list-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--bg); }
.list-row span { min-width: 0; overflow-wrap: anywhere; }

.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: .04em; color: var(--ink-soft); }
.output-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.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); }
.output-placeholder { color: var(--ink-soft); font-size: 14px; margin: 0; }
.out-text { font-family: var(--font-doc); font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; margin: 0 0 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); }
.kpi .kl { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.kpi .kv { font-size: 20px; font-weight: 700; margin-top: 2px; }
.verdict { font-size: 14px; font-weight: 700; margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg); }
.verdict.ok { color: var(--ok); border-color: var(--ok); }
.verdict.warn { color: var(--warn); border-color: var(--warn); }
.verdict.bad { color: var(--danger); border-color: var(--danger); }
.bar { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 4px 0 12px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.over > i { background: var(--danger); }
.bar-label { font-size: 12.5px; color: var(--ink-soft); display: flex; justify-content: space-between; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-bottom: 12px; }
table.data th, table.data td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.note { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; margin: 0 0 10px; }
.list-plain { margin: 0 0 12px; padding-left: 18px; font-size: 13.5px; line-height: 1.55; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-soft); }
.pill.low { color: var(--ok); border-color: var(--ok); }
.pill.medium { color: var(--warn); border-color: var(--warn); }
.pill.high { color: var(--danger); border-color: var(--danger); }
.swatches { display: flex; gap: 8px; margin-bottom: 12px; }
.swatch { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line-strong); }
.rev-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--bg); font-size: 13.5px; line-height: 1.5; }
.rev-item .orig { color: var(--ink-soft); font-size: 12.5px; }

/* saved */
.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; }
.saved-item-main { min-width: 0; }
.saved-item-name { font-size: 13.5px; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.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; }

/* guide */
.guide { display: flex; flex-direction: column; gap: 22px; max-width: 720px; }
.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-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; line-height: 1.55; }
.guide-section h3 { font-size: 14px; margin: 14px 0 6px; }
.guide-section ol { 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; }
.guide-note .ui-ref { background: var(--bg-raised); }

/* printable price sheet — fixed light "paper" */
.sheet { background: #ffffff; color: #1b1d1c; border: 1px solid #cfc9ba; border-radius: 8px; padding: 28px 30px; font-family: var(--font-doc); }
.sheet h2 { font-size: 22px; margin-bottom: 4px; }
.sheet .s-tag { color: #55534c; font-size: 14px; margin: 0 0 18px; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: #4636e3; margin: 18px 0 8px; font-family: var(--font-ui); }
.sheet table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sheet td { padding: 7px 0; border-bottom: 1px solid #e4e0d6; vertical-align: top; }
.sheet td.p { text-align: right; font-weight: 700; white-space: nowrap; padding-left: 12px; }
.sheet .s-sub { color: #55534c; font-size: 12.5px; }
.sheet .s-foot { margin-top: 18px; font-size: 12.5px; color: #55534c; line-height: 1.5; }
@media print {
  body * { visibility: hidden !important; }
  .sheet, .sheet * { visibility: visible !important; }
  .sheet { position: absolute; left: 0; top: 0; width: 100%; border: none; }
  .gate { display: none !important; }
}

@media (max-width: 600px) {
  .tabs { width: 100%; order: 3; }
  .tab-btn { flex: 1; padding: 8px 6px; font-size: 13px; }
  .brand { margin-right: 0; flex: 1; }
}

:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
