/* ═══════════════════════════════════════
   DESIGN TOKENS (ITM brand-aligned)
   ═══════════════════════════════════════ */
:root {
  --bg: #2f2c2c;
  --bg-alt: #3a3737;
  --text-loud: rgba(255,255,255,0.95);
  --text-body: rgba(255,255,255,0.75);
  --text-soft: rgba(255,255,255,0.50);
  --text-dim: rgba(255,255,255,0.45);
  --ghost: rgba(255,255,255,0.05);
  --ghost-hover: rgba(255,255,255,0.10);
  --rule: rgba(255,255,255,0.10);
  --accent: #3e4d50;
  --accent-ghost: rgba(62,77,80,0.15);
  --green: #22C55E;
  --amber: #F59E0B;
  --red: #cf2e2e;
  --fab-bg: rgba(47,44,44,0.95);
  --sans: "Varela Round", system-ui, sans-serif;
  --serif: "Varela Round", system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f0;
    --bg-alt: #eaeae5;
    --text-loud: rgba(47,44,44,0.95);
    --text-body: rgba(47,44,44,0.75);
    --text-soft: rgba(47,44,44,0.50);
    --text-dim: rgba(47,44,44,0.50);
    --ghost: rgba(47,44,44,0.05);
    --ghost-hover: rgba(47,44,44,0.10);
    --rule: rgba(47,44,44,0.12);
    --fab-bg: rgba(245,245,240,0.95);
  }
}

*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { font-size:16px; -webkit-font-smoothing:antialiased; }
body {
  background: var(--bg); color: var(--text-body); font-family: var(--sans);
  font-weight: 300; line-height: 1.5; min-height: 100dvh;
  display: flex; transition: background 0.4s, color 0.4s;
}

/* ═══ SKIP LINK ═══ */
.skip-link {
  position: absolute; top: -100%; left: 16px; z-index: 999;
  background: var(--accent); color: #fff; padding: 8px 16px;
  border-radius: 0 0 6px 6px; font-size: 13px; font-weight: 600;
  text-decoration: none; transition: top 0.2s;
}
.skip-link:focus { top: 0; }

/* ═══ SCREEN READER ONLY ═══ */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ═══ LOGIN GATE ═══ */
.gate {
  position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--bg); z-index: 200;
}
.gate-card { text-align: center; }
.gate-logo-img {
  width: 52px; height: 52px; margin: 0 auto 12px; display: block;
}
.gate-title {
  font-family: var(--serif); font-size: 28px; font-weight: 500;
  color: var(--text-loud); margin-bottom: 4px;
}
.gate-sub {
  font-size: 10px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 32px;
}
.gate-card input {
  width: 240px; text-align: center; margin-bottom: 12px;
}
.gate-btn { width: 240px; }
.gate-error {
  font-size: 13px; color: var(--red); margin-top: 16px;
}

/* ═══ SPINE ═══ */
.spine {
  width: 200px; display: flex; flex-direction: column; align-items: stretch;
  padding: 24px 0 16px; border-right: 1px solid var(--rule); flex-shrink: 0;
  transition: width 0.25s ease;
  overflow: hidden;
}
.spine.collapsed { width: 56px; }

.spine-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; margin-bottom: 28px; min-height: 36px;
}
.spine-logo {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 4px;
}
.brand-name {
  font-size: 12px; font-weight: 400; color: var(--text-body);
  line-height: 1.2; white-space: nowrap;
  opacity: 1; transition: opacity 0.15s;
}
.brand-name small { font-size: 11px; color: var(--text-soft); }
.spine.collapsed .brand-name { opacity: 0; pointer-events: none; }

.tab {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; height: 40px; cursor: pointer;
  font-family: var(--sans); font-size: 13px;
  color: var(--text-dim); transition: color 0.2s, background 0.2s;
  border-left: 3px solid transparent; margin-bottom: 2px;
}
.tab:hover { color: var(--text-soft); background: var(--ghost); }
.tab.active { color: var(--accent); border-left-color: var(--accent); background: var(--ghost); }

.tab-short {
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em;
  flex-shrink: 0; width: 28px; text-align: center;
  display: none;
}
.tab-long {
  font-size: 13px; font-weight: 400; white-space: nowrap;
  transition: opacity 0.15s;
}
.spine.collapsed .tab-short { display: block; }
.spine.collapsed .tab-long { display: none; }
.spine.collapsed .tab { justify-content: center; padding: 0; }

