/* =========================================================================
   FinStab Annotator — design tokens
   ========================================================================= */
:root {
  /* color */
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --ink: #1C1917;
  --ink-secondary: #57534E;
  --muted: #A8A29E;
  --accent: #3E63DD;
  --accent-hover: #3151C4;
  --accent-soft: #EEF1FD;
  --accent-soft-border: #C7D2FE;

  /* status colors — used ONLY for status badges, always paired with a text label */
  --status-open-bg: #F1F5F9;   --status-open-text: #475569;   --status-open-border: #E2E8F0;
  --status-progress-bg: #FEF3C7; --status-progress-text: #B45309; --status-progress-border: #FDE68A;
  --status-done-bg: #DCFCE7;   --status-done-text: #15803D;   --status-done-border: #BBF7D0;
  --status-skipped-bg: #FEE2E2; --status-skipped-text: #B91C1C; --status-skipped-border: #FECACA;

  /* semantic label colors (surprise buttons — distinct from status badges) */
  --surprise-tight: #B91C1C;
  --surprise-expected: #57534E;
  --surprise-loose: #15803D;
  --surprise-none: #6B7280;

  /* single chart accent (binding per spec) */
  --chart-accent: #3E63DD;
  --chart-grid: #E5E7EB;
  --chart-axis-text: #6B7280;
  --chart-value-ink: #374151;

  /* spacing (8px scale) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* radius */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  /* shadow */
  --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.07), 0 1px 2px rgba(28, 25, 23, 0.04);

  /* type */
  --font-ui: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-mono: "Consolas", "Courier New", monospace;
  --fs-2xs: 11px; --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px;
  --fs-md: 15px; --fs-lg: 17px; --fs-xl: 20px; --fs-2xl: 26px;

  --transition: 120ms ease;

  font-family: var(--font-ui);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#root { min-height: 100vh; }

button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0 0 var(--sp-3) 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-md); color: var(--ink-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-top: var(--sp-8); }
p { margin: 0 0 var(--sp-3) 0; }

a { color: var(--accent); }

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* =========================================================================
   Layout primitives
   ========================================================================= */
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-8);
  box-shadow: var(--shadow-sm);
  min-width: 340px;
}

.brand-mark {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}

.login-card input {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-12);
}

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
  transition: border-color var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn:hover { border-color: var(--border-strong); background: #FAFAF9; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-hover); }

.btn-link {
  border: none;
  background: none;
  color: var(--accent);
  padding: var(--sp-1) var(--sp-2);
  font-weight: 500;
}
.btn-link:hover { text-decoration: underline; }

.btn-big { padding: var(--sp-3) var(--sp-5); font-size: var(--fs-md); }
.btn-block { width: 100%; margin-top: var(--sp-2); }

.coder-grid { display: flex; gap: var(--sp-4); margin: var(--sp-5) 0 var(--sp-3) 0; }
.btn-coder { padding: var(--sp-5) var(--sp-8); font-size: var(--fs-lg); font-weight: 600; }
.btn-coder:hover { border-color: var(--accent); color: var(--accent); }

.inline-form { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }
.inline-form input {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.error-text { color: var(--surprise-tight); margin: var(--sp-2) 0; font-size: var(--fs-sm); }
.muted { color: var(--muted); font-size: 0.92em; }

.notice {
  background: #F0FDF4;
  border: 1px solid var(--status-done-border);
  color: var(--status-done-text);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) 0;
  font-size: var(--fs-sm);
}

/* =========================================================================
   App shell / header / tabs
   ========================================================================= */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: var(--sp-4);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: var(--fs-lg); color: var(--ink); letter-spacing: -0.01em; }
.coder-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-4);
}
.coder-chip-name { font-weight: 600; }

.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-5);
}
.tab {
  border: none;
  background: none;
  padding: var(--sp-3) var(--sp-4);
  color: var(--muted);
  font-weight: 500;
  font-size: var(--fs-sm);
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--ink-secondary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-content { padding-top: var(--sp-2); }

/* =========================================================================
   Stat cards (Übersicht) / stat tiles (Agreement)
   ========================================================================= */
.stat-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-xs);
}
.stat-card-name { font-size: var(--fs-sm); color: var(--ink-secondary); font-weight: 600; margin-bottom: var(--sp-1); }
.stat-card-value { font-size: var(--fs-2xl); font-weight: 700; margin-bottom: var(--sp-3); letter-spacing: -0.02em; }
.stat-card-unit { font-size: var(--fs-sm); font-weight: 400; color: var(--muted); }
.stat-card-footnote { margin-top: var(--sp-2); }

