:root {
  --bg-base: #12141c;
  --bg-panel: #1a1d29;
  --bg-panel-alt: #20232f;
  --bg-hover: #262a3a;
  --border: #2a2e3f;
  --border-light: #363b52;
  --text-primary: #eae6dd;
  --text-muted: #8b8fa3;
  --text-faint: #565b70;
  --accent: #e8a33d;
  --accent-soft: rgba(232, 163, 61, 0.14);
  --danger: #e2574c;
  --danger-soft: rgba(226, 87, 76, 0.14);
  --success: #4caf7d;
  --success-soft: rgba(76, 175, 125, 0.14);
  --radius: 10px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

/* Light theme override. Toggled via [data-theme="light"] on <html>. */
[data-theme="light"] {
  --bg-base: #f6f4ee;
  --bg-panel: #ffffff;
  --bg-panel-alt: #f1efe6;
  --bg-hover: #e9e6da;
  --border: #ddd8c9;
  --border-light: #cac4b0;
  --text-primary: #262319;
  --text-muted: #6f6a58;
  --text-faint: #a39d88;
  --accent: #c97f1e;
  --accent-soft: rgba(201, 127, 30, 0.12);
  --danger: #b8382c;
  --danger-soft: rgba(184, 56, 44, 0.10);
  --success: #21744e;
  --success-soft: rgba(33, 116, 78, 0.10);
}

[data-theme="light"] .login-screen {
  background:
    radial-gradient(circle at 20% 20%, rgba(201,127,30,0.08), transparent 40%),
    var(--bg-base);
}

[data-theme="light"] .task-card:hover,
[data-theme="light"] .login-card {
  box-shadow: 0 12px 34px rgba(60, 50, 20, 0.08);
}

[data-theme="light"] ::-webkit-scrollbar-thumb { background: #cfc9b7; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #b9b29c; }

/* ---------- Theme toggle ---------- */

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 3px 3px;
  display: inline-flex;
  gap: 2px;
  font-size: 0.72rem;
}
.theme-toggle button {
  background: none;
  border: none;
  color: inherit;
  padding: 3px 9px;
  border-radius: 16px;
  font-size: 0.72rem;
  line-height: 1.4;
}
.theme-toggle button.active {
  background: var(--accent);
  color: #1a1207;
  font-weight: 600;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

#app { height: 100vh; display: flex; flex-direction: column; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #454b68; }

/* ---------- Login ---------- */

.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(232,163,61,0.06), transparent 40%),
    var(--bg-base);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}

.login-mark {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.login-card h1 {
  font-size: 1.5rem;
  margin: 0 0 26px;
  font-weight: 700;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
}
.field input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #1a1207;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.92rem;
  margin-top: 8px;
}
.btn-primary:hover { background: #f0b25a; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.form-error {
  background: var(--danger-soft);
  border: 1px solid rgba(226,87,76,0.35);
  color: #f4b7b1;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* ---------- Shell ---------- */

.app-shell { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.brand span { color: var(--accent); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
}

.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid transparent;
}
.project-item:hover { background: var(--bg-hover); }
.project-item.active { background: var(--bg-panel-alt); border-color: var(--border-light); }

.project-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.project-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.sidebar-footer button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.sidebar-footer button:hover { color: var(--text-primary); }

/* ---------- Board ---------- */

.board-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.board-header {
  padding: 22px 28px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.board-title {
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.board-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
  text-align: center;
  padding: 40px;
}
.empty-state .empty-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.board-columns {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 20px 28px 24px;
  overflow-x: auto;
  align-items: flex-start;
}

.column {
  width: 296px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.column.drag-over { border-color: var(--accent); background: var(--bg-panel-alt); }

.column-header {
  padding: 12px 12px 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.column-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.88rem;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 2px 4px;
  border-radius: 5px;
  min-width: 0;
}
.column-title:hover, .column-title:focus { background: var(--bg-hover); }

.column-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  background: var(--bg-base);
  border-radius: 5px;
  padding: 2px 6px;
  min-width: 22px;
  text-align: center;
}

.column-menu-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 5px;
}
.column-menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.column-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}

.column-footer { padding: 8px 10px 12px; }
.add-task-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border-light);
  color: var(--text-muted);
  padding: 8px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
}
.add-task-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.add-column {
  width: 260px;
  flex-shrink: 0;
}
.add-column-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border-light);
  color: var(--text-muted);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.add-column-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Task card ---------- */