.spine-fold {
  margin-top: auto; height: 40px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; font-size: 18px;
  color: var(--text-dim); transition: color 0.2s, transform 0.25s;
  border-top: 1px solid var(--rule);
}
.spine-fold:hover { color: var(--text-soft); }
.spine.collapsed .spine-fold { transform: rotate(180deg); }
/* ═══ STAGE ═══ */
.stage { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.rail {
  padding: 28px 48px 0; display: flex; justify-content: space-between;
  align-items: flex-end; min-height: 72px; flex-shrink: 0;
}
.view-title {
  font-family: var(--serif); font-size: 32px; font-weight: 500;
  color: var(--text-loud); letter-spacing: -0.01em; line-height: 1;
}
.view-sub {
  font-family: var(--sans); font-size: 9px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim);
  margin-left: 8px; vertical-align: super;
}

/* ═══ CONTENT ═══ */
.content { padding: 24px 48px 48px; max-width: 900px; }
.view { display: none; }
.view.active { display: block; }

/* ═══ CARDS ═══ */
.card {
  background: var(--ghost); border: 1px solid var(--rule);
  border-radius: 8px; padding: 24px; margin-bottom: 20px;
}
.micro-label {
  display: block; font-size: 9px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 6px; margin-top: 14px;
}
.micro-label:first-child { margin-top: 0; }

textarea, input[type="text"], input[type="url"], input[type="number"], select {
  width: 100%; background: var(--bg-alt); border: 1px solid var(--rule);
  border-radius: 6px; padding: 10px 14px; color: var(--text-loud);
  font-family: var(--sans); font-size: 14px; font-weight: 300;
  outline: none; transition: border-color 0.2s;
}
textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }
select { cursor: pointer; }

/* ═══ FOCUS VISIBLE ═══ */
.run-btn:focus-visible,
.tab:focus-visible,
.spine-fold:focus-visible,
.dim-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row { display: flex; gap: 16px; align-items: flex-end; margin-top: 16px; flex-wrap: wrap; }
.field { flex: 1; min-width: 140px; }

.run-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 10px 28px; font-family: var(--sans); font-size: 12px;
  font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer; transition: opacity 0.2s; white-space: nowrap;
  align-self: flex-end;
}
.run-btn:hover { opacity: 0.85; }
.run-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ═══ SCORE RING ═══ */
.score-ring {
  display: flex; flex-direction: column; align-items: center;
  padding: 20px 0 16px; border-bottom: 1px solid var(--rule); margin-bottom: 20px;
}
.score-value {
  font-family: var(--serif); font-size: 56px; font-weight: 700;
  color: var(--text-loud); line-height: 1;
}
.score-value.high { color: var(--green); }
.score-value.mid { color: var(--amber); }
.score-value.low { color: var(--red); }
.score-label {
  font-size: 9px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-dim); margin-top: 4px;
}

/* ═══ DIMENSIONS ═══ */
.dimensions { display: grid; gap: 12px; margin-bottom: 20px; }
.dim-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--ghost); border-radius: 6px;
}
.dim-name { font-size: 13px; color: var(--text-body); }
.dim-score {
  font-family: var(--serif); font-size: 18px; font-weight: 700;
  min-width: 32px; text-align: center;
}
.dim-score.s4 { color: var(--green); }
.dim-score.s3 { color: var(--green); }
.dim-score.s2 { color: var(--amber); }
.dim-score.s1 { color: var(--red); }
.dim-analysis {
  font-size: 12px; color: var(--text-soft); margin-top: 4px;
  padding-left: 14px; max-height: 0; overflow: hidden; opacity: 0;
  transition: max-height 0.2s ease, opacity 0.2s ease;
}
.dim-row.expanded .dim-analysis { max-height: 500px; opacity: 1; }
.dim-row { cursor: pointer; flex-wrap: wrap; }

