:root {
  --bg: #f5f1e8;
  --panel: rgba(255, 252, 247, 0.94);
  --panel-strong: #fffdf8;
  --text: #182229;
  --muted: #5d6867;
  --line: #d8ccbc;
  --accent: #145e56;
  --accent-soft: #dfeee8;
  --warn: #916211;
  --warn-soft: #f4ead2;
  --high: #8b3d37;
  --high-soft: #f3dfdc;
  --shadow: 0 14px 36px rgba(24, 34, 41, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(20, 94, 86, 0.05), transparent 220px),
    var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.page-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 24px auto 40px;
  display: grid;
  gap: 20px;
}

.page-shell > *,
.result-stack > *,
.answer-grid > *,
.query-card,
.panel,
.query-form,
.sample-strip,
.sample-list,
.inline-controls,
textarea,
.tracker-details,
.flag-stack,
.flag-card,
.table-shell {
  min-width: 0;
}

.page-header,
.query-card,
.panel {
  background: var(--panel);
  border: 1px solid rgba(216, 204, 188, 0.92);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.page-header,
.panel,
.query-card {
  padding: 22px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  font-size: 2.1rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1.18rem;
}

h4 {
  font-size: 0.98rem;
}

.lede,
.muted,
.panel-note,
.subtle-label {
  color: var(--muted);
}

.lede {
  max-width: 760px;
  margin: 10px 0 0;
  line-height: 1.6;
}

.status-group {
  display: grid;
  gap: 10px;
  justify-items: end;
  max-width: 360px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
}

.status-pill.ready {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill.warning {
  background: var(--warn-soft);
  color: var(--warn);
}

.subtle-label {
  font-size: 0.86rem;
  text-align: right;
  line-height: 1.45;
}

.query-card {
  display: grid;
  gap: 18px;
}

.query-topline,
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.inline-controls,
.query-actions,
.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.query-form {
  display: grid;
  gap: 14px;
}

textarea {
  width: 100%;
  min-height: 106px;
  resize: vertical;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
}

textarea:focus,
input:focus {
  outline: 2px solid rgba(20, 94, 86, 0.18);
  border-color: var(--accent);
}

.toggle,
.max-rows {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.max-rows input {
  width: 84px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.primary-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.primary-button:disabled {
  opacity: 0.65;
  cursor: progress;
}

.sample-strip {
  display: grid;
  gap: 10px;
}

.sample-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sample-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sample-question {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
}

.sample-question:hover {
  border-color: var(--accent);
  background: rgba(20, 94, 86, 0.04);
}

.result-shell {
  display: grid;
  gap: 20px;
}

.result-shell.is-empty #rows-card,
.result-shell.is-empty #pdf-card,
.result-shell.is-empty #relevant-flags-card {
  display: none;
}

.answer-panel {
  background: linear-gradient(180deg, rgba(20, 94, 86, 0.05), rgba(255, 252, 247, 0.98));
}

.answer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.9fr);
  gap: 18px;
  margin-top: 18px;
}

.answer-copy {
  margin: 12px 0 0;
  font-size: 1rem;
  line-height: 1.65;
  white-space: pre-line;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 253, 248, 0.92);
}

.mini-list {
  margin: 12px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.warnings {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.warning-item {
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid rgba(145, 98, 17, 0.16);
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 11px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  background: rgba(20, 94, 86, 0.08);
  color: var(--accent);
}

.result-stack {
  display: grid;
  gap: 20px;
}

.panel-note {
  margin: 12px 0 0;
  line-height: 1.55;
}

.table-shell {
  margin-top: 16px;
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.empty-state {
  padding: 20px;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead {
  background: #f1e8db;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(216, 204, 188, 0.85);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

td {
  white-space: normal;
  line-height: 1.45;
}

tbody tr:nth-child(even) {
  background: rgba(245, 241, 232, 0.6);
}

.flag-stack {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.flag-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px;
  background: var(--panel-strong);
  width: 100%;
  overflow: hidden;
}

.flag-card.high {
  border-color: rgba(139, 61, 55, 0.24);
}

.flag-card.medium {
  border-color: rgba(145, 98, 17, 0.2);
}

.flag-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}

.flag-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.flag-badge.high {
  background: var(--high-soft);
  color: var(--high);
}

.flag-badge.medium {
  background: var(--warn-soft);
  color: var(--warn);
}

.flag-badge.rule {
  background: var(--accent-soft);
  color: var(--accent);
}

.subsection-title {
  margin-top: 18px;
}

.tracker-details summary,
#sql-panel summary {
  cursor: pointer;
  font-weight: 700;
}

pre {
  margin: 14px 0 0;
  padding: 16px;
  border-radius: 16px;
  background: #f7f1e6;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.55;
}

.tracker-stack .flag-card {
  background: rgba(255, 252, 247, 0.9);
}

/* ---------------- dashboard additions ---------------- */

.ghost-button {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}
.ghost-button:hover { background: rgba(20, 94, 86, 0.06); }
.ghost-button:disabled { opacity: 0.55; cursor: progress; }

.fy-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel-strong);
}
.fy-toggle .fy-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}
.fy-toggle .fy-btn:hover { color: var(--text); }
.fy-toggle .fy-btn.is-active { background: var(--accent); color: #fff; }

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--panel);
  border: 1px solid rgba(216, 204, 188, 0.92);
  border-radius: 999px;
  padding: 6px;
  box-shadow: var(--shadow);
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--accent); color: #fff; }

