:root {
  --bg: #f4f5f9;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e4ec;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-soft: #eef0ff;
  --good: #16a34a;
  --good-soft: #ecfdf3;
  --warn: #b45309;
  --warn-soft: #fff7e6;
  --error: #dc2626;
  --error-soft: #fdecec;
  --gray-soft: #f1f2f6;
  --gray-text: #4b5563;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* App shell: fixed-width history sidebar + everything else */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}
.sidebar {
  flex: none;
  width: 280px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-new-btn {
  width: 100%;
  text-align: center;
}
.sidebar-new-btn-hidden { display: none; }
.sidebar-search {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: var(--gray-soft);
}
.sidebar-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-quota {
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sidebar-quota-full { color: var(--warn); }
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.history-item {
  position: relative;
  border-radius: 10px;
}
.history-item:hover { background: var(--gray-soft); }
.history-item-active { background: var(--accent-soft); }
.history-item-link {
  display: block;
  padding: 8px 30px 8px 10px;
  text-decoration: none;
  color: var(--text);
}
.history-item-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-active .history-item-title { color: var(--accent-dark); }
.history-item-flag { color: var(--warn); }
.history-item-subtitle {
  font-size: 11.5px;
  color: var(--gray-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.history-item-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.history-item-delete-form {
  position: absolute;
  top: 4px;
  right: 2px;
  margin: 0;
}
.history-item-delete {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.history-item-delete:hover { color: var(--error); background: var(--error-soft); }
.history-empty {
  font-size: 13px;
  padding: 8px 10px;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 16px;
  cursor: pointer;
}

.main-col {
  flex: 1;
  min-width: 0;
}

@media (max-width: 900px) {
  .sidebar-toggle { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 15;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.15s ease;
    box-shadow: 2px 0 10px rgba(16, 24, 40, 0.12);
  }
  .sidebar.sidebar-open { transform: translateX(0); }
  .main-col { width: 100%; }
  .topbar-inner { padding-left: 60px; }
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
/* Single shared brand mark, reused everywhere (topbar/sidebar/footer/
   login) via the brand_lockup() macro: icon on top, company name below.
   The icon art ships on a solid black canvas (no transparency) - rather
   than let that show up as a stray black rectangle on the white page, it
   sits in its own small dark "plate", which reads as an intentional badge
   instead of a rendering glitch. */
.brand-lockup {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.brand-lockup-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #101114;
  border-radius: 8px;
  flex: none;
}
.brand-lockup-icon img { display: block; }
.brand-lockup-name {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  line-height: 1.2;
}
.brand-lockup-sm .brand-lockup-icon { padding: 4px; border-radius: 7px; }
.brand-lockup-sm .brand-lockup-icon img { height: 22px; width: auto; }
.brand-lockup-sm .brand-lockup-name { font-size: 10.5px; }
.brand-lockup-lg .brand-lockup-icon { padding: 10px; border-radius: 14px; }
.brand-lockup-lg .brand-lockup-icon img { height: 44px; width: auto; }
.brand-lockup-lg .brand-lockup-name { font-size: 19px; }

/* Header only: name sits beside the icon, not stacked below it - the
   sidebar footer/login page keep the shared macro's default stacked
   layout, which suits their narrower/centered contexts better. */
.topbar .brand-lockup {
  flex-direction: row;
  gap: 8px;
}
.topbar .brand-lockup-name { font-size: 13px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.btn-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.btn-link:hover { color: var(--accent-dark); text-decoration: underline; }

/* --- Admin link (topbar) -------------------------------------------------
   A single direct link into the tile dashboard (templates/admin.html) -
   used to be a dropdown of 4 links, each just pre-selecting a filter the
   dashboard's own tiles already let you click into, so the extra step
   was dropped in favor of going straight there. */
.admin-menu-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
}
.admin-menu-trigger:hover { border-color: var(--accent); color: var(--accent-dark); }
.admin-menu-icon { font-size: 14px; line-height: 1; }
.admin-menu-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
}

.app-footer {
  max-width: 880px;
  margin: 32px auto 0;
  padding: 18px 24px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.app-footer-tagline { color: var(--muted); font-size: 12.5px; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

/* Login page - standalone, not part of the app shell/sidebar (rendered
   before a session exists) but built from the same white/blue visual
   language (.card, .btn-primary, etc.) as everywhere else, rather than
   the browser's own unstyleable native login popup. */
.login-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
.login-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.login-card .brand-lockup { margin-bottom: 20px; }
.login-title { margin: 0 0 2px; font-size: 20px; }
.login-card form { width: 100%; text-align: left; margin-top: 18px; }
.login-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}
.login-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: white;
}
.login-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-submit { width: 100%; margin-top: 22px; text-align: center; }
.login-footer { font-size: 12.5px; }

.page {
  max-width: 880px;
  margin: 40px auto;
  padding: 0 24px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

h1 { margin-top: 0; font-size: 22px; }
h2 { font-size: 16px; margin-top: 32px; }
.muted { color: var(--muted); font-size: 14px; }
.error-text { color: var(--error); font-size: 14px; }

.dropzone {
  margin-top: 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-title { font-size: 15px; font-weight: 500; margin: 0 0 6px; }
.dropzone-hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.btn {
  display: inline-block;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled {
  background: #c7c9f5;
  cursor: not-allowed;
}
.btn-outline {
  background: white;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline:hover { background: var(--accent-soft); }

.file-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.file-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
}
.file-chip-remove {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.file-chip-remove:hover { color: var(--error); }

.error-banner {
  margin-top: 20px;
  background: var(--error-soft);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
}
.success-banner {
  margin-top: 20px;
  background: var(--good-soft);
  border: 1px solid var(--good);
  color: var(--good);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
}

.required-star { color: var(--error); }

.confirm-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 24px;
  font-size: 14px;
}
.confirm-table th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 10px 12px;
  background: var(--gray-soft);
}
.confirm-table tr.group-row td {
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: none;
}
.confirm-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.confirm-table select {
  width: 100%;
  min-width: 200px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: white;
}
.file-select-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.file-select-row .file-select { width: auto; flex: 1; }
.view-file-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  text-decoration: none;
  font-size: 15px;
}
.view-file-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.view-file-btn-disabled {
  pointer-events: none;
  opacity: 0.35;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge-content { background: var(--good-soft); color: var(--good); }
.badge-weak { background: var(--warn-soft); color: var(--warn); }
.badge-filename { background: var(--warn-soft); color: var(--warn); }
.badge-default { background: var(--accent-soft); color: var(--accent-dark); }
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-none { background: var(--gray-soft); color: var(--gray-text); }
.reason { margin-top: 6px; font-size: 12.5px; }
.file-confidence-row { margin-top: 6px; }
.file-confidence-row + .file-confidence-row { padding-top: 6px; border-top: 1px solid var(--border); }

.actions {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Full-page loading state while the automation actually runs (a blocking
   POST that can take a minute or two for large files) - shown from the
   moment #run-form is submitted until the browser navigates away to the
   results page. */
.run-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(244, 245, 249, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* THE actual bug behind "clicking Run Automation does nothing": a plain
   class selector's `display: flex` is an author-stylesheet rule, and
   author rules always beat the browser's built-in `[hidden] { display:
   none }` UA rule regardless of specificity or source order - so the
   `hidden` attribute on #run-overlay was being silently ignored. The
   overlay was rendered (and capturing every click via `position: fixed;
   inset: 0`) from the moment the confirm page loaded, before anyone
   touched "Run Automation" - confirmed live with Playwright, which
   reported the click on the button being intercepted by this exact div
   even while its `hidden=""` attribute was present in the DOM. Needs a
   selector specific enough to win back control of `display` when hidden
   is set. */
.run-overlay[hidden] { display: none; }
.run-overlay-content {
  text-align: center;
  max-width: 380px;
  padding: 32px;
}
.run-overlay-hint {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 18px 0 0;
  min-height: 1.4em;
  animation: loader-message-fade 2.2s ease-in-out infinite;
}
@keyframes loader-message-fade {
  0% { opacity: 0.35; }
  15%, 85% { opacity: 1; }
  100% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .run-overlay-hint { animation: none; }
  .chat-typing span { animation: none; opacity: 0.8; }
}
.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}


.pipeline-heading { margin-top: 0; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.tile-hint { margin-top: 4px; }

.stat-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.stat-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: var(--card-bg);
  font: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: box-shadow 0.12s, border-color 0.12s;
}
.stat-tile:hover { border-color: var(--accent); }
.stat-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.stat-tile-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft) inset; }
.stat-tile.stat-good { background: var(--good-soft); border-color: var(--good); }
.stat-tile.stat-new { background: var(--accent-soft); border-color: var(--accent); }
.stat-tile.stat-warn { background: var(--warn-soft); border-color: var(--warn); }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Books ITC -> Matched -> Potentially Claimable -> Under Review - a
   fixed 4-across row reads as one funnel; the default 3-column .stat-grid
   would wrap the 4th tile onto its own line. See results.html/
   static/itc-position.js. */
.itc-position-grid { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) { .itc-position-grid { grid-template-columns: repeat(2, 1fr); } }
.itc-position-detail { margin-top: 14px; }

.tile-detail-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--gray-soft);
}
.tile-detail-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.spinner-sm { width: 18px; height: 18px; border-width: 2.5px; }
.tile-detail-table-wrap { overflow-x: auto; }
.tile-detail-table { background: var(--card-bg); }
.tile-detail-truncated { margin-top: 8px; font-size: 12.5px; }

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 13px;
}
.report-table th, .report-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.report-table th { color: var(--muted); font-weight: 600; }

@media (max-width: 640px) {
  .confirm-table, .confirm-table thead, .confirm-table tbody, .confirm-table th, .confirm-table td, .confirm-table tr {
    display: block;
  }
  .confirm-table thead { display: none; }
  .confirm-table tr { margin-bottom: 16px; border: 1px solid var(--border); border-radius: 10px; }
  .stat-grid { grid-template-columns: 1fr; }
}

/* Excel viewer */
.page.page-wide { max-width: 1400px; }
.view-card .results-header { align-items: center; }
.view-card .results-header h1 {
  font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

.sheet-tabs {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.sheet-tab {
  font-size: 13px;
  text-decoration: none;
  color: var(--gray-text);
  background: var(--gray-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}
.sheet-tab:hover { border-color: var(--accent); color: var(--accent); }
.sheet-tab-active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.view-table-wrap {
  margin-top: 16px;
  overflow: auto;
  max-height: 72vh;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.view-table {
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: pre;
}
.view-table th, .view-table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.view-table thead th {
  position: sticky;
  top: 0;
  background: var(--gray-soft);
  color: var(--gray-text);
  z-index: 1;
}
.row-num-col {
  position: sticky;
  left: 0;
  background: var(--gray-soft);
  color: var(--muted);
  text-align: right;
  z-index: 2;
}
thead .row-num-col { z-index: 3; }
/* Landed on via a chat answer's "<Sheet> sheet, row N" link (see
   intake.js's linkifySheetReferences and app.py's view_excel ?row=N) -
   the row this specific answer was about, so it's findable at a glance
   instead of scanning the whole sheet by eye. */
.view-row-highlight td { background: var(--warn-soft); }
.view-row-highlight .row-num-col { background: var(--warn); color: #fff; font-weight: 700; }
.cell-formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--accent-dark);
  background: var(--accent-soft);
}

/* --- Chat panel (results page - ask about this run, local Qwen model) --- */
.chat-card { padding: 24px 28px 20px; }
.chat-status-row { display: flex; justify-content: flex-end; }
.chat-status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.chat-status[data-state="online"] { background: var(--good); }
.chat-status[data-state="offline"] { background: var(--error); }

.chat-messages {
  margin-top: 10px;
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
.chat-messages:empty { margin-top: 4px; }
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg-user .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg-assistant .chat-bubble { background: var(--gray-soft); color: var(--text); border-bottom-left-radius: 4px; }
.chat-msg-error .chat-bubble { background: var(--error-soft); color: var(--error); }

.chat-typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: chat-typing-bounce 1.1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-suggest-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.chat-suggest-row.hidden { display: none; }
.chat-suggest-chip {
  background: var(--gray-soft); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; color: var(--text); cursor: pointer; text-align: left;
  white-space: normal;
}
.chat-suggest-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chat-suggest-chip:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-input-row {
  margin-top: 14px;
  display: flex;
  gap: 10px;
}
.chat-input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
}
.chat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-send { flex: none; }

/* --- Chat-first intake (redesigned upload screen) --- */
.intake-center {
  display: flex; flex-direction: column; align-items: center;
  /* Idle state (no thread yet): centers the hero + composer TOGETHER as
     one visual group in the middle of the viewport, matching how the
     "new chat" landing screen of a chat app usually reads - not the
     heading floating alone in the upper half with the input pinned all
     the way down at the true bottom, which is what plain flex:1-on-the-
     hero-alone used to produce on a tall viewport (see the :has() rule
     below for what changes once a real thread starts). min-height, not
     height/max-height - tall enough to center the empty state, but free
     to grow past that once real content (a verification card with many
     files, say) needs more room; the page itself scrolls then, same as
     any normal page - not boxed into a fixed-height inner scroll pane. */
  justify-content: center;
  min-height: calc(100vh - 140px);
}
.intake-hero {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 4px; max-width: 820px;
}
.intake-hero h1 { font-size: 24px; margin: 0; }
.intake-hero.hidden { display: none; }

/* Big centered drop target - same attach flow as the composer's own "+"
   button (see intake.js: both funnel into the one hidden #intake-file-input
   and the same addPendingFiles), just a much larger, more discoverable
   target for a first-time visitor who hasn't spotted the small "+" yet. */
.intake-dropzone {
  margin-top: 18px; width: 100%; max-width: 620px; padding: 48px 28px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--card-bg); border: 2px dashed var(--border); border-radius: 20px;
  color: var(--gray-text); font-family: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.intake-dropzone:hover, .intake-dropzone:focus-visible {
  border-color: var(--accent); color: var(--accent-dark); outline: none;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.12); transform: translateY(-1px);
}
.intake-dropzone.intake-dropzone-active {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark);
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.16); transform: translateY(-1px);
}
.intake-dropzone-icon {
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  transition: background 0.15s, color 0.15s;
}
.intake-dropzone:hover .intake-dropzone-icon, .intake-dropzone.intake-dropzone-active .intake-dropzone-icon {
  background: var(--accent); color: #fff;
}
.intake-dropzone-text { font-size: 15px; }
.intake-dropzone-hint { font-size: 12px; color: var(--muted); font-weight: 400; }

.intake-thread {
  width: 100%; max-width: 1080px;
  padding: 20px 4px 12px; display: none; flex-direction: column; gap: 14px;
}
.intake-thread.show { display: flex; }
/* Once a real conversation is showing, switch back to normal top-down
   chat layout - the thread grows to fill the space and the composer
   returns to sticking at the bottom (see .intake-composer-wrap below),
   instead of staying grouped/centered with the now-hidden hero. */
.intake-center:has(.intake-thread.show) {
  justify-content: flex-start;
}
.intake-center:has(.intake-thread.show) .intake-thread { flex: 1; }

.intake-msg { display: flex; }
.intake-msg-user { justify-content: flex-end; }
.intake-msg-assistant { justify-content: flex-start; }
.intake-bubble { max-width: 84%; }
.intake-msg-user .intake-bubble {
  background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 14px; border-bottom-right-radius: 4px;
  font-size: 14px;
}
.intake-msg-assistant .intake-bubble { width: 100%; }
.intake-bubble-note { color: var(--muted); font-size: 13px; }

.intake-chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.intake-file-chip {
  background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
}

.intake-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); font-size: 13.5px;
  white-space: pre-wrap;
}
/* A chat answer's "<Sheet> sheet, row N" source reference, turned into a
   link straight to that row - see intake.js's linkifySheetReferences. */
.intake-sheet-link { color: var(--accent); font-weight: 600; text-decoration: underline; }
.intake-sheet-link:hover { color: var(--accent-dark); }

/* --- Post-run feedback (results page - see webapp/feedback.py) --- */
.feedback-fab {
  position: fixed; bottom: 24px; right: 24px; z-index: 40;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.25); cursor: pointer;
}
.feedback-fab:hover { background: var(--accent-dark); }

.feedback-modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(16, 24, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.feedback-modal-backdrop[hidden] { display: none; }
.feedback-modal {
  position: relative; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--card-bg); border-radius: var(--radius); padding: 28px 24px 24px;
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.3);
}
.feedback-modal h2 { margin-top: 0; }
.feedback-modal-close {
  position: absolute; top: 14px; right: 14px; width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--gray-soft); color: var(--muted);
  font-size: 16px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.feedback-modal-close:hover { border-color: var(--accent); color: var(--accent); }

.feedback-issue-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 12px;
}
.feedback-issue-option {
  display: flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text); cursor: pointer;
}
.feedback-comment { height: auto; resize: vertical; font-family: inherit; }

/* Admin review page (/admin/feedback) - one card per item rather than a
   table: issue count, comment length, and attachment count all vary
   wildly per submission, which made a fixed-column table (the original
   design) produce wildly uneven row heights and force multi-line
   attachment filenames into a narrow column - hard to scan. A card gives
   every piece of that variable content its own full-width line. */
.feedback-admin-list { display: flex; flex-direction: column; gap: 14px; }
.feedback-admin-item {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  background: var(--card-bg);
}
.feedback-admin-item-fixed { background: var(--gray-soft); }
.feedback-admin-item-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.feedback-admin-run-link { font-weight: 700; color: var(--accent-dark); text-decoration: none; margin-right: 6px; }
.feedback-admin-run-link:hover { text-decoration: underline; }
.feedback-admin-issues { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.feedback-admin-issue-tag {
  background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.feedback-admin-comment {
  margin: 10px 0 0; font-size: 13.5px; color: var(--text); line-height: 1.5; white-space: pre-wrap;
}
.feedback-admin-item .file-row-list { margin-top: 10px; }
.feedback-admin-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

/* --- Scanned invoice review (a PDF/image, extracted by a vision model
   and always editable before it can be run - see webapp/invoice_vision.py
   and intake.js's invoiceReviewHtml) --- */
.invoice-review {
  margin-top: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--gray-soft);
}
.invoice-review-error {
  font-size: 12.5px; color: var(--error); margin-bottom: 8px;
}
.invoice-review-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 10px;
}
.invoice-review-field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.invoice-review-input, select.invoice-review-input {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  font-family: inherit; background: var(--card-bg); color: var(--text);
}
.invoice-review-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.invoice-review-input.invoice-review-lowconf { border-color: var(--warn); background: var(--warn-soft); }
.invoice-review-warn { margin-top: 8px; font-size: 12px; color: var(--warn); }

.intake-suggest-row { display: flex; flex-wrap: wrap; gap: 7px; }
.intake-suggest-chip {
  background: var(--gray-soft); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; color: var(--text); cursor: pointer; text-align: left;
  white-space: normal;
}
.intake-suggest-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.intake-suggest-chip:disabled { opacity: 0.5; cursor: not-allowed; }
.intake-step { display: flex; align-items: center; gap: 10px; }
.intake-spinner {
  width: 15px; height: 15px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; display: inline-block;
}
@media (prefers-reduced-motion: reduce) { .intake-spinner { animation-duration: 1.6s; } }

.intake-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  margin: 10px 0 6px;
}
.intake-group-label:first-child { margin-top: 0; }
.intake-role-row { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; }
.intake-dot {
  width: 18px; height: 18px; border-radius: 50%; flex: none; margin-top: 1px;
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: #fff;
}
.intake-dot-ok { background: var(--good); }
.intake-dot-pending { background: var(--gray-soft); color: var(--muted); }
.intake-role-label { flex: 1; min-width: 0; }
.intake-role-key { font-weight: 600; }
.intake-row-sub { font-size: 12.5px; color: var(--gray-text); margin-top: 2px; }
.intake-row-missing { color: var(--warn); }
/* One line per file when a role has more than one attached (e.g. a
   year's worth of monthly ledgers) - filename + badge, then its own
   remove button immediately after (not pushed to the far edge of the
   row) so it visibly belongs to that one file and is easy to hit
   without a second look, one line per file rather than one remove
   button for the whole role. */
.intake-role-file { display: flex; align-items: center; justify-content: flex-start; gap: 8px; margin-top: 4px; }
.intake-role-file:first-child { margin-top: 2px; }
.intake-role-file .intake-row-btn { width: 22px; height: 22px; font-size: 11px; }
.intake-role-file .view-file-btn { width: 22px; height: 22px; font-size: 11px; border-radius: 6px; }
.intake-row-btn {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card-bg); color: var(--muted); cursor: pointer; font-size: 12px;
}
.intake-row-btn:hover { border-color: var(--error); color: var(--error); background: var(--error-soft); }
.intake-row-btn-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.intake-result-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.intake-result-actions .btn:disabled { opacity: 0.45; cursor: not-allowed; }

.intake-stat-group + .intake-stat-group { margin-top: 10px; }
.intake-stat-group-title { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.intake-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.intake-stat-tile { background: var(--gray-soft); border-radius: 10px; padding: 10px 12px; }
.intake-stat-tile.intake-stat-new { background: var(--accent-soft); }
.intake-stat-tile.intake-stat-warn { background: var(--warn-soft); }
.intake-stat-val { font-size: 19px; font-weight: 700; }
.intake-stat-lab { font-size: 11px; color: var(--gray-text); margin-top: 1px; }

.intake-composer-wrap {
  width: 100%; max-width: 1080px; padding: 12px 4px 20px;
  /* Stays reachable at the bottom of the viewport as the page grows and
     scrolls normally (see .intake-center/.intake-thread above) - without
     this, a long thread would push the composer off-screen with no
     scrollbar-free way back to it. */
  position: sticky; bottom: 0; background: var(--bg);
}
/* Hidden (not just disabled) while a run is actually executing - see
   intake.js's runAutomation - a disabled-but-visible composer still
   looks usable, which is exactly the confusion this avoids. */
.intake-composer-wrap.hidden { display: none; }
.intake-composer-hint { font-size: 11.5px; color: var(--muted); text-align: center; margin: 0 0 8px; }
/* Sticky bottom bar shown instead of the composer during file review -
   see index.html's comment and intake.js's beginRun/updateVerifyBar.
   display:none by default (same pattern as .intake-thread.show) rather
   than relying on the [hidden] attribute, so toggling it can't lose to
   author-stylesheet specificity/ordering surprises. */
.intake-verify-bar {
  display: none; align-items: center; justify-content: center; gap: 12px;
  width: 100%; max-width: 1080px; margin: 0 auto; padding: 14px 4px 20px;
  position: sticky; bottom: 0; background: var(--bg);
}
.intake-verify-bar.show { display: flex; }
.intake-composer {
  display: flex; align-items: flex-end; gap: 8px; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 22px; padding: 8px; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.intake-attach-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--gray-soft); color: var(--text); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.intake-attach-btn:hover { border-color: var(--accent); color: var(--accent); }
.intake-attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.intake-composer-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.intake-composer-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px 2px; }
.intake-chip {
  display: flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent-dark);
  border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; font-weight: 600;
}
.intake-chip button {
  border: none; background: rgba(79,70,229,0.15); color: var(--accent-dark); width: 16px; height: 16px;
  border-radius: 50%; cursor: pointer; font-size: 10px; display: flex; align-items: center; justify-content: center;
}
.intake-composer-input {
  border: none; outline: none; background: transparent; font-size: 14.5px; color: var(--text);
  padding: 7px 6px; font-family: inherit; width: 100%;
}
.intake-composer-input:disabled { color: var(--muted); }
.intake-send-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--border); color: var(--muted); cursor: not-allowed; font-size: 15px;
  display: flex; align-items: center; justify-content: center; transition: background 0.15s, color 0.15s;
}
.intake-send-btn.ready { background: var(--accent); color: #fff; cursor: pointer; }
.intake-send-btn.ready:hover { background: var(--accent-dark); }

/* --- Compact input/output file rows (results page + inline results card) --- */
/* Two columns: input files (left) and the output file (right) - each one
   a group of compact pills rather than a stack of full-width rows. Wraps
   to a single column on its own when there isn't room side-by-side
   (narrower contexts like the inline chat results card). */
.files-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin-top: 12px;
}
.files-col { flex: 1 1 260px; min-width: 0; }
.files-col-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}
.file-row-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.file-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--gray-soft);
  flex: none;
  max-width: 100%;
}
.file-row-label {
  font-weight: 500;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-row .view-file-btn {
  width: 26px;
  height: 26px;
  font-size: 12px;
  border-radius: 6px;
}

/* --- Active sessions / login audit (admin) ------------------------------ */
.session-status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.session-status-online { background: var(--good); }
.session-status-idle { background: var(--warn); }
.session-status-offline { background: var(--gray-text); }

.audit-table-wrap {
  overflow-x: auto;
  margin-top: 16px;
}
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  white-space: nowrap;
}
.audit-table th {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 10px 12px;
  background: var(--gray-soft);
  position: sticky;
  top: 0;
}
.audit-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.audit-table tbody tr:hover { background: var(--gray-soft); }
.audit-ip { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

/* --- Admin dashboard refresh bar (Active Sessions / Login Audit /
   Pending Registrations / Feedback) ---------------------------------- */
.admin-refresh-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -4px 0 16px;
  font-size: 12.5px;
}
.admin-refresh-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.admin-refresh-btn:hover { border-color: var(--accent); color: var(--accent-dark); }

/* --- Admin dashboard tiles (reuses .stat-tile/.stat-value/.stat-label's
   look from the results page's own clickable tiles - same interaction,
   same visual language, just a 4-across grid instead of 3) ------------ */
.admin-tile-grid { grid-template-columns: repeat(4, 1fr); margin-top: 4px; margin-bottom: 20px; }
@media (max-width: 640px) {
  .admin-tile-grid { grid-template-columns: repeat(2, 1fr); }
}
