/* ================================================================
   Deck Analysis v3 - Conversation Card UI
   Light theme, system sans-serif, blue accent, TOC sidebar.
   ================================================================ */

/* ── 1. Design Tokens ─────────────────────────────────────────── */

:root {
  --bg-page: #f8f9fa;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-toc: #ffffff;

  --border: #e2e8f0;
  --border-focus: #2563eb;

  --text-primary: #1a202c;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;

  --success: #16a34a;
  --success-light: #f0fdf4;
  --error: #dc2626;
  --error-light: #fef2f2;

  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;

  --transition: 0.2s ease;
  --toc-width: 200px;
}


/* ── 2. Reset & Base ──────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}


/* ── 3. Page Layout ───────────────────────────────────────────── */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-link {
  font-size: 13px;
  color: var(--accent);
  /* Standard blue underlined link (dls, 2026-09-19). Links are underlined
     at rest, not only on hover, so a reader can tell what is clickable
     without probing the page with the mouse. Hover shifts the colour
     instead, matching .btn-link:hover. */
  text-decoration: underline;
  font-weight: 500;
}

.header-link:hover {
  color: var(--accent-hover);
}

#model-badge {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-page);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Build number stamped in at deploy time (see build-badge.js).
   Deliberately quiet: monospace and muted so it reads as build
   metadata rather than as another nav link, but at header-link size
   so it stays legible enough to compare against the number the deploy
   script printed. */
#build-badge {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}


/* ── 4. Login Screen ──────────────────────────────────────────── */

#login-screen {
  max-width: 380px;
  margin: 80px auto 0;
  text-align: center;
}

#login-screen h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 6px;
}

.cost-hint {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
  margin-bottom: 28px;
}

#login-screen input {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 12px;
}

#login-screen input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

#login-screen input::placeholder {
  color: var(--text-muted);
}

#login-error {
  margin-top: 12px;
  font-size: 13px;
  color: var(--error);
  background: var(--error-light);
  padding: 8px 12px;
  border-radius: var(--radius);
}


/* ── 5. Workspace (TOC + Conversation) ────────────────────────── */

#workspace {
  display: flex;
  gap: 0;
  align-items: flex-start;
}

/* ── 6. Table of Contents (left sidebar) ──────────────────────── */

#toc {
  width: var(--toc-width);
  min-width: 140px;
  max-width: 320px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  flex-shrink: 0;
  background: var(--bg-toc);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 0;
}

.toc-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 14px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  /* Flex so the "<<" collapse button sits right-justified next to
     the "Steps" label. */
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Shared style for the "<<" (in sidebar) and ">>" (in top bar)
   toggle buttons. Designed to read as a blue text link, not a chunky
   button — matches the "discrete control" feel the user asked for. */
.toc-toggle-btn {
  background: transparent;
  border: none;
  padding: 0 2px;
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  font-family: inherit;
}
.toc-toggle-btn:hover {
  text-decoration: underline;
}

/* Collapsed-state top bar. Sticky to viewport so it stays in view
   as the user scrolls through the conversation. z-index lifts it
   above conversation cards. Display toggled via body.toc-collapsed. */
#toc-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-toc);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  margin-bottom: 12px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.toc-bar-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-size: 11px;
  flex-shrink: 0;
}

#toc-bar-list {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}
#toc-bar-list::-webkit-scrollbar { height: 3px; }
#toc-bar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Pills are read-only indicators — no cursor change, no hover state.
   To navigate, the user expands the sidebar via the ">>" button. */
.toc-bar-item {
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.4;
  user-select: none;
}
.toc-bar-item.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}
.toc-bar-item.complete {
  color: var(--success);
}

/* When the body has the collapsed class: hide the sidebar entirely
   and reveal the sticky top bar. */
body.toc-collapsed #toc,
body.toc-collapsed #splitter {
  display: none !important;
}
body.toc-collapsed #toc-bar {
  display: flex !important;
}

#toc ul {
  list-style: none;
}

#toc li {
  padding: 6px 14px 6px 18px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

#toc li:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Active section: the whole group (heading + subs) gets the background */
#toc li.active-section {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  color: var(--text-primary);
}

/* The one item with the dot: bold blue, stands out within the section */
#toc li.active-dot {
  color: var(--accent) !important;
  font-weight: 700;
  background: #dbeafe;
  position: relative;
}

