:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eceff2;
  --border: #dde1e6;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2f6f4f;
  --primary-dark: #234f38;
  --danger: #b3413a;
  --warning: #b8860b;
  --critical: #b3413a;
  --ok: #2f6f4f;
  --tint-critical: #fbe4e1;
  --tint-warning: #fbf0d9;
  --tint-ok: #e3efe8;
  --tint-info: #e6ecf7;
  --tint-info-text: #33538c;
  --badge-bg: #eef0f3;
  --panel-bg: #f8f9fa;
  --overlay: rgba(15, 15, 17, 0.3);
  --on-primary: #ffffff;
  --shadow: 0 1px 3px rgba(20, 20, 25, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* Elegant black, not just an inverted palette: near-black surfaces with a
   restrained step between --bg and --surface, muted greys, one calm accent.
   `data-theme` is always set explicitly by the inline script in base.html's
   <head> (light, dark, or the resolved system preference) before first
   paint — there is no "unset" state to also handle via a media query. */
:root[data-theme="dark"] {
  --bg: #0b0b0c;
  --surface: #141416;
  --surface-2: #1a1a1d;
  --border: #2a2a2d;
  --text: #e9e9eb;
  --muted: #9a9aa3;
  --primary: #4a9b74;
  --primary-dark: #6fc79a;
  --danger: #e0685c;
  --warning: #dba846;
  --critical: #e0685c;
  --ok: #4a9b74;
  --tint-critical: rgba(224, 104, 92, 0.16);
  --tint-warning: rgba(219, 168, 70, 0.16);
  --tint-ok: rgba(74, 155, 116, 0.16);
  --tint-info: rgba(122, 155, 224, 0.18);
  --tint-info-text: #a7c0f7;
  --badge-bg: #1d1d20;
  --panel-bg: #1a1a1d;
  --overlay: rgba(0, 0, 0, 0.6);
  --on-primary: #06110c;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary-dark); }

.muted { color: var(--muted); font-size: 0.9em; }

/* ---------- theme toggle ---------- */

.theme-toggle {
  position: fixed;
  top: 0.8rem;
  right: 1rem;
  z-index: 50;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  box-shadow: var(--shadow);
}
.theme-toggle:hover { border-color: var(--primary); }
/* Inside the topbar the fixed badge would overlap the nav; dock it in flow instead. */
.topbar .theme-toggle { position: static; box-shadow: none; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--primary-dark); }
.topbar-spacer { flex: 1; }
.user-name { color: var(--muted); font-size: 0.9rem; }

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
}
.nav-link:hover { color: var(--text); }

.ai-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.ai-status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--danger);
}
.ai-status.ok .ai-status-dot { background: var(--ok); }
.ai-status-form { display: inline-block; margin-left: 0.4rem; }
.ai-status-form select {
  width: auto;
  margin-top: 0;
  padding: 0.1rem 0.3rem;
  font-size: 0.78rem;
  display: inline-block;
}
.link-button {
  background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; padding: 0;
}
.link-button:hover { color: var(--text); }
.inline-form { display: inline; }

/* ---------- generic ---------- */

main { padding: 1.2rem; }
.page { max-width: 720px; margin: 0 auto; }
.breadcrumb { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.4rem; }

button, input, select, textarea { font: inherit; }

button.primary, button[type="submit"].primary {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
}
button.primary:hover { background: var(--primary-dark); }
button.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
}
button.danger {
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 0.8rem;
}