/* ═══ COMPLIANCE FLAGS ═══ */
.compliance-flags { margin-bottom: 16px; }
.flag {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 6px; margin-bottom: 8px;
}
.flag.CRITICAL { background: rgba(207,46,46,0.10); border-left: 3px solid var(--red); }
.flag.HIGH { background: rgba(245,158,11,0.08); border-left: 3px solid var(--amber); }
.flag.MEDIUM { background: rgba(59,130,246,0.08); border-left: 3px solid #3B82F6; }
.flag.MEDIUM .flag-badge { background: #3B82F6; color: #fff; }
.flag.LOW { background: var(--ghost); border-left: 3px solid var(--text-dim); }
.flag.LOW .flag-badge { background: var(--text-dim); color: var(--text-body); }
.flag.PASSED { background: rgba(34,197,94,0.06); border-left: 3px solid var(--green); }
.flag-badge {
  font-size: 9px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 3px;
}
.flag.CRITICAL .flag-badge { background: var(--red); color: #fff; }
.flag.HIGH .flag-badge { background: var(--amber); color: #000; }
.flag-item { font-size: 13px; color: var(--text-body); flex: 1; }
.flag-detail { font-size: 12px; color: var(--text-soft); }

.summary {
  font-size: 14px; color: var(--text-body); padding: 14px;
  background: var(--ghost); border-radius: 6px; line-height: 1.6;
}

/* ═══ VARIATIONS ═══ */
.variation-card {
  background: var(--ghost); border: 1px solid var(--rule);
  border-radius: 8px; padding: 20px; margin-bottom: 16px;
}
.variation-text {
  font-family: var(--serif); font-size: 18px; font-weight: 400;
  color: var(--text-loud); line-height: 1.4; margin-bottom: 16px;
}
.hook-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hook-item {
  padding: 8px 12px; background: var(--bg-alt); border-radius: 4px;
}
.hook-name {
  font-size: 9px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim);
}
.hook-score { font-family: var(--serif); font-size: 20px; font-weight: 700; color: var(--text-loud); }
.hook-reasoning { font-size: 11px; color: var(--text-soft); margin-top: 2px; }
.composite-score {
  text-align: center; padding: 12px; margin-top: 12px;
  border-top: 1px solid var(--rule);
}
.composite-value { font-family: var(--serif); font-size: 28px; font-weight: 700; color: var(--accent); }
.composite-label { font-size: 9px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); }
.framework-mapping { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }
.framework-stage { font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
.framework-stage strong { color: var(--text-body); text-transform: capitalize; }

/* ═══ FATIGUE ═══ */
.fatigue-headline { text-align: center; padding: 20px 0; border-bottom: 1px solid var(--rule); margin-bottom: 20px; }
.days-value { font-family: var(--serif); font-size: 64px; font-weight: 700; line-height: 1; }
.days-label { display: block; font-size: 9px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); margin-top: 4px; }
.timeline { margin-bottom: 20px; }
.timeline-phase {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: 6px; margin-bottom: 6px;
}
.timeline-phase.peak { border-left: 3px solid var(--green); }
.timeline-phase.warning { border-left: 3px solid var(--amber); }
.timeline-phase.decay { border-left: 3px solid var(--red); }
.timeline-phase.cliff { border-left: 3px solid var(--text-dim); }
.phase-name { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-soft); min-width: 70px; }
.phase-days { font-size: 13px; color: var(--text-body); }
.fatigue-meta { display: flex; gap: 24px; margin-bottom: 16px; }
.meta-item { font-size: 13px; color: var(--text-soft); }
.meta-item strong { color: var(--text-body); }
.velocity { font-size: 14px; color: var(--text-body); padding: 14px; background: var(--ghost); border-radius: 6px; }

/* ═══ SPECS ═══ */
.char-counter-wrap { position: relative; }
.char-count {
  position: absolute; right: 12px; bottom: 12px;
  font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums;
}
.char-count.warn { color: var(--amber); }
.char-count.over { color: var(--red); }
.specs-status {
  text-align: center; padding: 16px; margin-bottom: 16px;
  font-family: var(--serif); font-size: 24px; font-weight: 700;
}
.specs-status.pass { color: var(--green); }
.specs-status.fail { color: var(--red); }
.violation {
  padding: 12px 14px; background: var(--ghost); border-radius: 6px;
  margin-bottom: 8px; border-left: 3px solid var(--red);
}
.violation-field { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); }
.violation-issue { font-size: 14px; color: var(--text-body); margin-top: 4px; }
.violation-rec { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

/* ═══ LOADER ═══ */
.loader {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 100; overflow: hidden;
}
.loader-dot {
  width: 30%; height: 100; background: var(--accent);
  animation: loader-slide 1.2s ease-in-out infinite;
}
@keyframes loader-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* ═══ ERROR BANNER ═══ */
.error-banner {
  font-size: 13px; color: var(--red); padding: 10px 14px;
  background: rgba(207,46,46,0.10); border-left: 3px solid var(--red);
  border-radius: 4px; margin-top: 12px;
}

/* ═══ DIM CHEVRON ═══ */
.dim-chevron {
  font-size: 12px; color: var(--text-dim); margin-right: 8px;
  transition: transform 0.2s; display: inline-block;
}
.dim-row.expanded .dim-chevron { transform: rotate(90deg); }

/* ═══ FATIGUE COLOR CODING ═══ */
.days-value { color: var(--accent); }
.days-value.good { color: var(--green); }
.days-value.warn { color: var(--amber); }
.days-value.bad { color: var(--red); }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .spine { width: 56px; }
  .spine .tab-long,
  .spine .brand-name { opacity: 0; pointer-events: none; display: none; }
  .spine .tab-short { display: block; }
  .spine .tab { justify-content: center; padding: 0; }
  .content { padding: 16px 20px 40px; }
  .rail { padding: 20px 20px 0; }
  .view-title { font-size: 24px; }
  .hook-grid { grid-template-columns: repeat(2, 1fr); }
  .row { flex-direction: column; }
}
