:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-muted: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-focus: #0f766e;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #f0fdfa;
  --accent-border: #ccfbf1;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --panel: #131c2a;
    --panel-muted: #1a2536;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --border-focus: #14b8a6;
    --accent: #14b8a6;
    --accent-hover: #2dd4bf;
    --accent-soft: #042f2e;
    --accent-border: #115e59;
    --success: #4ade80;
    --success-soft: #052e16;
    --warn: #fbbf24;
    --warn-soft: #451a03;
    --danger: #f87171;
    --danger-soft: #450a0a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s ease; }
a:hover { text-decoration: underline; }

header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 56px;
}

nav .brand {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-right: 18px;
  letter-spacing: -0.01em;
}

nav a.nav-link {
  padding: 6px 12px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
}

nav a.nav-link:hover {
  color: var(--text);
  background: var(--panel-muted);
  text-decoration: none;
}

nav a.nav-link.active {
  color: var(--text);
  background: var(--panel-muted);
  font-weight: 600;
}

nav .spacer { flex: 1; }

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--panel-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-right: 8px;
  transition: all 0.15s ease;
}

.search-trigger:hover {
  color: var(--text);
  border-color: var(--accent);
}

.search-trigger kbd {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.75rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

h1 {
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 32px 0 12px;
}

p.sub {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 0.9rem;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }

.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.cols {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.kpi {
  display: flex;
  flex-direction: column;
}

.kpi .label {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.kpi .value {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.kpi .note {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 4px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  background: var(--panel-muted);
  letter-spacing: 0.01em;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0, 0, 0, 0.015); }

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tfoot td {
  font-weight: 600;
  background: var(--panel-muted);
  border-top: 1px solid var(--border);
}

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

dl.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  margin: 0;
  font-size: 0.9rem;
}

dl.facts dt { color: var(--text-muted); }
dl.facts dd { margin: 0; white-space: pre-line; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 500;
  background: var(--panel-muted);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.active, .badge.paid, .badge.ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(21, 128, 61, 0.2);
}

.badge.proposal, .badge.sent, .badge.lead, .badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(180, 83, 9, 0.2);
}

.badge.lost, .badge.void, .badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.2);
}

.badge.credit {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}

/* Insight Cards */
.insights-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: 24px;
}

.insight-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-left: 4px solid var(--accent);
}

.insight-card.opportunity { border-left-color: var(--accent); }
.insight-card.pacing { border-left-color: var(--warn); }
.insight-card.alert { border-left-color: var(--danger); }
.insight-card.success { border-left-color: var(--success); }

.insight-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.insight-title {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.insight-body {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 10px;
}

.insight-action {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
}

/* Charts */
.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.chart-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.chart-wrapper {
  position: relative;
  height: 260px;
  width: 100%;
}

/* Todos list */
.todo { list-style: none; padding: 0; margin: 0; }
.todo li {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  background: var(--panel);
  margin-bottom: 8px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.88rem;
}
.todo li.danger { border-left-color: var(--danger); }
.todo li.warn { border-left-color: var(--warn); }
.todo li.info { border-left-color: var(--accent); }

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tabs a {
  padding: 5px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--panel);
  font-size: 0.85rem;
}
.tabs a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* Forms */
form.stack { display: grid; gap: 16px; max-width: 800px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-weight: normal; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
textarea { min-height: 80px; resize: vertical; }

button, .button {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
button:hover, .button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}
.button.secondary, button.secondary {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}
.button.secondary:hover, button.secondary:hover {
  background: var(--panel-muted);
  border-color: var(--border);
}
button.danger {
  background: var(--panel);
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.3);
}
button.danger:hover {
  background: var(--danger-soft);
}
button.link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0;
  font-size: 0.85rem;
  cursor: pointer;
}
button.link:hover { text-decoration: underline; color: var(--text); }

form.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
form.inline input, form.inline select { width: auto; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: grid;
  gap: 14px;
}
legend {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0 6px;
}

.lines td { padding: 6px; }
.lines input, .lines select { padding: 6px 8px; }

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; }

.pos { color: var(--success); }
.neg { color: var(--danger); }

.callout {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--warn-soft);
  color: var(--text);
  border: 1px solid rgba(180, 83, 9, 0.2);
  margin-bottom: 16px;
  font-size: 0.88rem;
}

.empty {
  color: var(--text-muted);
  padding: 24px;
  text-align: center;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
}

/* Smart receipt dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 24px 20px;
  text-align: center;
  background: var(--panel-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 18px;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 4px;
}
.dropzone-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}
.dropzone-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Command Palette Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 15vh;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  overflow: hidden;
  animation: modal-enter 0.15s ease-out;
}
@keyframes modal-enter {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-input-wrap {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-input {
  border: none;
  font-size: 1rem;
  padding: 0;
  background: transparent;
  color: var(--text);
  outline: none;
}
.modal-input:focus { box-shadow: none; }
.modal-results {
  max-height: 320px;
  overflow-y: auto;
  list-style: none;
  padding: 6px;
  margin: 0;
}
.modal-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.modal-result-item:hover, .modal-result-item.selected {
  background: var(--panel-muted);
  text-decoration: none;
}
.modal-result-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.uptime-strip { display: flex; gap: 2px; height: 28px; }
.uptime-strip span { flex: 1; border-radius: 2px; background: var(--panel-muted); border: 1px solid var(--border); }
.uptime-strip span.ok { background: var(--success); border-color: var(--success); }
.uptime-strip span.warn { background: var(--warn); border-color: var(--warn); }
.uptime-strip span.danger { background: var(--danger); border-color: var(--danger); }