/* Blue dot to the left of the active item */
#toc li.active-dot::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

#toc li.toc-sub.active-dot::before {
  left: 16px;
}

#toc li.complete {
  color: var(--success);
}

#toc li.complete::after {
  content: ' \2713';
  font-size: 11px;
}

/* Sub-items are indented under their parent section */
#toc li.toc-sub {
  padding-left: 28px;
  font-size: 12px;
  color: var(--text-muted);
}

#toc li.toc-sub.active {
  color: var(--accent);
}

#toc::-webkit-scrollbar {
  width: 4px;
}
#toc::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}


/* ── 7. Splitter (resizable divider) ──────────────────────────── */

#splitter {
  width: 12px;
  min-width: 12px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

#splitter::after {
  content: '';
  width: 3px;
  background: var(--border);
  border-radius: 2px;
  transition: background var(--transition);
}

#splitter:hover::after,
#splitter.dragging::after {
  background: var(--accent);
}

/* Prevent text selection while dragging the splitter */
body.resizing {
  user-select: none;
  cursor: col-resize;
}


/* ── 8. Conversation Area ─────────────────────────────────────── */

#conversation {
  flex: 1;
  min-width: 0;
  padding-left: 16px;
}


/* ── 9. Card System (shared) ──────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 0;
  animation: fadeIn 0.3s ease;
}

.card-header {
  padding: 12px 20px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

/* Cost chip rendered in the response card header.
   Lowercase, monospace, smaller, less heavy than the title. */
.card-cost {
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}
.card-cost:empty { display: none; }

.card-body {
  padding: 10px 20px 16px;
}

.card-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}


/* ── 10. Upload Card ──────────────────────────────────────────── */

.card-upload .upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.card-upload .upload-area:hover,
.card-upload .upload-area.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.card-upload .upload-area p {
  color: var(--text-secondary);
  font-size: 14px;
}

.card-upload .file-name {
  margin-top: 8px;
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
}

.card-upload .model-selector {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 14px;
}

.card-upload .model-selector label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition);
}

.card-upload .model-selector label:hover {
  border-color: var(--accent);
}

.card-upload .model-selector input[type="radio"] {
  accent-color: var(--accent);
}

.card-upload .model-selector input:checked + span {
  font-weight: 600;
  color: var(--text-primary);
}

.card-upload.locked .upload-area {
  pointer-events: none;
  opacity: 0.5;
}

.card-upload.locked .model-selector {
  pointer-events: none;
  opacity: 0.5;
}


/* ── 11. Prompt Card ──────────────────────────────────────────── */

.card-prompt {
  border-left: 3px solid transparent;
  position: relative;
}

/* Blue accent only when actively editing */
.card-prompt.editing {
  border-left-color: var(--accent);
}

.card-prompt .step-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.card-prompt textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  resize: none;
  overflow: hidden;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

.card-prompt textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Readonly state: dimmed, no focus ring */
.card-prompt.readonly textarea {
  background: var(--bg-page);
  color: var(--text-secondary);
  border-color: transparent;
  cursor: default;
}

.card-prompt .card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

/* Pen (edit) button in the top-right corner of readonly prompt cards */
.card-prompt .edit-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  line-height: 1;
}

.card-prompt .edit-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}


/* ── 12. Response Card ────────────────────────────────────────── */

.card-response .output-area {
  font-size: 14px;
  line-height: 1.7;
}

/* Step 0 (PDF extraction): height-capped with internal scroll */
.card-response.capped .output-area {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--bg-page);
}

.card-response.capped .output-area::-webkit-scrollbar {
  width: 5px;
}
.card-response.capped .output-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}


/* ── 13. Continue Button (between cards) ──────────────────────── */

.continue-row {
  display: flex;
  justify-content: flex-end;
  padding: 12px 0;
}


/* ── 14. Export Card ──────────────────────────────────────────── */

.card-export .card-body {
  text-align: center;
}

.card-export .export-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
}

.card-export .session-summary {
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}


/* ── 15. Loading / Spinner ────────────────────────────────────── */

.card-loading .card-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 16px 20px;
}

.card-loading .log-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.card-loading .log-line {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
}
.card-loading .log-line.active {
  color: var(--text-primary);
  font-weight: 500;
}

.spinner {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ── 16. Usage Bar (fixed bottom) ─────────────────────────────── */

#usage-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 6px 24px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: center;
  z-index: 100;
}


