:root {
  --ink: #13293D;
  --ink-2: #3D4F61;
  --muted: #6B7785;
  --line: #E1DED6;
  --line-2: #ECE9E2;
  --paper: #F6F4EF;
  --card: #FFFFFF;
  --accent: #2F7D6D;
  --accent-ink: #1E5A4E;
  --accent-soft: #E3F1EC;
  --forecast: #F3F0FA;
  --forecast-ink: #5B4B8A;
  --warn: #9A5B00;
  --warn-soft: #FFF4E0;
  --danger: #A3312A;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --serif: "Fraunces", Georgia, serif;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
.boot { padding: 40px; color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-family: var(--serif); font-size: 28px; letter-spacing: -.01em; }
h2 { font-family: var(--serif); font-size: 21px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand { background: var(--ink); color: #E8EEF3; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-brand h1 { color: #fff; font-size: 40px; line-height: 1.1; max-width: 12ch; }
.auth-brand p { max-width: 40ch; color: #B9C6D2; }
.auth-brand > svg { position: absolute; right: -40px; bottom: 60px; opacity: .9; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .02em; }
.brand .logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-form form { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.auth-switch { font-size: 13px; color: var(--muted); }
.auth-switch button { background: none; border: 0; color: var(--accent-ink); cursor: pointer; padding: 0; text-decoration: underline; }

.auth-form { position: relative; }
.auth-lang { position: absolute; top: 20px; right: 24px; }
select.lang { padding: 5px 8px; font-size: 12.5px; border-radius: 7px; }
select.lang.dark { background: rgba(255,255,255,.08); color: #E8EEF3; border-color: rgba(255,255,255,.18); }
select.lang.dark option { color: var(--ink); }

/* ---------- forms ---------- */
label.field { display: grid; gap: 5px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input.cell, select {
  border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 8px 10px; outline: none; min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; display: inline-flex; gap: 8px; align-items: center; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #0B1B2A; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.seg { display: inline-flex; background: var(--line-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(19,41,61,.12); }

/* ---------- shell ---------- */
.topbar { height: 56px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; position: sticky; top: 0; z-index: 10; }
.topbar .brand { cursor: pointer; }
.topbar .user { display: flex; gap: 12px; align-items: center; font-size: 13px; color: #B9C6D2; }
.topbar .btn.ghost { color: #E8EEF3; }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.08); }
.page { max-width: 1180px; margin: 0 auto; padding: 32px 24px 80px; }

/* projects */
.proj-head { display: flex; justify-content: space-between; align-items: end; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.proj { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; cursor: pointer; display: grid; gap: 6px; transition: border-color .15s; }
.proj:hover { border-color: var(--ink-2); }
.proj .name { font-weight: 600; font-size: 16px; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--r); padding: 40px; text-align: center; color: var(--muted); }

/* workspace */
.ws { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.side { border-right: 1px solid var(--line); padding: 24px 14px; background: #FBFAF7; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; }
.side .pname { font-weight: 600; padding: 0 10px 4px; }
.side .psub { font-size: 12px; color: var(--muted); padding: 0 10px 18px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: s; }
.steps button { width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: center; color: var(--ink-2); }
.steps button::before { counter-increment: s; content: counter(s); width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 11.5px; font-family: var(--mono); background: #fff; flex: none; }
.steps button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(19,41,61,.08); }
.steps button.on::before { background: var(--ink); color: #fff; border-color: var(--ink); }
.steps button.done::before { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.side .saving { font-size: 12px; color: var(--muted); padding: 16px 10px; }
.main { padding: 28px 32px 80px; min-width: 0; }
.main-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.main-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 16px; }
.card > h3 { margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.notice { background: var(--warn-soft); border: 1px solid #F1D7A6; color: var(--warn); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.info { background: var(--accent-soft); border: 1px solid #BFE0D5; color: var(--accent-ink); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }

/* dropzone */
.drop { display: block; border: 1.5px dashed #C9C4B8; border-radius: var(--r); padding: 28px; text-align: center; background: #FBFAF7; cursor: pointer; transition: all .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { display: block; font-size: 15px; margin-bottom: 4px; }
.drop input { display: none; }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 6px 10px; border-bottom: 1px solid var(--line-2); text-align: right; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; position: sticky; left: 0; background: inherit; }
.tbl thead th { background: #FBFAF7; font-weight: 600; color: var(--ink-2); font-size: 12px; position: sticky; top: 0; }
.tbl tbody tr { background: #fff; }
.tbl tr.group td { background: #FBFAF7; font-weight: 600; color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tbl tr.total td { font-weight: 600; border-top: 1px solid var(--line); background: #FDFCFA; }
.tbl tr.grand td { font-weight: 600; border-top: 2px solid var(--ink); background: #fff; }
.tbl td.fc, .tbl th.fc { background: var(--forecast); }
.tbl th.fc { color: var(--forecast-ink); }
.tbl td.label { color: var(--ink); white-space: normal; min-width: 240px; }
.tbl td.zero { color: #B5BBC3; }
input.cell { width: 100px; text-align: right; padding: 4px 6px; border-color: transparent; background: transparent; font-family: var(--mono); font-size: 12.5px; border-radius: 5px; }
input.cell:hover { border-color: var(--line); background: #fff; }
input.cell:focus { background: #fff; }
input.cell.ovr { background: #FFF8E6; border-color: #F1D7A6; }
input.cell.wide { width: 120px; }
.tbl td .badge, .badge { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); font-weight: 500; letter-spacing: .02em; }
.badge.saft { background: var(--accent-soft); color: var(--accent-ink); }
.badge.manual { background: #FFF1D6; color: var(--warn); }
.badge.fc { background: var(--forecast); color: var(--forecast-ink); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.legend-row { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; border: 1px solid var(--line); }

/* questionnaire */
.qcat { margin-bottom: 18px; }
.qcat h4 { margin: 0 0 8px; font-size: 13.5px; }
.q { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.q:last-child { border-bottom: 0; }
.score { display: inline-flex; gap: 3px; }
.score button { width: 30px; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-family: var(--mono); font-size: 12.5px; }
.score button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.scale-hint { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); width: 198px; margin-left: auto; }

/* results */
.hero { background: var(--ink); color: #fff; border-radius: 14px; padding: 28px 30px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: end; margin-bottom: 16px; }
.hero .lbl { color: #B9C6D2; font-size: 13px; }
.hero .val { font-family: var(--serif); font-size: 48px; line-height: 1.05; letter-spacing: -.02em; margin: 6px 0; }
.hero .val small { font-family: var(--sans); font-size: 16px; color: #B9C6D2; margin-left: 6px; }
.hero .seg { background: rgba(255,255,255,.1); }
.hero .seg button { color: #CFD9E2; }
.hero .seg button.on { background: #fff; color: var(--ink); }
.methods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.mcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.mcard.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.mcard .t { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; }
.mcard .v { font-family: var(--serif); font-size: 26px; margin: 6px 0 10px; }
.bridge { width: 100%; font-size: 13px; border-collapse: collapse; }
.bridge td { padding: 4px 0; border-bottom: 1px solid var(--line-2); }
.bridge td:last-child { text-align: right; font-family: var(--mono); }
.bridge tr.tot td { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--ink); }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--sans); font-size: 11px; fill: var(--muted); }
.chart .lab { fill: var(--ink); font-size: 12px; }
.chart .v { font-family: var(--mono); fill: var(--ink-2); font-size: 11px; }
.tip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; z-index: 50; opacity: 0; transition: opacity .1s; }
.kf-tbl td.label { min-width: 220px; }

.modal-back { position: fixed; inset: 0; background: rgba(19,41,61,.45); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 24px; max-width: 540px; width: 100%; box-shadow: 0 20px 50px rgba(19,41,61,.25); }
.modal h2 { margin-bottom: 8px; }
.modal p { color: var(--ink-2); margin: 0 0 18px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: all .2s; pointer-events: none; font-size: 13px; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }

@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 32px; min-height: 220px; }
  .auth-brand > svg { display: none; }
  .ws { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .steps { grid-auto-flow: column; overflow-x: auto; }
  .steps button { white-space: nowrap; }
  .main { padding: 20px 16px 60px; }
  .methods, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .cols-2 { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .hero .val { font-size: 36px; }
  .q { grid-template-columns: 1fr; }
  .scale-hint { margin-left: 0; }
}