.task-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--card-accent, var(--border-light));
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  transition: transform .08s ease, box-shadow .08s ease;
}
.task-card:hover { border-color: var(--border-light); box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.task-card.dragging { opacity: 0.4; }
.task-card.drag-placeholder {
  border: 1px dashed var(--accent);
  background: var(--accent-soft);
  height: 44px;
}

.task-title {
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 6px;
  word-break: break-word;
}

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

.priority-tag {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.priority-low { background: var(--success-soft); color: var(--success); }
.priority-medium { background: var(--accent-soft); color: var(--accent); }
.priority-high { background: var(--danger-soft); color: var(--danger); }

.due-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-faint);
}
.due-tag.overdue { color: var(--danger); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 18px;
  font-size: 1.1rem;
}

.modal-row { display: flex; gap: 12px; }
.modal-row .field { flex: 1; }

.field textarea {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}
.field textarea:focus, .field select:focus { border-color: var(--accent); }

.field select {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.color-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
}
.color-swatch.selected { border-color: var(--text-primary); }

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 22px;
  gap: 10px;
}

.btn {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
}
.btn:hover { background: var(--bg-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #1a1207; }
.btn-accent:hover { background: #f0b25a; }
.btn-danger { color: var(--danger); border-color: rgba(226,87,76,0.4); }
.btn-danger:hover { background: var(--danger-soft); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.error { border-color: rgba(226,87,76,0.5); color: #f4b7b1; }

/* ---------- Stats ---------- */

.stats-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 28px 0;
}

.stats-toolbar select {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.stats-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 28px 32px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
}
.stat-value.warn { color: var(--danger); }

.stat-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.stats-section {
  margin-bottom: 28px;
}
.stats-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 12px;
  font-weight: 600;
}

.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label {
  width: 110px;
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  flex: 1;
  height: 18px;
  background: var(--bg-panel-alt);
  border-radius: 5px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  min-width: 2px;
}
.bar-value {
  width: 46px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-faint);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.stats-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.stats-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.stats-table tr:last-child td { border-bottom: none; }

.stats-empty {
  color: var(--text-faint);
  font-size: 0.85rem;
  padding: 20px 0;
}

/* ---------- Notebook ---------- */

.notebook-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.notebook-tree, .notebook-pages {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}

.notebook-tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
}

.notebook-book-row, .notebook-chapter-row, .notebook-page-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.86rem;
}
.notebook-book-row:hover, .notebook-chapter-row:hover, .notebook-page-item:hover { background: var(--bg-hover); }
.notebook-book-row.active, .notebook-chapter-row.active, .notebook-page-item.active {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
}

.notebook-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notebook-chapter-list {
  margin: 2px 0 10px 18px;
  border-left: 1px solid var(--border);
  padding-left: 8px;
}
.notebook-chapter-row { font-size: 0.82rem; }

.chapter-linked-badge {
  font-size: 0.7rem;
  color: var(--accent);
}

.notebook-page-item {
  border-left: 3px solid var(--border-light);
  margin-bottom: 4px;
}
.notebook-page-item.status-new { border-left-color: var(--text-faint); }
.notebook-page-item.status-in_progress { border-left-color: #e0b94a; }
.notebook-page-item.status-done { border-left-color: var(--success); }

.notebook-editor {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 22px 30px;
  display: flex;
  flex-direction: column;
}

.notebook-title-input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 700;
  padding: 4px 2px;
  margin-bottom: 12px;
}
.notebook-title-input:focus { outline: none; background: var(--bg-panel-alt); border-radius: 6px; }

.status-pills { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.status-pill {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}
.status-pill.status-new.active { background: var(--bg-panel-alt); color: var(--text-primary); border-color: var(--border-light); }
.status-pill.status-in_progress.active { background: rgba(224,185,74,0.16); color: #e0b94a; border-color: rgba(224,185,74,0.4); }
.status-pill.status-done.active { background: var(--success-soft); color: var(--success); border-color: rgba(76,175,125,0.4); }

.notebook-content-area {
  flex: 1;
  min-height: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 16px;
  font-size: 0.92rem;
  line-height: 1.6;
  resize: vertical;
  font-family: var(--font-body);
}
.notebook-content-area:focus { border-color: var(--accent); }

.notebook-editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
