/* ============ Theme tokens ============ */
:root,
[data-theme="light"] {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-raised: #fcfbf9;
  --text: #1e2124;
  --text-dim: #63666b;
  --text-faint: #9a9d9f;
  --border: #e3e1dc;
  --border-strong: #cfccc4;
  --accent: #3f7d6e;
  --accent-text: #ffffff;
  --accent-dim: #e5f0ec;
  --danger: #c1443c;
  --danger-dim: #fbe9e7;

  --cat-bug: #c1443c;
  --cat-bug-dim: #fbe9e7;
  --cat-feature: #2f8f6c;
  --cat-feature-dim: #e6f3ee;
  --cat-ui: #8b5fbf;
  --cat-ui-dim: #f1eaf9;
  --cat-idea: #c98a2c;
  --cat-idea-dim: #fbf1e0;
  --status-hold: #6b7280;
  --status-hold-dim: #eceef0;

  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04);
  --shadow-lg: 0 8px 24px rgba(20, 20, 20, 0.10);
}

[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1d2024;
  --surface-raised: #23262b;
  --text: #e7e5e0;
  --text-dim: #a4a7ab;
  --text-faint: #6d7176;
  --border: #2c3034;
  --border-strong: #3a3e43;
  --accent: #5eb39f;
  --accent-text: #0d1a17;
  --accent-dim: #1f332e;
  --danger: #e2665c;
  --danger-dim: #3a2320;

  --cat-bug: #e2665c;
  --cat-bug-dim: #3a2320;
  --cat-feature: #4cb98c;
  --cat-feature-dim: #1d3129;
  --cat-ui: #a98ae0;
  --cat-ui-dim: #2b2338;
  --cat-idea: #d9a34a;
  --cat-idea-dim: #3a2e17;
  --status-hold: #9aa1ab;
  --status-hold-dim: #2a2d31;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }
h1, h2, h3, .display {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
a { color: inherit; }
button { font-family: inherit; color: var(--text); }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============ App shell ============ */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

/* ---- Sidebar (spine) ---- */
.spine {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.spine-header {
  padding: 18px 16px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.spine-title { font-size: 18px; }
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  color: var(--text-dim);
}
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text); }

.spine-search {
  padding: 0 12px 12px;
}
.spine-search input { width: 100%; }

.spine-section-label {
  padding: 10px 16px 4px;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.03em;
}
.spine-section-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 12px;
}
.fav-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10.5px;
  padding: 2px 8px;
  color: var(--text-faint);
}
.fav-toggle:hover { border-color: var(--border-strong); color: var(--text); }
.fav-toggle.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.spine-group { display: flex; flex-direction: column; }
.spine-subsection-label {
  padding: 8px 16px 2px;
  font-size: 10.5px;
  color: var(--text-faint);
  font-style: italic;
}
.spine-empty-note {
  padding: 6px 16px 10px;
  font-size: 11.5px;
  color: var(--text-faint);
}
.project-row { cursor: pointer; }
.star-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 13px;
  padding: 0 2px;
  flex-shrink: 0;
}
.star-btn:hover { color: var(--text); }
.star-btn.active { color: #c98a2c; }
.spine-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spine-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-left: 3px solid transparent;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spine-item:hover { background: var(--surface-raised); color: var(--text); }
.spine-item.active {
  border-left-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text);
  font-weight: 500;
}
.spine-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-faint);
}
.spine-count {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.spine-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.spine-footer button {
  background: none; border: none; color: var(--text-dim); font-size: 12px; text-decoration: underline;
  padding: 0;
}
.spine-version {
  padding: 4px 16px 12px;
  font-size: 10px;
  color: var(--text-faint);
  text-align: center;
}

/* ---- Main column ---- */
.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}
.quickadd-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.quickadd-bar input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.quickadd-bar button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
}
.quickadd-bar button:disabled { opacity: 0.5; cursor: default; }

.main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 80px;
}

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.sticky-project-bar {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -24px 12px;
  padding: 12px 24px;
  font-weight: 600;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.view-header h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; }
.project-color-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.view-subtitle { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

.stat-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.stat-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--surface-raised);
  margin: 0;
  min-width: 0;
}
.stat-group legend {
  font-size: 10px;
  color: var(--text-faint);
  padding: 0 5px;
  letter-spacing: 0.03em;
}
.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  min-width: 84px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.stat-chip:hover { border-color: var(--border-strong); }
.stat-chip.active { border-color: var(--accent); background: var(--accent-dim); }
.stat-chip .num { font-family: 'Source Serif 4', serif; font-size: 20px; font-weight: 600; display: block; color: var(--text); }
.stat-chip .label { font-size: 11px; color: var(--text-faint); }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.toolbar select, .toolbar input[type="text"] {
  font-size: 12.5px;
  padding: 6px 8px;
}
.toolbar .spacer { flex: 1; }
.not-done-toggle {
  background: none;
  border: 1.5px solid var(--border-strong);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  color: var(--text);
}
.not-done-toggle:hover { border-color: var(--accent); color: var(--accent); }
.not-done-toggle.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.clearable-input { position: relative; display: inline-flex; align-items: center; }
.clearable-input input { padding-right: 22px; }
.clearable-input .clear-btn {
  position: absolute; right: 4px;
  background: none; border: none;
  color: var(--text-faint); font-size: 13px; line-height: 1;
  padding: 2px 4px;
}
.clearable-input .clear-btn:hover { color: var(--danger); }
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
}
.btn:hover { border-color: var(--border-strong); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--danger-dim); }

