/* Nautilus — one stylesheet. Tokens first (the only :root block), then base,
   layout, components in page order. Dark ground, gold accent, hairlines. */

:root {
  color-scheme: dark;

  /* Ground and surfaces */
  --bg: #0c0e0d;
  --panel: #141716;
  --panel-subtle: #171b1a;
  --panel-raise: rgba(255, 255, 255, 0.014);
  --hover-wash: rgba(255, 255, 255, 0.05);

  /* Ink */
  --text: #e9e7e1;
  --text-secondary: #b6bcb7;
  --muted: #7d847f;
  --text-faint: #5d635f;

  /* Hairlines. NOTE: --line-strong is inverted on dark — it is BRIGHTER than
     --line (hover/focus borders), where on the old light theme it was darker. */
  --line: #232827;
  --line-soft: #1c211f;
  --line-strong: #39413e;

  /* Accent: gold. NOTE: --accent-dark is also inverted — it is LIGHTER than
     --accent. Every call site uses it as the hover state on filled gold. */
  --accent: #d1a74d;
  --accent-dark: #e0bd6d;
  --accent-tint: rgba(209, 167, 77, 0.11);
  --accent-line: rgba(209, 167, 77, 0.32);
  --accent-ink: #17100e;
  --accent-text: #f0d9a4;

  /* Semantic hues, each with a tint (fill) and line (border) partner */
  --green: #78c286;
  --green-tint: rgba(120, 194, 134, 0.09);
  --green-line: rgba(120, 194, 134, 0.35);
  --amber: #d9a13f;
  --amber-tint: rgba(217, 161, 63, 0.1);
  --amber-line: rgba(217, 161, 63, 0.38);
  --red: #e0705f;
  --red-tint: rgba(224, 112, 95, 0.09);
  --red-line: rgba(224, 112, 95, 0.4);
  --blue: #6f9fc4;
  --blue-tint: rgba(111, 159, 196, 0.1);
  --blue-line: rgba(111, 159, 196, 0.35);
  --purple: #9b86d0;
  --purple-tint: rgba(155, 134, 208, 0.1);
  --purple-line: rgba(155, 134, 208, 0.35);

  /* Aliases kept so existing selectors keep resolving */
  --green-dark: #8fd09b;
  --green-tint-solid: #1a2620;
  --amber-text: var(--amber);
  --teal: var(--accent);
  --teal-tint: var(--accent-tint);
  --chip: #1c211f;

  /* Geometry */
  --radius: 8px;
  --radius-lg: 10px;

  /* Elevation: dark UI leans on hairlines, not drop shadows */
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-lift: 0 8px 28px rgba(0, 0, 0, 0.55);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-dark); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-family: var(--font-serif); font-size: 30px; font-weight: 500; line-height: 1.15; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }
pre { margin: 0; font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
ul, ol { margin: 0; padding: 0; list-style: none; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 0.93em; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.h-count { font-family: var(--font-mono); font-size: 14px; color: var(--muted); margin-left: 8px; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Frame ---------- */
.app-frame { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.app-sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 22px 14px;
  background: #101312;
  border-right: 1px solid var(--line);
}
.sidebar-brand a { display: flex; flex-direction: column; gap: 2px; padding: 0 8px 20px; color: var(--text); }
.sidebar-brand span { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.sidebar-brand strong { font-family: var(--font-serif); font-size: 18px; font-weight: 500; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--text-secondary);
}
.sidebar-link:hover { background: var(--hover-wash); color: var(--text); }
.sidebar-link.active { background: var(--accent-tint); color: var(--accent-text); }
.sidebar-count {
  font-family: var(--font-mono); font-size: 11px;
  padding: 1px 7px; border-radius: 999px;
  background: var(--amber-tint); color: var(--amber); border: 1px solid var(--amber-line);
}
.sidebar-footer { margin-top: auto; padding: 0 10px; display: flex; flex-direction: column; gap: 6px; }
.sidebar-username { font-size: 12.5px; color: var(--text-secondary); }
.sidebar-sign-out { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; }
.sidebar-sign-out:hover { color: var(--text); }

.app-shell { padding: 30px 34px 60px; min-width: 0; }
.app-shell.narrow { max-width: 860px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-header .eyebrow { margin-bottom: 6px; }
.page-header .muted { margin-top: 6px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.inline-form { display: inline; margin: 0; }

/* ---------- Buttons, pills, banners ---------- */
.button, .small-button {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 7px 13px; cursor: pointer; white-space: nowrap;
}
.button:hover, .small-button:hover { border-color: var(--accent-line); color: var(--accent-text); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: var(--accent-ink); }
.button.attention { background: var(--amber-tint); border-color: var(--amber-line); color: var(--amber); }
.button.attention b { font-family: var(--font-mono); }
.small-button { padding: 4px 9px; font-size: 12px; }
.small-button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.small-button.quiet:hover { border-color: var(--line-strong); color: var(--text); }
.status-pill, .priority-pill, .deal-tag, .due-badge, .todo-count, .stage-count {
  display: inline-flex; align-items: center;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em;
  padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--text-secondary);
}
.status-pill.active { color: var(--green); border-color: var(--green-line); background: var(--green-tint); }
.status-pill.not_connected, .status-pill.closed { color: var(--muted); }
.priority-pill.urgent { color: var(--red); border-color: var(--red-line); background: var(--red-tint); }
.priority-pill.high { color: var(--amber); border-color: var(--amber-line); background: var(--amber-tint); }
.due-badge.soon { color: var(--amber); border-color: var(--amber-line); }
.due-badge.overdue { color: var(--red); border-color: var(--red-line); }
.phase-badge { display: inline-flex; align-items: center; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; padding: 2px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.todo-count { color: var(--accent-text); border-color: var(--accent-line); }
.todo-count.zero { color: var(--text-faint); border-color: var(--line); }
.notice-banner, .form-errors {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px;
}
.notice-banner { background: var(--green-tint); border: 1px solid var(--green-line); color: var(--green-dark); }
.form-errors { background: var(--red-tint); border: 1px solid var(--red-line); color: var(--red); }
.empty-state { padding: 26px 18px; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); color: var(--muted); text-align: center; }

/* ---------- Panels and forms ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; }
.panel h2 { margin-bottom: 10px; }
.panel > .section-header h2 { margin-bottom: 0; }
.section-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-header .muted { font-size: 12px; }
.section-description { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.deal-form label, .brief-form, .stack-form { display: flex; flex-direction: column; gap: 5px; }
.deal-form label > span { font-size: 12px; color: var(--text-secondary); }
.deal-form label > span small { color: var(--muted); margin-left: 6px; }
input[type="text"], input[type="date"], input[type="number"], input[type="password"], select, textarea {
  font: inherit; font-size: 13.5px; color: var(--text);
  background: var(--panel-subtle); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-tint); }
textarea { resize: vertical; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .span-2 { grid-column: span 2; }
.checkbox-group { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checkbox-group legend { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.compact-choice { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.field-hint { margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }
.form-actions.compact { margin-top: 8px; }
.quiet-details { margin-top: 14px; }
.quiet-details > summary, .board-footer > summary { font-size: 12.5px; color: var(--muted); padding: 6px 0; }
.quiet-details > summary:hover, .board-footer > summary:hover { color: var(--text); }
.quiet-list li { padding: 5px 0; font-size: 13px; border-top: 1px solid var(--line-soft); }
.quiet-list li .muted { font-size: 12px; margin-left: 6px; }

/* ---------- Board ---------- */
.kanban-board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; align-items: start; }
.stage-column { background: var(--panel-raise); border: 1px solid var(--line-soft); border-radius: var(--radius-lg); padding: 10px; min-height: 160px; }
.stage-column.drag-over { border-color: var(--accent-line); background: var(--accent-tint); }
.stage-column-header { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 10px; }
.stage-column-header h2 { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.stage-column-cards { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.deal-card {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line-strong);
  border-radius: var(--radius); padding: 11px 12px; cursor: grab;
}
.deal-card:hover { border-color: var(--line-strong); border-left-color: var(--accent); }
.deal-card h3 a { color: var(--text); }
.deal-card h3 a:hover { color: var(--accent-text); }
.deal-card-line { font-size: 12.5px; color: var(--text-secondary); margin-top: 3px; }
.deal-card-footer { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.deal-card[data-deal-type="trade"] { border-left-color: var(--blue); }
.deal-card[data-deal-type="lease"] { border-left-color: var(--green); }
.deal-card[data-deal-type="loan"] { border-left-color: var(--purple); }
.deal-card[data-deal-type="teardown"] { border-left-color: var(--amber); }
.deal-card[data-deal-type="rebuild"] { border-left-color: var(--red); }
.deal-card[data-deal-type="btb"] { border-left-color: var(--accent); }
.sortable-ghost { opacity: 0.35; }
.sortable-drag { box-shadow: var(--shadow-lift); }
.board-footer { margin-top: 22px; }

/* ---------- Deal page ---------- */
.deal-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.deal-layout .span-2 { grid-column: span 2; }
.brief-form textarea { width: 100%; font-size: 13.5px; }
.activity-list { display: flex; flex-direction: column; }
.activity-item { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.activity-item:first-child { border-top: 0; padding-top: 0; }
.activity-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.activity-subject { font-size: 12.5px; color: var(--muted); margin: 2px 0 4px; }
.asks { margin-top: 6px; padding-left: 14px; list-style: disc; color: var(--text-secondary); font-size: 12.5px; }

/* ---------- To-dos ---------- */
.todo-add { display: grid; grid-template-columns: 1fr 200px 150px 120px auto; gap: 8px; margin-bottom: 24px; }
.todo-group { margin-bottom: 22px; }
.todo-group-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.todo-group-title a { color: var(--text); }
.todo-group-title .muted { font-family: var(--font-mono); font-size: 11px; }
.todo-list { display: flex; flex-direction: column; }
.todo-row {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 12px; align-items: start;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 6px;
}
.todo-row.overdue { border-color: var(--red-line); }
.todo-check { width: 20px; height: 20px; margin-top: 2px; padding: 0; border: 1.5px solid var(--line-strong); border-radius: 50%; background: transparent; cursor: pointer; }
.todo-check:hover { border-color: var(--green); background: var(--green-tint); }
.todo-row.priority-urgent .todo-check { border-color: var(--red); }
.todo-row.priority-high .todo-check { border-color: var(--amber); }
.todo-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.todo-title { color: var(--text); font-weight: 500; }
.todo-title:hover { color: var(--accent-text); }
.todo-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.overdue-text { color: var(--red); }
.todo-actions { opacity: 0; transition: opacity 120ms; }
.todo-row:hover .todo-actions, .todo-row:focus-within .todo-actions { opacity: 1; }
.todo-draft { margin-top: 6px; }
.draft-details > summary { font-size: 12px; color: var(--accent-text); }
.draft-text { margin-top: 8px; padding: 10px 12px; background: var(--panel-subtle); border: 1px solid var(--line); border-radius: var(--radius); font-family: var(--font-sans); font-size: 13px; line-height: 1.55; }
.draft-actions { margin-top: 6px; }
.drafting { font-size: 12px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.source-message { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.source-message header { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.message-body { font-family: var(--font-sans); font-size: 13px; color: var(--text-secondary); }
.attachment-list { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-chip { font-size: 12px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; }

/* ---------- Unsorted ---------- */
.unsorted-row { display: grid; grid-template-columns: 1fr 260px; gap: 20px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 10px; }
.unsorted-main h2 { font-size: 15px; }
.unsorted-excerpt { margin-top: 8px; color: var(--text-secondary); font-size: 13px; }
.router-reason { margin-top: 8px; font-size: 12.5px; color: var(--text-secondary); }
.router-reason .eyebrow { margin-right: 6px; }
.unsorted-actions { display: flex; flex-direction: column; gap: 8px; }
.unsorted-actions .button { justify-content: center; }
.stack-form { gap: 8px; }

/* ---------- Settings ---------- */
.integration-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 14px; }
.integration-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 12px; }
.integration-provider { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.integration-description { color: var(--text-secondary); font-size: 12.5px; margin-top: 4px; }
.connection-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.llm-settings-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; }
.llm-settings-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-secondary); }
.daily-sync-toggle { flex-direction: row !important; align-items: center; }
.llm-settings-note { margin-top: 12px; font-size: 12px; color: var(--muted); }
.deal-overview-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 20px; margin: 0; }
.deal-overview-facts dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--font-mono); }
.deal-overview-facts dd { margin: 2px 0 0; font-size: 13px; }
.table-scroll { overflow-x: auto; margin-top: 12px; }
.llm-spend-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.llm-spend-table th, .llm-spend-table td { text-align: left; padding: 6px 10px 6px 0; border-top: 1px solid var(--line-soft); }
.llm-spend-table th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.context-section { margin-bottom: 26px; }
.token-value { display: block; margin-top: 10px; padding: 10px 12px; background: var(--panel-subtle); border: 1px solid var(--accent-line); border-radius: var(--radius); font-family: var(--font-mono); font-size: 12.5px; word-break: break-all; }
.token-form { margin-top: 14px; }
.token-list { margin-top: 12px; }
.token-list li { display: flex; align-items: center; gap: 10px; }
.token-list li .inline-form { margin-left: auto; }

/* ---------- Auth ---------- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.auth-card .deal-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) { .kanban-board { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) {
  .app-frame { grid-template-columns: 1fr; }
  .app-sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-brand a { padding: 0 8px 0 0; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; gap: 10px; }
  .app-shell { padding: 20px 16px 40px; }
  .kanban-board { grid-template-columns: 1fr 1fr; }
  .deal-layout, .form-grid { grid-template-columns: 1fr; }
  .deal-layout .span-2, .form-grid .span-2 { grid-column: span 1; }
  .todo-add { grid-template-columns: 1fr 1fr; }
  .unsorted-row { grid-template-columns: 1fr; }
  .todo-actions { opacity: 1; }
}
@media (max-width: 600px) {
  .kanban-board { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
}