.stat-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  text-align: center;
}
.stat-tile-value { font-size: var(--fs-xl); font-weight: 700; color: var(--accent); }
.stat-tile-label { font-size: var(--fs-2xs); color: var(--muted); margin-top: var(--sp-1); text-transform: uppercase; letter-spacing: 0.04em; }

/* =========================================================================
   Progress bars
   ========================================================================= */
.progress-bar-track {
  background: #EFEDEA;
  border-radius: var(--radius-full);
  height: 8px;
  overflow: hidden;
}
.progress-bar-track.progress-bar-slim { height: 5px; }
.progress-bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 200ms ease;
}

/* =========================================================================
   Table
   ========================================================================= */
.speech-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.speech-table th, .speech-table td {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.speech-table thead th {
  background: #FBFAF9;
  color: var(--ink-secondary);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.speech-table tbody tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; transition: background var(--transition); }
.clickable-row:hover { background: #F6F5F3; }

.badge {
  display: inline-block;
  padding: 3px var(--sp-3);
  border-radius: var(--radius-full);
  font-size: var(--fs-2xs);
  font-weight: 600;
  border: 1px solid transparent;
}
.badge-open { background: var(--status-open-bg); color: var(--status-open-text); border-color: var(--status-open-border); }
.badge-in_progress { background: var(--status-progress-bg); color: var(--status-progress-text); border-color: var(--status-progress-border); }
.badge-done { background: var(--status-done-bg); color: var(--status-done-text); border-color: var(--status-done-border); }
.badge-skipped { background: var(--status-skipped-bg); color: var(--status-skipped-text); border-color: var(--status-skipped-border); }

.kv-list { list-style: none; padding: 0; }
.kv-list li { padding: var(--sp-1) 0; font-size: var(--fs-sm); }

.confusion-table {
  border-collapse: collapse;
  margin: var(--sp-2) 0 var(--sp-6) 0;
}
.confusion-table th, .confusion-table td {
  border: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-3);
  text-align: center;
  font-size: var(--fs-xs);
}
.confusion-table thead th { background: #FBFAF9; color: var(--ink-secondary); }
.confusion-table td.cell-zero { color: var(--muted); }

/* =========================================================================
   Markdown / Anleitung tab
   ========================================================================= */
.prose { max-width: 76ch; }
.prose h1 { font-size: var(--fs-xl); margin-top: var(--sp-6); }
.prose h2 { font-size: var(--fs-lg); margin-top: var(--sp-6); text-transform: none; letter-spacing: normal; color: var(--ink); font-weight: 650; }
.prose h3 { font-size: var(--fs-md); margin-top: var(--sp-5); text-transform: none; letter-spacing: normal; color: var(--ink); font-weight: 650; }
.prose p { line-height: 1.65; color: var(--ink-secondary); }
.prose ul { padding-left: var(--sp-5); color: var(--ink-secondary); }
.prose li { margin-bottom: var(--sp-1); }
.prose code {
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.prose pre {
  background: #1C1917;
  color: #F4F4F3;
  padding: var(--sp-4);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}
.prose pre code { background: none; color: inherit; padding: 0; }
.prose table { border-collapse: collapse; margin: var(--sp-3) 0 var(--sp-5) 0; width: 100%; }
.prose th, .prose td { border: 1px solid var(--border); padding: var(--sp-2) var(--sp-3); text-align: left; font-size: var(--fs-sm); }
.prose thead th { background: #FBFAF9; }

/* =========================================================================
   Labeling view — two-column layout
   ========================================================================= */
.labeling-page { max-width: 1280px; }

.labeling-header {
  padding-bottom: var(--sp-4);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.labeling-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-2);
}
.labeling-title { font-size: var(--fs-md); }
.labeling-header-actions { display: flex; gap: var(--sp-1); }

.labeling-progress-row { display: flex; flex-direction: column; gap: var(--sp-1); max-width: 480px; }
.labeling-progress-text { font-size: var(--fs-xs); color: var(--ink-secondary); }

.labeling-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--sp-6);
  align-items: start;
}
.reading-column { min-width: 0; }
.sidebar-column {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  position: sticky;
  top: var(--sp-6);
}

@media (max-width: 980px) {
  .labeling-grid { grid-template-columns: 1fr; }
  .sidebar-column { position: static; }
}

/* paragraphs */
.paragraph-focus, .paragraph-scroll { margin-bottom: var(--sp-5); }

.paragraph-block {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  margin: var(--sp-2) 0;
  transition: background var(--transition);
}
.paragraph-block.dimmed {
  color: var(--muted);
  background: #F3F2EF;
  cursor: pointer;
  font-size: var(--fs-sm);
}
.paragraph-block.dimmed:hover { background: #ECEAE5; color: var(--ink-secondary); }
.paragraph-block.current {
  background: var(--accent-soft);
  color: var(--ink);
  cursor: default;
  font-family: var(--font-serif);
}

.reading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.7;
  max-width: 72ch;
  padding: var(--sp-6) var(--sp-8);
  color: var(--ink);
}
.check { color: var(--status-done-text); font-weight: 700; margin-right: var(--sp-1); }

/* side panels: metadata / context / market data */
.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.side-panel-toggle {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: var(--sp-3) var(--sp-4);
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--ink);
}
.side-panel-toggle:hover { background: #FBFAF9; }
.side-panel-body { padding: 0 var(--sp-4) var(--sp-4) var(--sp-4); }

.metadata-card { padding: var(--sp-4); }
.metadata-row { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-1) 0; font-size: var(--fs-sm); }
.metadata-label { color: var(--muted); }
.metadata-value { color: var(--ink); font-weight: 500; text-align: right; }

