:root {
  --bg: #f3f1ec;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --surface-3: #e7e3d9;
  --text: #1b2226;
  --muted: #5b666c;
  --border: #ddd7ca;
  --accent: #1f5f73;
  --accent-strong: #174a5a;
  --accent-text: #ffffff;
  --accent-soft: #e0edf1;
  --gold: #b8862b;
  --danger: #a3372b;
  --ok: #2f7a4f;
  --mark: #ffe58a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 35, 0.05), 0 6px 20px rgba(20, 30, 35, 0.06);
  --topbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171a;
    --surface: #182024;
    --surface-2: #1f292e;
    --surface-3: #263238;
    --text: #e7ecee;
    --muted: #98a5ab;
    --border: #2e3b42;
    --accent: #72b8cc;
    --accent-strong: #9bd0de;
    --accent-text: #0c191e;
    --accent-soft: #1c3640;
    --gold: #d9a94a;
    --danger: #e3796c;
    --ok: #6cc394;
    --mark: #6b5a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); }

body {
  background: var(--bg);
  color: var(--text);
  font: 16.5px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.85rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

.muted { color: var(--muted); }
.error { color: var(--danger); }

button, .button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1.05rem;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover, .button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: default; }
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.secondary:hover, .button.secondary:hover { background: var(--accent-soft); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.link-btn { background: none; border: 1px solid transparent; color: var(--muted); padding: 0.4rem 0.8rem; font-weight: 500; }
.link-btn:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.25rem 1.75rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card form { text-align: left; display: grid; gap: 0.6rem; margin-top: 1rem; }
.login-card button { margin-top: 0.4rem; justify-content: center; }
.login-logo { display: block; margin: 0 auto 0.5rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: var(--topbar-h);
  padding: 0 clamp(16px, 2.5vw, 40px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 750; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand img { border-radius: 8px; }
.nav { display: flex; gap: 0.2rem; margin-left: auto; align-items: center; }
.nav a { padding: 0.4rem 0.85rem; border-radius: 99px; color: var(--muted); text-decoration: none; font-weight: 550; transition: background 0.15s, color 0.15s; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { background: var(--accent); color: var(--accent-text); }
.menu-toggle { display: none; margin-left: auto; }

.view { width: 100%; max-width: 1760px; margin: 0 auto; padding: 1.75rem clamp(16px, 2.5vw, 40px) 4rem; }

/* ---------- guide ---------- */
.guide { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: clamp(1.25rem, 2vw, 2.5rem); align-items: start; }
.guide-side {
  position: sticky;
  top: calc(var(--topbar-h) + 1rem);
  max-height: calc(100vh - var(--topbar-h) - 2rem);
  overflow: auto;
  display: grid;
  gap: 0.75rem;
  align-content: start;
}
.toc {
  display: grid;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
}
.toc a {
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.35;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}
.toc a:hover { background: var(--surface-2); }
.toc a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; border-left-color: var(--accent); }
.toc a.toc-sub { margin-left: 0.9rem; padding-left: 0.8rem; font-size: 0.87rem; color: var(--muted); border-left: 2px solid var(--border); border-radius: 0 8px 8px 0; }
.toc a.toc-sub:hover { color: var(--text); }
.toc a.toc-sub.active { color: var(--accent); border-left-color: var(--accent); }

.search-results { display: grid; gap: 0.35rem; padding: 0.6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.search-results[hidden] { display: none; }
.search-results p { margin: 0 0 0.2rem; font-size: 0.88rem; }
.result { display: grid; gap: 0.1rem; padding: 0.5rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 0.9rem; }
.result:hover { background: var(--surface-2); }
.result-count { color: var(--muted); font-size: 0.78rem; }

.guide-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: clamp(1.25rem, 2.5vw, 2.75rem) clamp(1.25rem, 3vw, 3.25rem) 2.5rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.guide-content > h1 { padding-bottom: 0.75rem; border-bottom: 3px solid var(--accent); display: inline-block; }
.guide-content h3 {
  margin-top: 2.25rem;
  padding: 0.35rem 0 0.35rem 0.8rem;
  border-left: 4px solid var(--gold);
  background: linear-gradient(90deg, var(--surface-2), transparent 70%);
  border-radius: 0 6px 6px 0;
}
.guide-content p, .guide-content li { max-width: 110ch; }
.guide-content ul, .guide-content ol { padding-left: 1.4rem; }
.guide-content li { margin: 0.25rem 0; }
.guide-content strong { color: color-mix(in srgb, var(--text) 92%, var(--accent)); }

.table-wrap {
  margin: 1rem 0 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}
.guide-content table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.guide-content th, .guide-content td { padding: 0.6rem 0.8rem; vertical-align: top; text-align: left; border-bottom: 1px solid var(--border); }
.guide-content th + th, .guide-content td + td { border-left: 1px solid var(--border); }
.guide-content th { background: var(--accent-soft); color: var(--text); font-weight: 650; font-size: 0.9rem; }
.guide-content tbody tr:nth-child(even) td { background: var(--surface-2); }
.guide-content tbody tr:last-child td { border-bottom: none; }
.guide-content tbody tr:hover td { background: var(--surface-3); }
.guide-content td:first-child { font-weight: 600; }

.guide-content blockquote {
  position: relative;
  margin: 1.1rem 0;
  padding: 0.85rem 5.5rem 0.85rem 1.2rem;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 12px 12px 0;
}
.guide-content blockquote p { margin: 0.25rem 0; max-width: none; }
.copy-btn { position: absolute; top: 0.6rem; right: 0.6rem; padding: 0.25rem 0.7rem; font-size: 0.8rem; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.roadmap { margin: 1.5rem 0; }
.roadmap-title { font-weight: 700; font-size: 1.05rem; }
.roadmap-phases { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; position: relative; }
.phase { border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem; background: var(--surface); box-shadow: var(--shadow); }
.phase strong { font-size: 1.05rem; }
.phase-accent { border: 2px solid var(--accent); background: var(--accent-soft); }
.phase-when { display: block; color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.phase ul { margin: 0.5rem 0 0; padding-left: 1.1rem; font-size: 0.93rem; }
.roadmap-foot { margin-top: 0.9rem; padding: 0.7rem; text-align: center; background: var(--surface-2); border-radius: 12px; font-weight: 550; }

/* ---------- records ---------- */
.records-head { display: flex; justify-content: space-between; gap: 1.5rem; align-items: flex-start; margin-bottom: 1.25rem; }
.records-head p { margin: 0; max-width: 90ch; }
.records-head button { flex-shrink: 0; }
.summary { display: flex; flex-wrap: wrap; gap: 0.85rem; margin-bottom: 1.25rem; }
.stat {
  flex: 1 1 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: grid;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.75rem; font-weight: 750; line-height: 1.15; }
.stat-label { color: var(--muted); font-size: 0.86rem; }
.stat-note { color: var(--danger); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.estimator, .acc-wrap { flex: 1 1 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); }
.estimator h3, .acc-wrap h3 { margin: 0 0 0.6rem; font-size: 1rem; }
.estimator-row { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: end; }
.estimator-row label { font-size: 0.9rem; color: var(--muted); }
.estimator-row input { width: 8rem; display: block; margin-top: 0.2rem; }
.estimator-row strong { font-size: 1.25rem; color: var(--accent); }
.estimator p { margin: 0.6rem 0 0; font-size: 0.85rem; }
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.5rem; }
.acc { display: flex; justify-content: space-between; align-items: center; padding: 0.45rem 0.75rem; border-radius: 8px; background: var(--surface-2); font-size: 0.92rem; }
.acc strong { font-size: 1.05rem; color: var(--ok); }
.acc-gap { outline: 1px dashed var(--danger); background: transparent; }
.acc-gap strong { color: var(--danger); }

.view > input[type="search"] { margin-bottom: 1rem; max-width: 520px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 0.85rem; }
.card {
  display: grid;
  gap: 0.3rem;
  align-content: start;
  text-align: left;
  font-weight: 400;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.card:hover { background: var(--surface); border-color: var(--accent); transform: translateY(-1px); }
.card-date { font-weight: 700; }
.card-field em { color: var(--muted); font-style: normal; font-size: 0.9rem; }
.badge { justify-self: start; font-size: 0.75rem; padding: 0.05rem 0.55rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge-warn { background: color-mix(in srgb, var(--gold) 22%, transparent); color: var(--text); font-weight: 600; }
.empty { grid-column: 1 / -1; padding: 3rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- dialogs and forms ---------- */
.dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem 1.75rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.dialog::backdrop { background: rgba(10, 15, 18, 0.55); backdrop-filter: blur(2px); }
.dialog h2 { margin-top: 0; }
.record-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 1rem; }
.record-form label { font-weight: 600; margin-top: 0.5rem; grid-column: 1 / -1; font-size: 0.92rem; }
.record-form input, .record-form select, .record-form textarea, .record-form .error, .record-form .actions { grid-column: 1 / -1; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.1rem; }
.detail { display: grid; grid-template-columns: 1fr; gap: 0.1rem; margin: 0; }
.detail dt { font-weight: 650; color: var(--muted); font-size: 0.82rem; margin-top: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
.detail dd { margin: 0; white-space: pre-wrap; }
.meta { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.5rem; }
.revision { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.75rem; }

/* ---------- export ---------- */
.export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.9rem; margin: 1rem 0 0.9rem; }
.export-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.export-card h2 { margin: 0; font-size: 1.05rem; }

.print-sheet { display: none; }

/* ---------- smaller screens ---------- */
@media (max-width: 1100px) {
  .guide { grid-template-columns: 270px minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .menu-toggle { display: inline-flex; margin-left: auto; }
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.5rem 16px; box-shadow: var(--shadow); }
  .nav.open { display: flex; }
  .nav a { border-radius: 8px; }
  .guide { grid-template-columns: 1fr; }
  .guide-side { position: static; max-height: none; }
  .toc { max-height: 45vh; overflow: auto; }
  .roadmap-phases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .records-head { flex-direction: column; }
  .record-form { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .roadmap-phases { grid-template-columns: 1fr; }
  h1 { font-size: 1.5rem; }
}

/* ---------- print ---------- */
@media print {
  body.printing > *:not(.print-sheet) { display: none !important; }
  body.printing .print-sheet { display: block; color: #000; }
  .print-entry { break-inside: avoid; border-top: 1px solid #999; padding-top: 0.5rem; margin-top: 0.5rem; }
  body:not(.printing) .topbar, body:not(.printing) .guide-side, body:not(.printing) .copy-btn { display: none; }
  body:not(.printing) .guide { display: block; }
  body:not(.printing) .guide-content { border: none; box-shadow: none; }
}