label { display: block; margin-bottom: 0.6rem; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.error { color: var(--danger); }

/* ---------- auth pages ---------- */

.auth-page { display: flex; justify-content: center; padding-top: 3rem; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 0; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1rem 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.google-button {
  display: block;
  text-align: center;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
}
.google-button:hover { background: var(--surface-2); }

/* ---------- lists (workspaces / boards) ---------- */

.card-list { list-style: none; padding: 0; margin: 1rem 0; }
.card-list-item {
  display: block;
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.card-list-item:hover { border-color: var(--primary); }

details.new-form {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
}
details.new-form form { margin-top: 0.8rem; }

/* ---------- board ---------- */

.board-header { max-width: 100%; }
.board-header-row { display: flex; align-items: center; gap: 1rem; }
.board-header-row h1 { margin: 0.2rem 0; }

.alert-strip { margin: 0.4rem 0 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.pill {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.pill-critical { background: var(--tint-critical); color: var(--critical); }
.pill-warning { background: var(--tint-warning); color: var(--warning); }
.pill-ok { background: var(--tint-ok); color: var(--ok); }

.board-columns {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}

.board-column {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.7rem;
  min-width: 260px;
  max-width: 280px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}

.column-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}
.column-header h2 { font-size: 0.95rem; margin: 0; color: var(--text); }
.column-count { font-size: 0.8rem; color: var(--muted); }
.column-count.wip-breach { color: var(--danger); font-weight: 700; }

.column-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 40px;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  cursor: grab;
}
.task-card.overdue { border-left-color: var(--danger); }
.task-card.priority-urgent { border-left-color: var(--critical); }
.task-card.priority-high { border-left-color: var(--warning); }
.task-card-title { font-size: 0.9rem; margin-bottom: 0.35rem; }
.task-card-meta { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--muted);
  text-transform: uppercase;
}
.badge.ai-badge { background: var(--tint-info); color: var(--tint-info-text); }
.badge.overdue-badge { background: var(--tint-critical); color: var(--danger); }
.sortable-ghost { opacity: 0.4; }

.add-task-form { margin-top: 0.6rem; }
.add-task-form input {
  background: transparent;
  border: 1px dashed var(--border);
  font-size: 0.85rem;
}

/* ---------- drawer ---------- */

.drawer-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 380px; max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.2rem;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.18s ease;
  box-shadow: var(--shadow);
}
.drawer.open { transform: translateX(0); }

.drawer-header { display: flex; justify-content: space-between; align-items: baseline; }
.drawer-header h2 { font-size: 1.05rem; margin: 0; }

.subtasks ul { list-style: none; padding: 0; }
.subtasks li { padding: 0.3rem 0; font-size: 0.9rem; border-bottom: 1px solid var(--border); }
.subtasks li.complete { text-decoration: line-through; color: var(--muted); }

.ai-panel { margin-top: 1.4rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.ai-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.ai-actions button {
  background: var(--surface);
  border: 1px solid var(--primary);
  color: var(--primary-dark);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.spinner { display: none; font-size: 0.8rem; color: var(--muted); }
.htmx-request .spinner, .spinner.htmx-request { display: inline; }

.ai-proposal { margin-top: 0.8rem; background: var(--panel-bg); border-radius: 8px; padding: 0.7rem; }
.proposal-list { list-style: none; padding: 0; }
.proposal-list li { padding: 0.25rem 0; font-size: 0.85rem; }
.ai-unavailable { color: var(--muted); font-style: italic; font-size: 0.85rem; }

.ai-analysis {
  margin: 0.6rem 0 1rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.ai-analysis.health-at_risk { border-color: var(--warning); }
.ai-analysis.health-blocked { border-color: var(--danger); }
.bottleneck { margin: 0.5rem 0; padding-left: 0.6rem; border-left: 3px solid var(--border); }
.bottleneck.severity-critical { border-left-color: var(--critical); }
.bottleneck.severity-warning { border-left-color: var(--warning); }

/* ---------- brainstorm canvas ---------- */

.brainstorm-canvas {
  position: relative;
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 480px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
}

.sticky-note {
  position: absolute;
  width: 200px;
  min-height: 140px;
  padding: 0.7rem;
  border-radius: 4px;
  box-shadow: var(--shadow);
  cursor: grab;
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.sticky-note.dragging { cursor: grabbing; z-index: 1000; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25); }
.sticky-note textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}
.sticky-note textarea:focus { outline: none; }
.sticky-note-toolbar {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.4rem;
  opacity: 0.7;
}
.sticky-note-toolbar button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
  color: inherit;
}
.sticky-note .ai-badge { align-self: flex-start; margin-bottom: 0.3rem; }

.sticky-note.color-yellow { background: #fdf3c7; color: #4a3f10; }
.sticky-note.color-pink { background: #fbdce6; color: #5b2338; }
.sticky-note.color-blue { background: #d9e8fb; color: #1f3a5c; }
.sticky-note.color-green { background: #dcf1e1; color: #1c4a30; }
.sticky-note.color-purple { background: #e8def8; color: #3d2a5c; }

:root[data-theme="dark"] .sticky-note { border-color: rgba(255, 255, 255, 0.08); }
:root[data-theme="dark"] .sticky-note.color-yellow { background: #4a3f10; color: #f3e5a8; }
:root[data-theme="dark"] .sticky-note.color-pink { background: #4a1f2e; color: #f5c9d8; }
:root[data-theme="dark"] .sticky-note.color-blue { background: #17304d; color: #bcd6f5; }
:root[data-theme="dark"] .sticky-note.color-green { background: #143b26; color: #b8e6c6; }
:root[data-theme="dark"] .sticky-note.color-purple { background: #2e2049; color: #d9c9f5; }

.color-picker { display: flex; gap: 0.3rem; }
.color-picker button {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  padding: 0;
}
.color-picker button.color-yellow { background: #fdf3c7; }
.color-picker button.color-pink { background: #fbdce6; }
.color-picker button.color-blue { background: #d9e8fb; }
.color-picker button.color-green { background: #dcf1e1; }
.color-picker button.color-purple { background: #e8def8; }
.color-picker button.selected { outline: 2px solid var(--primary); outline-offset: 1px; }

.brainstorm-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.brainstorm-panel {
  margin-top: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
  box-shadow: var(--shadow);
}
.brainstorm-panel h3 { margin-top: 0; }
.theme-group { margin-bottom: 0.9rem; }
.theme-group h4 { margin: 0 0 0.3rem; font-size: 0.9rem; }
.suggestion-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.suggestion-item button {
  background: var(--surface);
  border: 1px solid var(--primary);
  color: var(--primary-dark);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}