/* ── 17. Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: 8px 18px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

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

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--accent-hover);
}


/* ── 18. Markdown Rendering ───────────────────────────────────── */

.output-area h1 { font-size: 18px; font-weight: 600; margin: 16px 0 8px; }
.output-area h2 { font-size: 16px; font-weight: 600; margin: 14px 0 6px; }
.output-area h3 { font-size: 14px; font-weight: 600; margin: 12px 0 4px; }
.output-area p { margin: 8px 0; }
.output-area ul, .output-area ol { margin: 8px 0 8px 24px; }
.output-area li { margin: 4px 0; }

.output-area table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
  table-layout: fixed;
  word-wrap: break-word;
}
.output-area th, .output-area td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.output-area th {
  background: var(--bg-page);
  font-weight: 600;
  font-size: 12px;
}
.output-area tr:nth-child(even) {
  background: var(--bg-page);
}
.output-area blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}
.output-area code {
  background: var(--bg-page);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.output-area pre {
  background: var(--bg-page);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--border);
}
.output-area pre code {
  background: none;
  padding: 0;
}
.output-area a { color: var(--accent); }
.output-area strong { font-weight: 600; }


/* ── 19. Error States ─────────────────────────────────────────── */

.error-msg {
  color: var(--error);
  background: var(--error-light);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
}


/* ── 20. Spending Page ────────────────────────────────────────── */

#dashboard h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

#dashboard h2:not(:first-child) {
  margin-top: 32px;
}

#dashboard table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#dashboard th {
  background: var(--bg-page);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
}

#dashboard td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 13px;
}

#dashboard tr:hover {
  background: var(--bg-hover);
}

#dashboard tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--text-primary);
  padding-top: 10px;
}

#no-data {
  color: var(--text-muted);
  text-align: center;
  margin-top: 32px;
  font-style: italic;
}


/* ── 21. Income Report View ────────────────────────────────────── */

/* The "Grouped by image" / "Strict date order" label exists only for
   the printed PDF, where the live checkbox would be meaningless. On
   screen the checkbox says which view is showing, so the label is
   hidden and the print block below swaps the two. */
.report-order-print-label {
  display: none;
}


/* ── 22. Print Override ────────────────────────────────────────── */

@media print {
  body { background: white; }
  .page { max-width: none; padding: 0; }
  header, #usage-bar, #toc, #splitter, .card-prompt, .card-upload, .card-loading, .card-export, .continue-row {
    display: none !important;
  }
  /* Put the income report's OWN header back. The blanket `header`
     hide above is aimed at the page's nav bar, but the report view
     wraps its title ("<NAME> Earnings for <period>") and its headline
     Total line in a <header> too, so it reuses the global header flex
     layout on screen. Without this rule the printed PDF, which is the
     artifact that actually gets shared, has no name, no period and no
     total anywhere in it. The id selector outranks the bare `header`
     selector above, so the nav bar stays hidden and only the report's
     own block comes back. The element stays a <header> on purpose:
     its screen layout comes from the global `header` rule. */
  #report-view header { display: flex !important; }
  #workspace { display: block !important; }
  #conversation { padding-left: 0 !important; }
  .card-response { box-shadow: none; border: none; margin: 0; }
  .card-response.capped .output-area { max-height: none; overflow: visible; }

  /* Summary ordering control: the checkbox is interactive noise in a
     PDF, but the PDF must still record WHICH view produced it (same
     provenance motive as the build stamp), so the checkbox goes and
     the static label appears in its place. */
  .report-group-toggle { display: none !important; }
  .report-order-print-label { display: inline !important; }

  /* Income report PDF layout: each per-image group (photo, then its
     data extract and change notes, in that order since 2026-09-19)
     starts on its own page so the printed PDF reads as page 1 =
     header/summary, page 2 = Image 1, etc. */
  .photo-section { break-before: page; page-break-before: always; }
  /* Cap screenshot height in print so the image stays on the same
     page as its data extract table + notes, which now follow it,
     instead of wrapping to
     the next page. Aspect ratio is preserved (max-height scales,
     doesn't crop). 4in is intentionally tight so it's visibly
     smaller than the original — confirms the cap is in effect.
     !important is required because the rendered <img> carries an
     inline style="max-height:720px;..." that would otherwise win on
     specificity. */
  .photo-section img { max-height: 4in !important; }
}
