:root {
  /* Brand palette — Vivid Tangelo #F37022 on Attractive Black #231F20 */
  --brand-orange: #F37022;
  --brand-orange-strong: #D85B14;
  --brand-orange-soft: #FCE4D2;
  --brand-black: #231F20;
  --brand-brown: #4F3826;

  --bg: #F5F3EF;
  --panel: #FFFFFF;
  --panel-2: #FAF6F0;
  --text: #231F20;
  --text-soft: #4A4544;
  --muted: #7A7370;
  --border: #E2DCD3;
  --header-bg: #231F20;
  --header-text: #FFFFFF;

  --ok: #2C7D3F;
  --ok-bg: #E8F3EA;
  --warn: #A0671A;
  --warn-bg: #FBEFD5;
  --error: #B53A2A;
  --error-bg: #FBE3DD;

  --radius: 6px;
  --gap: 16px;
  --control-h: 34px;
  --shadow-card: 0 1px 2px rgba(35,31,32,0.06), 0 4px 12px rgba(35,31,32,0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* App shell — fill the viewport so the footer is always pinned to the bottom
   and only the transcript/report panels scroll. */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.topbar { flex: 0 0 auto; }
.footer { flex: 0 0 auto; }

a { color: var(--brand-orange-strong); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-orange); }

.topbar {
  padding: 14px 0;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 4px solid var(--brand-orange);
}

.topbar-inner {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  /* Align with the panel header text: card border (1px) + panel-header padding (24px) */
  margin-left: 25px;
  font-weight: 700;
  color: var(--header-text);
  text-decoration: none;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--brand-orange); }

.topbar-actions { margin: 0; }

.link-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--header-text);
  cursor: pointer;
  font: inherit;
  padding: 6px 14px;
  border-radius: var(--radius);
}
.link-btn:hover { background: rgba(255,255,255,0.12); border-color: var(--brand-orange); color: var(--brand-orange); }

.container {
  width: 100%;
  max-width: 1680px;
  margin: 20px auto;
  padding: 0 24px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  margin-top: 0;
}

/* Login */
.login-card {
  max-width: 420px;
  margin: 80px auto;
  background: var(--panel);
  padding: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-top: 4px solid var(--brand-orange);
  box-shadow: var(--shadow-card);
}

.login-card h1 { margin: 0 0 12px; font-size: 22px; }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.login-card input[type=password] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font: inherit;
}
.login-card input[type=password]:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(243,112,34,0.15);
}

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

/* Config bar — horizontal control strip under the header */
.config-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 12px 18px;
  margin-bottom: 20px;
}

.config-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.kb-group { margin-left: auto; }
.inline-form { margin: 0; display: inline-flex; align-items: center; }

.config-divider {
  width: 1px;
  align-self: stretch;
  min-height: 28px;
  background: var(--border);
}

.config-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.config-field { display: flex; align-items: center; gap: 8px; }
.config-field label {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
.config-field #k-value { color: var(--brand-orange-strong); }

.config-model {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-soft);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
}

/* Compact controls */
.config-bar input[type=range] { width: 150px; }
.config-bar .status {
  height: var(--control-h);
  margin: 0;
  padding: 0 12px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
}

/* Upload controls hosted in the Transcript panel header — right-aligned, fixed width */
.header-controls {
  margin: 0 0 0 auto;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Generate button hosted in the Report panel header — right-aligned */
.report-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Custom file picker — grows to fill whitespace, shows long filenames */
.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;
}

.file-picker {
  flex: 0 0 auto;
  width: 280px;
  display: flex;
  align-items: stretch;
  height: var(--control-h);
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  cursor: pointer;
}
.file-picker:focus-within {
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(243, 112, 34, 0.15);
}
.file-btn {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 0 14px;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}
.file-picker:hover .file-btn { color: var(--brand-orange-strong); }
.file-name {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: calc(var(--control-h) - 2px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Layout — 50% transcript / 50% report */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  gap: 24px;
  align-items: stretch;
}

/* Panels — fill available height, locked header, scrolling body */
.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

@media (max-width: 1000px) {
  /* On narrow screens, fall back to normal page scrolling. */
  body { height: auto; overflow: auto; }
  .container { overflow: visible; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .panel { height: 70vh; }
}

.panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 12px 24px;
  border-bottom: 2px solid var(--brand-orange);
}

.panel-header h1 {
  flex: 0 0 auto;
  margin: 0;
  font-size: 20px;
  color: var(--text);
  border: none;
  padding: 0;
}

.panel-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 22px 28px;
}