.context-text {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 50vh;
  overflow-y: auto;
  color: var(--ink-secondary);
  margin: 0;
}

.market-caption { font-size: var(--fs-2xs); color: var(--muted); margin-top: var(--sp-2); margin-bottom: 0; }

/* =========================================================================
   Label form
   ========================================================================= */
.label-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
  position: sticky;
  bottom: var(--sp-4);
}
.summary-form { position: static; }

.form-group { margin-bottom: var(--sp-4); }
.form-label {
  font-weight: 600;
  font-size: var(--fs-2xs);
  margin-bottom: var(--sp-2);
  color: var(--ink-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.segmented { display: flex; gap: var(--sp-1); flex-wrap: wrap; }
.seg-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-full);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.seg-btn:hover:not(:disabled):not(.active) { border-color: var(--border-strong); }
.seg-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.seg-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.kbd-hints { display: flex; gap: var(--sp-1); margin-top: var(--sp-2); }
.kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  background: #F3F2EF;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--ink-secondary);
  line-height: 1.5;
}

.surprise-buttons { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.surprise-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.surprise-btn.surprise-tight { border-color: #F3C9C9; color: var(--surprise-tight); }
.surprise-btn.surprise-expected { border-color: var(--border-strong); color: var(--surprise-expected); }
.surprise-btn.surprise-loose { border-color: #BEE6CB; color: var(--surprise-loose); }
.surprise-btn.surprise-none { border-color: var(--border-strong); color: var(--surprise-none); }
.surprise-btn.active.surprise-tight { background: var(--surprise-tight); border-color: var(--surprise-tight); color: #fff; }
.surprise-btn.active.surprise-expected { background: var(--surprise-expected); border-color: var(--surprise-expected); color: #fff; }
.surprise-btn.active.surprise-loose { background: var(--surprise-loose); border-color: var(--surprise-loose); color: #fff; }
.surprise-btn.active.surprise-none { background: var(--surprise-none); border-color: var(--surprise-none); color: #fff; }

.confidence-dots { display: flex; gap: var(--sp-2); }
.dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--fs-xs);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.dot.filled { background: var(--accent); border-color: var(--accent); color: #fff; }

.label-form input[type="text"] {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.label-form input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.label-form input[type="range"] { width: 100%; accent-color: var(--accent); }

.summary-form h3 { margin-top: 0; }

.shortcut-footer {
  margin-top: var(--sp-6);
  font-size: var(--fs-2xs);
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* =========================================================================
   Market data charts (inline SVG small multiples)
   ========================================================================= */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
}
.chart-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-2) var(--sp-1) var(--sp-2);
  background: #FDFDFC;
}
.chart-panel-empty { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 80px; }
.chart-title { font-size: var(--fs-2xs); font-weight: 600; color: var(--ink-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.chart-empty-note { font-size: var(--fs-xs); color: var(--muted); font-style: italic; padding: var(--sp-3) 0; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-line { stroke: var(--chart-accent); stroke-width: 2; }
.chart-grid-line, .chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-axis-text { fill: var(--chart-axis-text); font-size: 11px; font-family: var(--font-ui); }
.chart-last-value { fill: var(--chart-value-ink); font-size: 11px; font-weight: 700; font-family: var(--font-ui); }
.chart-last-dot { fill: var(--chart-accent); }
.chart-crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 2 2; }
.chart-hover-dot { fill: var(--chart-accent); stroke: #fff; stroke-width: 1.5; }
.chart-tooltip-bg { fill: var(--ink); opacity: 0.92; }
.chart-tooltip-text { fill: #fff; font-size: 9px; font-family: var(--font-ui); }
.chart-tooltip-value { fill: #fff; font-size: 10px; font-weight: 700; font-family: var(--font-ui); }

@media (min-width: 700px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
}