.tab-panel { display: grid; gap: 20px; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.kpi-row.tight { margin-top: 14px; }
.kpi-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 6px;
}
.kpi-card.neg { border-color: rgba(139, 61, 55, 0.4); background: var(--high-soft); }
.kpi-card.pos { border-color: rgba(20, 94, 86, 0.35); background: var(--accent-soft); }
.kpi-card.warn { border-color: rgba(145, 98, 17, 0.35); background: var(--warn-soft); }
.kpi-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.kpi-value { font-family: Georgia, serif; font-size: 1.5rem; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.84rem; color: var(--muted); }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.swatch.budget { background: #9db8b2; }
.swatch.ok { background: var(--accent); }
.swatch.over { background: var(--high); }

.chart-shell { margin-top: 18px; display: grid; gap: 16px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 16px;
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 12px;
  padding: 6px;
  cursor: pointer;
  text-align: left;
}
.bar-row:hover { background: rgba(20, 94, 86, 0.05); }
.bar-label { display: grid; gap: 2px; }
.bar-name { font-weight: 700; }
.bar-cap { font-size: 0.82rem; color: var(--muted); }
.bar-cap.neg { color: var(--high); font-weight: 700; }
.bar-track { display: grid; gap: 5px; }
.bar { height: 13px; border-radius: 999px; min-width: 2px; }
.bar.budget { background: #9db8b2; }
.bar.used.ok { background: var(--accent); }
.bar.used.over { background: var(--high); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.cfop-select {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  max-width: 360px;
}

.cfop-summary { display: grid; gap: 12px; }
.cfop-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.cfop-head h3 { display: inline; margin-right: 10px; }
.note-line {
  margin: 6px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  line-height: 1.5;
}

td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.num.neg { color: var(--high); font-weight: 700; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.82rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(20, 94, 86, 0.06); }
.doc-link { color: var(--accent); font-weight: 700; text-decoration: none; }
.doc-link:hover { text-decoration: underline; }

.page-footer { text-align: center; padding: 4px 0 8px; }

.tx-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.tx-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
}
.tx-search {
  flex: 1 1 280px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }

/* reconciliation grid */
.cell-dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.cell-dot.complete { background: var(--accent); }
.cell-dot.partial { background: var(--warn); }
.cell-dot.missing { background: var(--high); }
.cell-dot.future { background: #c9bca9; }
.cell-dot.rogue { background: var(--panel-strong); border: 2px solid var(--high); }

.recon-table th.recon-col { text-align: center; white-space: nowrap; }
.recon-fund { font-weight: 700; white-space: nowrap; }
.recon-cell {
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  position: relative;
}
.recon-cell.complete { background: var(--accent-soft); color: var(--accent); }
.recon-cell.partial { background: var(--warn-soft); color: var(--warn); }
.recon-cell.missing { background: var(--high-soft); color: var(--high); }
.recon-cell.future { color: var(--muted); }
.recon-cell.has-rogue { box-shadow: inset 0 0 0 2px var(--high); }
.rogue-flag { color: var(--high); margin-left: 2px; font-size: 0.85rem; }

/* document hits (agent sources) */
.doc-hits { display: grid; gap: 12px; margin-top: 8px; }
.doc-hit {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--panel-strong);
}
.doc-hit-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; justify-content: space-between; }
.doc-meta { font-size: 0.82rem; color: var(--muted); }
.doc-snippet { margin: 8px 0 0; color: var(--text); line-height: 1.55; font-size: 0.92rem; }

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 980px) {
  .page-header,
  .query-topline,
  .panel-heading,
  .answer-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .status-group {
    justify-items: start;
    max-width: none;
  }

  .inline-controls {
    justify-content: start;
  }

  .two-col { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 16px, 100%);
    margin: 12px auto 24px;
    gap: 14px;
  }

  .page-header,
  .query-card,
  .panel {
    padding: 16px;
    border-radius: 16px;
  }

  .sample-list,
  .inline-controls,
  .meta-chips {
    gap: 8px;
  }

  .sample-list {
    display: grid;
    grid-template-columns: 1fr;
  }

  .inline-controls,
  .query-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toggle,
  .max-rows {
    width: 100%;
    justify-content: space-between;
  }

  .sample-question,
  .primary-button,
  .max-rows input {
    width: 100%;
  }
}
