:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e0e2e7;
  --text: #1b1d22;
  --text-dim: #6b7080;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --fire: #e0392f;
  --money: #d97c1f;
  --career: #c9a300;
  --hustle: #2f9e44;
  --build: #1f6fd6;
  --horizon: #868e96;
  --danger: #e0392f;
  --shadow: 0 1px 2px rgba(20, 22, 30, 0.06), 0 1px 8px rgba(20, 22, 30, 0.04);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #14151a;
  --surface: #1c1e24;
  --surface-2: #22242b;
  --border: #2c2f38;
  --text: #edeef2;
  --text-dim: #9a9fae;
  --accent: #7c93ff;
  --accent-text: #10111a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

.app { max-width: 1100px; margin: 0 auto; padding: 20px 20px 60px; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar h1 { font-size: 20px; margin: 0; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 20px; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px;
  cursor: pointer; text-align: left; font-family: inherit; width: 100%;
}
.stat-tile:hover { border-color: var(--accent); }
.stat-tile.active-filter { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -1px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-tile[data-tone="fire"] .stat-value { color: var(--fire); }
.stat-tile[data-tone="money"] .stat-value { color: var(--money); }
.stat-tile[data-tone="warn"] .stat-value { color: var(--danger); }
.stat-tile[data-tone="neutral"] .stat-value { color: var(--text-dim); }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none; border: none; padding: 10px 14px; font-size: 14px; font-weight: 600;
  color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; }
.checkbox-inline { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 13px; }

input, select, textarea, button {
  font-family: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.primary-btn { background: var(--accent); color: var(--accent-text); border: none; font-weight: 600; cursor: pointer; }
.primary-btn:hover { opacity: 0.9; }
.ghost-btn { background: transparent; cursor: pointer; }
.ghost-btn:hover { background: var(--surface-2); }
.danger-link { color: var(--danger); background: none; border: none; cursor: pointer; font-size: 12px; }

.add-form {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 8px; box-shadow: var(--shadow);
}
.add-form input, .add-form select { flex: 1 1 160px; }
.add-form textarea { flex: 1 1 100%; }
.form-actions { flex: 1 1 100%; display: flex; gap: 8px; justify-content: flex-end; }
.hidden { display: none !important; }

.priority-group { margin-bottom: 22px; }
.priority-group h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim);
  margin: 0 0 8px 2px; display: flex; align-items: center; gap: 8px;
}
.priority-group h2 .count { background: var(--surface-2); border-radius: 10px; padding: 1px 8px; font-size: 11px; }

.task-row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto auto auto 28px;
  align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; box-shadow: var(--shadow);
}
.task-row.done { opacity: 0.55; }
.task-row.overdue { border-color: var(--fire); }
.task-main { min-width: 0; }
.task-title { font-weight: 600; word-break: break-word; }
.task-title.done { text-decoration: line-through; }
.task-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.task-notes-toggle { cursor: pointer; text-decoration: underline dotted; }
.task-notes { color: var(--text-dim); font-size: 12px; margin-top: 6px; white-space: pre-wrap; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--surface-2); white-space: nowrap;
}

.task-row select { font-size: 12px; padding: 5px 6px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; min-width: 900px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tr.bill-row td { border-bottom: none; }
tr.bill-notes-row td.notes-cell {
  white-space: normal; color: var(--text-dim); font-size: 12px;
  padding-top: 0; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
tfoot td { font-weight: 700; border-bottom: none; border-top: 2px solid var(--border); }
tr.due-soon td { background: color-mix(in srgb, var(--fire) 8%, transparent); }

.notes-list { display: grid; gap: 8px; }
.note-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow);
}
.note-card:hover { border-color: var(--accent); }
.note-card h3 { margin: 0 0 4px; font-size: 14px; }
.note-card p { margin: 0; color: var(--text-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.modal {
  position: fixed; inset: 0; background: rgba(10, 10, 14, 0.5);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 20;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; max-width: 720px; width: 100%; max-height: 85vh; overflow-y: auto; position: relative;
}
.modal-close { position: absolute; top: 12px; right: 12px; }
.note-source-link { font-size: 12px; color: var(--accent); }
.note-body { white-space: pre-wrap; font-family: inherit; font-size: 13px; margin-top: 14px; }

.digest-section { margin-bottom: 22px; }
.digest-section h2 { font-size: 15px; margin: 0 0 10px; }
.digest-body { display: grid; gap: 8px; }
.digest-empty { color: var(--text-dim); font-size: 13px; }
.digest-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow);
}
.digest-card-title { font-weight: 600; margin-bottom: 4px; }
.digest-card-meta { color: var(--text-dim); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.digest-project-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow);
}
.digest-project-row.stalled { opacity: 0.6; border-style: dashed; }
.digest-project-row.clickable { cursor: pointer; }
.digest-project-row.clickable:hover { border-color: var(--accent); }
.digest-project-name { font-weight: 600; }
.digest-project-next { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.digest-counts { display: flex; gap: 6px; }

.digest-task-link { cursor: pointer; padding: 2px 4px; margin: -2px -4px; border-radius: 6px; }
.digest-task-link:hover { background: var(--surface-2); color: var(--text); }

@keyframes flash-highlight-anim {
  0%, 100% { box-shadow: none; }
  25%, 75% { box-shadow: 0 0 0 2px var(--accent); }
}
.task-row.flash-highlight { animation: flash-highlight-anim 2s ease-in-out; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .task-row { grid-template-columns: 20px 1fr; grid-auto-rows: auto; }
  .task-row select, .task-row .task-controls { grid-column: 1 / -1; }
}