/* ---- Item rows ---- */
.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-faint);
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
}
.item-row:hover { border-color: var(--border-strong); border-left-color: inherit; }
.item-row.cat-bug { border-left-color: var(--cat-bug); }
.item-row.cat-feature { border-left-color: var(--cat-feature); }
.item-row.cat-ui { border-left-color: var(--cat-ui); }
.item-row.cat-idea { border-left-color: var(--cat-idea); }

.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 500; font-size: 14px; }
.item-name.untitled { color: var(--text-faint); font-style: italic; font-weight: 400; }
.item-meta { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.pill {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--text-dim);
  background: var(--surface-raised);
  border: 1px solid var(--border);
}
.pill.status-in_progress { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.pill.status-done { color: var(--cat-feature); border-color: var(--cat-feature); background: var(--cat-feature-dim); }
.pill.tag { color: var(--text-faint); }
.tag-input-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px;
  background: var(--surface);
}
.tag-input-box:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.tag-input-field {
  flex: 1; min-width: 100px;
  border: none; background: transparent; padding: 2px 0;
  outline: none;
}
.tag-chip { display: inline-flex; align-items: center; gap: 4px; padding-right: 4px; }
.tag-remove {
  background: none; border: none; padding: 0 2px;
  color: var(--text-faint); font-size: 13px; line-height: 1;
}
.tag-remove:hover { color: var(--danger); }
.tag-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-suggestion { cursor: pointer; border: 1px solid var(--border); }
.tag-suggestion:hover { border-color: var(--border-strong); color: var(--text); }
.tag-suggestion.selected { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.link-btn {
  background: none; border: none; padding: 0;
  color: var(--text-dim); font-size: 11.5px; text-decoration: underline;
}
.link-btn:hover { color: var(--accent); }
.tag-count-link {
  cursor: pointer;
  color: var(--text-dim);
}
.tag-count-link:hover { color: var(--accent); border-color: var(--accent); }
.item-projects { font-size: 11.5px; color: var(--text-faint); flex-shrink: 0; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-select {
  flex-shrink: 0;
  font-size: 11.5px;
  padding: 4px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-dim);
}
.status-select.status-backlog { color: var(--text-dim); }
.status-select.status-in_progress { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.status-select.status-on_hold { color: var(--status-hold); border-color: var(--status-hold); background: var(--status-hold-dim); }
.status-select.status-done { color: var(--cat-feature); border-color: var(--cat-feature); background: var(--cat-feature-dim); }
.status-select.status-needs_work { color: var(--cat-idea); border-color: var(--cat-idea); background: var(--cat-idea-dim); }
.pill.status-needs_work { color: var(--cat-idea); border-color: var(--cat-idea); background: var(--cat-idea-dim); }

.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state h3 { font-size: 15px; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 13px; margin: 0; }

.add-item-footer {
  width: 100%;
  margin-top: 10px;
  text-align: center;
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 10, 12, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.project-screenshot-thumb {
  display: block;
  max-width: 180px;
  max-height: 100px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.lightbox-img {
  max-width: 95vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  cursor: default;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  padding: 22px;
}
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.modal-header-row h2 { margin-bottom: 0; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 5px;
  font-weight: 500;
}
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 70px; }
.name-textarea {
  resize: none;
  overflow: hidden;
  min-height: unset;
  line-height: 1.4;
  font-family: inherit;
  font-size: 14px;
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.checkbox-grid {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 160px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox-row input { width: auto; }
.pill-radio-group { display: flex; flex-wrap: wrap; gap: 6px; }
.pill-radio {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
}
.pill-radio:hover { border-color: var(--border-strong); color: var(--text); }
.pill-radio.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.modal-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px; gap: 8px;
}
.modal-actions .right { display: flex; gap: 8px; }

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

.attachment-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 160px; overflow-y: auto;
}
.attachment-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
}
.attachment-name {
  flex: 1; cursor: pointer; text-decoration: underline;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attachment-name:hover { color: var(--accent); }
.attachment-size { color: var(--text-faint); font-size: 11.5px; flex-shrink: 0; }

/* ---- Auth screen ---- */
.auth-screen {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 34px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .view-subtitle { margin-bottom: 22px; }
.auth-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-faint); font-size: 12px;
  margin: 18px 0;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.google-btn {
  width: 100%; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-weight: 600; font-size: 13.5px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.auth-error { color: var(--danger); font-size: 12.5px; margin-top: 8px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-width: 90vw;
}

/* ---- Mobile / drawer ---- */
.mobile-topbar { display: none; }
.drawer-scrim { display: none; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .spine {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 40;
  }
  .spine.open { transform: translateX(0); }
  .drawer-scrim {
    display: block;
    position: fixed; inset: 0; background: rgba(0,0,0,0.35);
    z-index: 39;
  }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .mobile-topbar button.menu-btn {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    width: 34px; height: 34px; font-size: 16px;
  }
  .main-scroll { padding: 0 16px 90px; }
  .view-header { margin-top: 16px; }
  .sticky-project-bar { margin: 0 -16px 12px; padding: 10px 16px; }
  .quickadd-bar { padding: 12px 16px; }
  .item-projects { display: none; }
  .modal { max-width: 100%; }
}