/* Loaded transcript view */
.transcript-view {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.transcript-view.empty {
  color: var(--muted);
  font-style: italic;
  font-family: inherit;
}
/* Active evidence highlight injected when a report quote is clicked */
.transcript-view mark.cce-highlight {
  background: var(--brand-orange-soft);
  color: var(--text);
  box-shadow: 0 0 0 2px var(--brand-orange);
  border-radius: 3px;
  padding: 0 1px;
}

label { display: block; color: var(--muted); margin-bottom: 6px; font-size: 13px; }
.mt { margin-top: 18px; }

input[type=file],
input[type=range],
textarea {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
textarea { min-height: 240px; resize: vertical; }
textarea:focus, input[type=file]:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(243,112,34,0.15);
}
input[type=range] { padding: 0; accent-color: var(--brand-orange); }

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

.btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { border-color: var(--brand-orange); color: var(--brand-orange); }

/* Button size/shape modifiers — must follow .btn so they override its padding/display */
.btn-sm {
  height: var(--control-h);
  padding: 0 14px;
  font-size: 13px;
}

.btn-icon {
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
}
.btn-icon:hover { border-color: var(--error); color: var(--error); }

.btn-primary {
  background: var(--brand-orange);
  border-color: var(--brand-orange);
  color: #FFFFFF;
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--brand-orange-strong);
  border-color: var(--brand-orange-strong);
  color: #FFFFFF;
}

/* Disabled (greyed-out) state — still clickable so JS can warn the user */
.btn.is-disabled { cursor: not-allowed; }
.btn.is-disabled,
.btn.is-disabled:hover {
  color: var(--muted);
  border-color: var(--border);
}
.btn-primary.is-disabled,
.btn-primary.is-disabled:hover {
  background: var(--border);
  border-color: var(--border);
  color: var(--muted);
}

.status {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 4px;
  font-size: 14px;
}
.status-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.status-warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.status-error { background: var(--error-bg); border-color: var(--error); color: var(--error); }

/* HTMX loading indicators */
.htmx-indicator {
  opacity: 0;
  margin-left: 8px;
  color: var(--brand-orange-strong);
  font-style: italic;
  transition: opacity 0.2s ease-in-out;
}
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* Report generation spinner — orange circle centered over the report panel */
.report-panel .panel-body { position: relative; }
.report-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.6);
}
.report-spinner .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--brand-orange-soft);
  border-top-color: var(--brand-orange);
  border-radius: 50%;
  animation: cce-spin 0.8s linear infinite;
}
@keyframes cce-spin { to { transform: rotate(360deg); } }

/* Results */
#results { margin-top: 0; }

