:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --border: #e2e2dc;
  --text: #1c1d1f;
  --muted: #6b6f76;
  --accent: #0f6e5c;
  --accent-text: #ffffff;
  --accent-soft: #e3f1ed;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2123;
    --surface-2: #292b2e;
    --border: #35383c;
    --text: #ececec;
    --muted: #9a9fa6;
    --accent: #4fc2a8;
    --accent-text: #0c1f1a;
    --accent-soft: #1d332e;
    --danger: #ff8a80;
    --danger-soft: #3a1f1d;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

h1,
h2,
h3,
p {
  margin: 0;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
}

/* --- Top bar ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand-name {
  font-weight: 650;
  letter-spacing: -0.01em;
}

.company {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company::before {
  content: "·";
  margin-right: 10px;
}

.topbar-actions {
  display: flex;
  gap: 6px;
}

/* --- Buttons ------------------------------------------------------------- */

.button {
  font: inherit;
  font-weight: 550;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.button:hover {
  background: var(--surface-2);
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.button.primary:hover {
  filter: brightness(1.08);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
}

.button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.button.small {
  padding: 4px 10px;
  font-size: 13px;
}

.button:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Setup --------------------------------------------------------------- */

.setup,
.callback {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 20px;
}

.setup h1,
.callback h1 {
  font-size: 26px;
  letter-spacing: -0.02em;
}

.lede,
.callback p {
  margin-top: 8px;
  color: var(--muted);
}

.steps {
  list-style: none;
  margin: 28px 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.step {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
}

.step + .step {
  border-top: 1px solid var(--border);
}

.step > div {
  min-width: 0;
  flex: 1;
}

.step h2 {
  font-size: 15px;
  font-weight: 600;
}

.step-detail {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}

.step-mark {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}

.step.ok .step-mark {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.step.ok .step-mark::after {
  content: "✓";
}

.step.missing .step-mark {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.step.missing .step-mark::after {
  content: "!";
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.copy-row code {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
}

.waiting {
  margin-top: 28px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.waiting h2 {
  font-size: 16px;
}

.waiting p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.paste-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.paste-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* --- Chat ---------------------------------------------------------------- */

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
}

.messages > * {
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.empty {
  padding-top: 8vh;
}

.empty h1 {
  font-size: 24px;
  letter-spacing: -0.02em;
}

.empty p {
  margin-top: 6px;
  color: var(--muted);
}

.suggestions {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.suggestion {
  font: inherit;
  text-align: left;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

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

.message {
  margin-bottom: 22px;
}

.message.user {
  display: flex;
  justify-content: flex-end;
}

.message.user .bubble {
  max-width: 80%;
  padding: 9px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--accent-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Lookups the assistant ran, so every answer can be traced to its source. */
.tool {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

.tool summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
}

.tool summary::-webkit-details-marker {
  display: none;
}

.tool-kind {
  flex: none;
  color: var(--muted);
  font-weight: 600;
}

.tool-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-status {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tool.failed .tool-status {
  color: var(--danger);
}

.prose + .tool {
  margin-top: 12px;
}

.tool + .prose {
  margin-top: 14px;
}

.tool pre {
  margin: 0;
  padding: 10px;
  border-top: 1px solid var(--border);
  font: 12px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--muted);
}

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

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

.working {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

/* Rendered Markdown */
.prose > :first-child {
  margin-top: 0;
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose pre,
.prose blockquote,
.prose .table-wrap {
  margin: 0.7em 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  margin: 1.2em 0 0.4em;
  font-size: 1.05em;
  letter-spacing: -0.01em;
}

.prose ul,
.prose ol {
  padding-left: 1.4em;
}

.prose li + li {
  margin-top: 0.2em;
}

.prose pre {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  overflow-x: auto;
  font-size: 13px;
}

.prose :not(pre) > code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
}

.prose blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

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

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.prose th,
.prose td {
  padding: 7px 12px;
  white-space: nowrap;
}

/* Columns the answer aligns itself (numbers go right) keep that alignment. */
.prose th:not([align]),
.prose td:not([align]) {
  text-align: left;
}

.prose th {
  background: var(--surface-2);
  font-weight: 600;
}

.prose tr + tr td {
  border-top: 1px solid var(--border);
}

/* --- Composer ------------------------------------------------------------ */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 20px 20px;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 200px;
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.prose + .prose {
  margin-top: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

/* --- Workspace: tabs, sync bar, views ------------------------------------ */

.tabs {
  display: flex;
  gap: 2px;
  margin: 0 auto 0 24px;
}

.tab {
  font: inherit;
  font-weight: 550;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab.active {
  background: var(--accent-soft);
  color: var(--text);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.syncbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.sync-summary {
  flex: 1;
  min-width: 0;
}

.sync-summary.failed {
  color: var(--danger);
}

.sync-warnings {
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.sync-warnings p + p {
  margin-top: 4px;
}

.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
}

.view.chat {
  padding: 0;
  overflow: hidden;
}

.view-intro {
  max-width: 900px;
  margin-bottom: 18px;
}

.view-intro h1 {
  font-size: 22px;
  letter-spacing: -0.02em;
}

.view-intro p {
  margin-top: 4px;
  color: var(--muted);
}

.view > .empty {
  max-width: 640px;
  margin: 0 auto;
}

input[type="search"],
input[type="date"],
input[type="number"],
input[type="password"],
select {
  font: inherit;
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.filters input[type="search"] {
  flex: 1 1 240px;
  max-width: 360px;
}

.filters input[type="number"] {
  width: 110px;
}

.filters select {
  max-width: 220px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
}

.list-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.list-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

a.button {
  text-decoration: none;
  display: inline-block;
}

/* --- Data tables ---------------------------------------------------------- */

.table-scroll {
  overflow-x: auto;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--border);
}

.grid th,
.grid td {
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
}

.grid th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-weight: 600;
}

.grid .num {
  text-align: right;
}

.grid tfoot td {
  font-weight: 600;
  border-bottom: 0;
}

.grid tr.clickable {
  cursor: pointer;
}

.grid tr.clickable:hover td,
.grid tr.clickable:focus-visible td {
  background: var(--accent-soft);
}

.group-title {
  margin: 18px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.group-title:first-child {
  margin-top: 0;
}

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

/* --- Findings ------------------------------------------------------------- */

.finding {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.finding.high {
  border-left-color: var(--danger);
}

.finding.medium {
  border-left-color: #c98a00;
}

.finding summary {
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
}

.finding summary::-webkit-details-marker {
  display: none;
}

.finding-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.finding-title {
  flex: 1;
  font-weight: 600;
}

.finding-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.finding-why {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  max-width: 900px;
}

.finding .table-scroll {
  max-height: 480px;
  overflow: auto;
  border-top: 1px solid var(--border);
}

.finding .grid {
  border: 0;
}

.finding > .note {
  padding: 8px 14px;
  margin: 0;
}

.badge {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

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

.badge.medium {
  background: color-mix(in srgb, #c98a00 18%, transparent);
  color: color-mix(in srgb, #c98a00 70%, var(--text));
}

.passed {
  margin-top: 22px;
  font-size: 13px;
  color: var(--muted);
}

.passed h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.passed ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

/* --- Transaction drawer --------------------------------------------------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(720px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgb(0 0 0 / 18%);
  z-index: 10;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.drawer-head h2 {
  font-size: 17px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}

.drawer-body h3 {
  margin: 20px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 14px;
}

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

.facts dd {
  margin: 0;
}

.drawer-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.raw summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

.raw pre {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font: 12px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer #new-chat {
  flex: none;
}

.codex-login {
  margin-top: 8px;
}

.codex-login-output {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font: 12px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
