:root {
  --ink: #1f2528;
  --muted: #5c6569;
  --line: #d0d5d8;
  --paper: #ffffff;
  --canvas: #e4e4e1;
  --teal: #1f6f68;
  --teal-deep: #12564f;
  --teal-soft: #edf6f4;
  --amber: #b47a2a;
  --wine: #73333d;
  --mono: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: calc(16px * var(--font-scale, 1)); }
body { background: var(--canvas); color: var(--ink); }
a { color: inherit; text-decoration: none; }
button, select, input { font: inherit; }
button, select { cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 18px;
  background: rgba(228, 228, 225, 0.95); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(31, 37, 40, 0.14);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hamburger { display: none; width: 34px; height: 34px; border: 1px solid rgba(31,37,40,.18); border-radius: 5px; background: transparent; }
.doc-title { font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-size-btn, .print-btn { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--muted); font-weight: 700; }
.print-btn svg { width: 15px; height: 15px; }
.font-size-btn:hover, .print-btn:hover { background: rgba(31,111,104,.06); color: var(--teal); }

.doc-layout { display: flex; align-items: flex-start; max-width: 1440px; margin: 0 auto; padding: 36px 20px 80px; gap: 32px; }
.toc { flex: 0 0 190px; position: sticky; top: 60px; align-self: flex-start; max-height: calc(100vh - 80px); overflow-y: auto; }
.toc-label { font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 0 10px 3px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.toc-link { display: flex; flex-direction: column; gap: 1px; padding: 7px 8px 7px 10px; border-left: 2px solid transparent; border-radius: 0 4px 4px 0; transition: border-color 140ms, background 140ms; }
.toc-link:hover, .toc-link.active { background: rgba(31,111,104,.07); border-left-color: var(--teal); }
.toc-num { font-size: .65rem; font-weight: 700; color: var(--teal); text-transform: uppercase; }
.toc-name { font-size: .78rem; color: var(--ink); line-height: 1.3; }
.toc-overlay { display: none; position: fixed; inset: 0; z-index: 25; background: rgba(31,37,40,.32); }

.doc-main { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.doc-page { background: var(--paper); box-shadow: 0 1px 3px rgba(31,37,40,.07), 0 4px 20px rgba(31,37,40,.09); border-radius: 2px; padding: 56px 68px; }
.cover-page { min-height: 440px; display: flex; flex-direction: column; justify-content: space-between; }
.cover-tag, .section-kicker, .mini-kicker { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--teal); margin-bottom: 18px; }
.cover-title, .section-title { font-family: Georgia, "Times New Roman", serif; color: var(--ink); line-height: 1.1; }
.cover-title { font-size: clamp(1.9rem, 4vw, 3rem); max-width: 720px; margin-bottom: 20px; }
.cover-subtitle { font-size: 1.05rem; line-height: 1.75; color: #3d4548; max-width: 720px; }
.cover-footer { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.cover-meta-row { display: flex; gap: 12px; font-size: .83rem; }
.cover-meta-row span { color: var(--muted); width: 90px; flex-shrink: 0; }
.section-kicker { margin-bottom: 10px; }
.section-title { font-size: clamp(1.4rem, 3vw, 1.9rem); margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.section-body p { font-size: 1rem; line-height: 1.82; color: #3a4245; margin-bottom: 16px; }
.section-body p:last-child { margin-bottom: 0; }
.section-body strong { color: var(--ink); }
.section-body a { color: var(--teal); text-decoration: underline; text-decoration-color: rgba(31,111,104,.35); text-underline-offset: 2px; }

.note-card { margin-top: 22px; padding: 16px 18px; border-left: 4px solid var(--teal); background: var(--teal-soft); color: #314043; line-height: 1.65; }
.interactive-card { margin-top: 28px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fbfcfb; }
.interactive-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); background: linear-gradient(135deg, var(--teal-soft), #fff); }
.interactive-head h3 { font-family: Georgia, "Times New Roman", serif; font-size: 1.25rem; font-weight: 700; }
.mini-kicker { margin-bottom: 5px; font-size: .64rem; }
.sample-select { max-width: 330px; border: 1px solid var(--line); border-radius: 5px; background: white; padding: 8px 10px; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 20px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: .76rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.form-grid input, .form-grid select { border: 1px solid var(--line); border-radius: 5px; padding: 9px 10px; background: white; color: var(--ink); font-size: .92rem; font-weight: 500; text-transform: none; letter-spacing: 0; }
.code-block { margin: 0 20px 20px; padding: 16px; border: 1px solid rgba(31,111,104,.18); border-radius: 6px; overflow-x: auto; background: #f7faf9; color: var(--ink); font: .82rem/1.65 var(--mono); white-space: pre-wrap; }
.llm-token { color: #11833f; font-weight: 800; }
.output-panel { margin: 0 20px 22px; padding: 16px 18px; border: 1px solid rgba(31,111,104,.25); border-radius: 6px; background: white; }
.output-label { font-size: .68rem; font-weight: 800; color: var(--teal); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.output-panel p { line-height: 1.75; color: #30393c; }

.file-grid, .metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 24px; }
.file-card, .metric { display: flex; flex-direction: column; gap: 7px; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcfb; min-height: 112px; }
.file-card:hover { border-color: rgba(31,111,104,.55); background: var(--teal-soft); }
.file-card span, .metric span { font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--teal); }
.file-card strong, .metric strong { font-size: 1rem; line-height: 1.3; color: var(--ink); }
.file-card em { margin-top: auto; color: var(--muted); font-size: .82rem; font-style: normal; }
.metric { min-height: 92px; background: var(--teal-soft); }
.metric strong { font-size: 1.3rem; }

/* ============================================================
   PASSWORD GATE
   ============================================================ */
body.auth-locked { overflow: hidden; }
body.auth-locked .report-shell { display: none; }
.gate-overlay[hidden] { display: none !important; }
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(31, 111, 104, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(115, 51, 61, 0.10) 0%, transparent 60%),
    linear-gradient(135deg, #e8e8e5 0%, #d4d5d2 50%, #c8ccc9 100%);
  animation: gateFadeIn 0.5s ease-out;
}

@keyframes gateFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.gate-card {
  width: 380px;
  max-width: 90vw;
  padding: 44px 36px 40px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(28px) saturate(1.6);
  -webkit-backdrop-filter: blur(28px) saturate(1.6);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 20px;
  box-shadow:
    0 8px 32px rgba(31, 37, 40, 0.12),
    0 1px 2px rgba(31, 37, 40, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  text-align: center;
  animation: gateCardSlide 0.5s ease-out;
}

@keyframes gateCardSlide {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.gate-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-deep) 100%);
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(31, 111, 104, 0.3);
}

.gate-icon svg {
  width: 28px;
  height: 28px;
  stroke: #fff;
}

.gate-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.4rem;
  color: var(--ink);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.gate-subtitle {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 28px;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate-input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 180ms, box-shadow 180ms;
  text-align: center;
  letter-spacing: 0.12em;
}

.gate-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 111, 104, 0.12);
}

.gate-input-error {
  border-color: #c0392b;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.10);
  animation: gateShake 0.4s ease;
}

@keyframes gateShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.gate-error-msg {
  font-size: 0.8rem;
  color: #c0392b;
  font-weight: 600;
  margin: -4px 0 0;
}

.gate-submit {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-deep) 100%);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 140ms, box-shadow 140ms;
  box-shadow: 0 2px 8px rgba(31, 111, 104, 0.25);
}

.gate-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(31, 111, 104, 0.35);
}

.gate-submit:active { transform: translateY(0); }

@media (max-width: 900px) {
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .doc-layout { padding: 22px 12px 60px; display: block; }
  .toc { position: fixed; top: 44px; left: 0; bottom: 0; width: min(280px, 85vw); z-index: 40; background: var(--paper); padding: 18px; transform: translateX(-105%); transition: transform 180ms ease; box-shadow: 8px 0 24px rgba(31,37,40,.18); }
  .toc.open { transform: translateX(0); }
  .toc-overlay.open { display: block; }
  .doc-page { padding: 34px 24px; }
  .form-grid, .file-grid, .metric-grid { grid-template-columns: 1fr; }
  .interactive-head { align-items: stretch; flex-direction: column; }
  .sample-select { max-width: none; }
}

@media print {
  body { background: white; }
  .topbar, .toc, .toc-overlay, .gate-overlay { display: none !important; }
  .doc-layout { display: block; padding: 0; max-width: none; }
  .doc-main { gap: 0; }
  .doc-page { box-shadow: none; border-radius: 0; page-break-after: always; }
}