/* Report markdown styling */
.tab-report h1, .tab-report h2, .tab-report h3 { color: var(--text); }
.tab-report h1 { font-size: 22px; }
.tab-report h2 {
  font-size: 18px;
  border-bottom: 2px solid var(--brand-orange);
  padding-bottom: 6px;
  margin-top: 32px;
  display: inline-block;
}
.tab-report h3 { font-size: 15px; color: var(--brand-orange-strong); margin-top: 26px; }
.tab-report table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
}
.tab-report th, .tab-report td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}
.tab-report th {
  background: var(--brand-black);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tab-report tr:nth-child(even) td { background: var(--panel-2); }
.tab-report blockquote {
  border-left: 4px solid var(--brand-orange);
  margin: 18px 0;
  padding: 6px 14px;
  color: var(--text-soft);
  font-style: italic;
  background: var(--brand-orange-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.tab-report code {
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--brand-brown);
}
.tab-report pre code { background: transparent; padding: 0; color: var(--text); }
.tab-report pre {
  background: var(--panel-2);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: auto;
}
/* Clickable transcript-evidence quotes in the coaching report */
.tab-report .evidence-quote {
  color: var(--brand-orange-strong);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}
.tab-report .evidence-quote:hover,
.tab-report .evidence-quote:focus-visible {
  background: var(--brand-orange-soft);
  text-decoration-style: solid;
  border-radius: 3px;
}
.tab-report .evidence-quote.not-found {
  color: var(--muted);
  text-decoration: none;
  cursor: default;
}

/* Evidence outcome cards (one per scored category) */
.tab-report .cce-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  margin: 16px 0;
  padding: 0 18px 14px;
  background: var(--panel);
}
.tab-report .cce-yes { border-left-color: var(--ok); }
.tab-report .cce-no { border-left-color: var(--error); }
.tab-report .cce-na { border-left-color: var(--muted); }

.tab-report .cce-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.tab-report .cce-num {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand-black);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.tab-report .cce-name {
  flex: 1 1 auto;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.tab-report .cce-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.tab-report .cce-badge::before {
  content: "\25CF";
  font-size: 9px;
  line-height: 1;
}
.tab-report .cce-badge-yes { background: var(--ok-bg); color: var(--ok); }
.tab-report .cce-badge-no { background: var(--error-bg); color: var(--error); }
.tab-report .cce-badge-na { background: var(--panel-2); color: var(--muted); }

.tab-report .cce-section { margin-top: 12px; }
.tab-report .cce-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.tab-report .cce-evidence {
  border-left: 3px solid var(--brand-orange);
  background: var(--brand-orange-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 8px 14px;
}
.tab-report .cce-quote { margin: 4px 0; line-height: 1.5; }
.tab-report .cce-qlabel { font-weight: 600; color: var(--text-soft); }
.tab-report .cce-ts { color: var(--muted); font-size: 13px; }
.tab-report .cce-empty { color: var(--muted); font-style: italic; }
.tab-report .cce-text { color: var(--text); line-height: 1.5; }
.tab-report .cce-source { color: var(--text-soft); font-size: 14px; }
.tab-report .cce-note .cce-text {
  background: var(--brand-orange-soft);
  border-radius: var(--radius);
  padding: 8px 12px;
}

/* Report sections: header tiles, callouts, tracking pills, score banner */
.tab-report .rpt-tiles { margin: 14px 0; font-size: 0; }
.tab-report .rpt-tile {
  display: inline-block;
  vertical-align: top;
  width: calc(33.333% - 8px);
  margin: 0 12px 12px 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-card);
}
.tab-report .rpt-tile:nth-child(3n) { margin-right: 0; }
.tab-report .rpt-tile-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}
.tab-report .rpt-tile-value { font-size: 15px; color: var(--text); word-break: break-word; }

.tab-report .rpt-callout {
  margin: 14px 0;
  padding: 12px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.tab-report .rpt-info { background: var(--panel-2); border-left: 4px solid var(--brand-orange); }
.tab-report .rpt-alert { background: var(--error-bg); border-left: 4px solid var(--error); }
.tab-report .rpt-list { margin: 0; padding-left: 20px; }
.tab-report .rpt-list li { margin: 4px 0; line-height: 1.5; }
.tab-report .rpt-callout-row { margin: 6px 0; line-height: 1.5; }
.tab-report .rpt-flag-kind {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--error);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-right: 4px;
}

.tab-report .rpt-pills { margin: 14px 0; }
.tab-report .rpt-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px 0;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
}
.tab-report .rpt-pill-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.tab-report .rpt-pill-val { font-size: 14px; font-weight: 600; color: var(--text); }

.tab-report .rpt-score {
  margin: 14px 0;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-orange);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-card);
}
.tab-report .rpt-score-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.tab-report .rpt-score-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  margin: 2px 0 8px;
}
.tab-report .rpt-score-max { font-size: 16px; font-weight: 600; color: var(--muted); }
.tab-report .rpt-score-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.tab-report .rpt-score-fill { height: 100%; background: var(--brand-orange); border-radius: 999px; }

.tab-report .rpt-panel {
  margin: 12px 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.tab-report .rpt-text { color: var(--text); line-height: 1.55; }
.tab-report .rpt-text p { margin: 0 0 8px; }
.tab-report .rpt-text p:last-child { margin-bottom: 0; }
.tab-report .rpt-empty { color: var(--muted); font-style: italic; }
.tab-report .rpt-notes { margin: 12px 0; padding-left: 22px; }
.tab-report .rpt-notes li { margin: 7px 0; line-height: 1.5; }

/* Warning modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(35, 31, 32, 0.55);
}
.modal-overlay[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 4px solid var(--brand-orange);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 24px 28px;
}
.modal-title { margin: 0 0 8px; font-size: 18px; color: var(--text); }
.modal-text { margin: 0 0 20px; color: var(--text-soft); }
.modal-actions { display: flex; justify-content: flex-end; }
