:root {
  --bg: #f5f7fb;
  --elev: #ffffff;
  --muted: #6b7280;   /* gray-600 */
  --text: #111827;    /* gray-900 */
  --accent: #3b82f6;  /* blue-500 */
  --ok: #059669;      /* green-600 */
  --warn: #d97706;    /* amber-600 */
  --border: #d1d5db;  /* gray-300 */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.brand { font-weight: 700; letter-spacing: 0.3px; }
.logo { display: inline-flex; align-items: center; gap: 6px; }
.logo-mark { color: var(--accent); }
.logo-text { line-height: 1; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.spacer { display: none; }

button, .ghost {
  background: var(--elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
}
button.small { padding: 4px 8px; font-size: 12px; }
button.secondary { background: transparent; }
button:disabled { opacity: 0.6; cursor: not-allowed; }
label.small { font-size: 12px; color: var(--muted); }
.topbar .ghost { background: transparent; }
.topbar .ghost:hover { background: rgba(59,130,246,0.08); border-color: #bfdbfe; }
.topbar .ghost.small, .topbar button { padding: 4px 8px; }
.hide-label { padding: 0 4px; }

main { padding: 12px; }

.auth { display: flex; justify-content: center; padding-top: 10vh; }
.auth-card { max-width: 340px; width: 100%; }
.card {
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.row { display: flex; gap: 8px; margin: 8px 0; }
/* Form controls default styling */
input, select {
  background: #f8fafc;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
/* Full-width only in stacked rows (auth) */
.row input, .row select { width: 100%; }

.super-goals { margin: 12px 0; }
.super-goals-list { display: flex; gap: 8px; flex-wrap: wrap; }
.super-goal {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: #f9fafb;
  font-size: 12px;
}
.super-goal-head { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.super-goal-notes { display: none; margin-top: 6px; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; background: #ffffff; max-width: 520px; }

/* Goals panel */
.goals-panel { margin: 12px 0; background: #faf5ff; border: 1px solid #e9d5ff; border-radius: 12px; padding: 10px; }
.goals-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.goals-add { display: flex; gap: 6px; align-items: center; }
.goals-list { display: grid; gap: 6px; margin-top: 8px; }
.goal-item { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px; background: #ffffff; border: 1px solid var(--border); border-radius: 8px; }
.goal-item-head { display: flex; gap: 6px; align-items: center; }
.goal-title { flex: 1; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }
.goal-notes { background: #f9fafb; border: 1px dashed var(--border); border-radius: 6px; padding: 6px; min-height: 24px; }

/* Goal completion counters under titles */
.goal-counts {
  display: block;
  font-size: 11px;
  margin-top: 2px;
  color: var(--muted);
}
.goal-counts .chip {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
}
.goal-counts .wk {
  background: var(--week-bg);
  border-color: var(--week-br);
  color: var(--accent);
}
.goal-counts .mo {
  background: var(--month-bg);
  border-color: var(--month-br);
  color: var(--warn);
}
.goal-counts .sep { margin: 0 6px; color: var(--muted); }

/* Conditional states for counts */
.goal-counts .chip.red {
  background: var(--today-bg);
  border-color: var(--today-br);
  color: #b91c1c; /* red-700 */
}
.goal-counts .chip.yellow {
  background: var(--month-bg);
  border-color: var(--month-br);
  color: var(--warn);
}
.goal-counts .chip.green {
  background: var(--task-bg);
  border-color: var(--task-br);
  color: var(--ok);
}

.board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.column {
  min-width: 300px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 140px);
}
.col-header {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.col-header h3 { margin: 0; }
.col-header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.col-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-controls { display: flex; gap: 6px; width: 100%; align-items: center; }
.add-title { flex: 1; min-width: 160px; }
.add-title::placeholder { color: var(--muted); }
.add-controls select { width: auto; min-width: 88px; }
.col-body {
  padding: 10px;
  overflow: auto;
}

.item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
}
.item-header { display: flex; gap: 8px; align-items: center; }
.item-title { flex: 1; }
.item-title input[type="text"] { width: 100%; background: transparent; border: none; color: var(--text); }
.item-title .title-edit { width: 100%; background: transparent; border: none; outline: none; color: var(--text); min-height: 1.2em; }
.goal-tag { margin-left: 8px; display: inline-block; background: #f5f3ff; border: 1px solid #e9d5ff; color: #5b21b6; border-radius: 999px; padding: 2px 8px; font-size: 12px; cursor: pointer; }
.goal-tag.none { opacity: 0.6; }
.muted { color: var(--muted); }
.checkbox { width: 16px; height: 16px; }
.priority { font-size: 11px; padding: 2px 6px; border-radius: 6px; border: 1px solid #3a4252; }
.p1 { color: #ff8a7a; border-color: #5a2f2b; }
.p2 { color: #ffc24b; border-color: #5a4b2b; }
.p3 { color: #6ad18a; border-color: #2b5a3a; }

.done .item-title input[type="text"],
.done .item-title .title-edit {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: #9aa3b3;
  color: #9aa3b3;
}

.item-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item-desc { background: #f9fafb; border: 1px dashed var(--border); border-radius: 8px; padding: 6px; min-height: 32px; }
.item-desc a { cursor: pointer; }
.item-desc ul, .item-desc ol { padding-left: 1.2rem; margin: 0 0 0.5em; }
.item-desc li { margin: 0.2em 0; }
.item-desc li p, .item-desc li div { display: inline; margin: 0; }
.toolbar { display: flex; gap: 6px; margin-bottom: 6px; }
.toolbar button { font-size: 12px; padding: 2px 6px; }

.children { margin-left: 16px; border-left: 2px dashed #e2e8f0; padding-left: 10px; }

/* Details & toggles */
.details { display: none; padding-top: 6px; border-top: 1px dashed #283041; }
.details.open { display: block; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 2px 6px; cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.chev { width: 22px; text-align: center; font-size: 14px; }
.icon-btn.plus { width: 22px; text-align: center; font-size: 16px; line-height: 1; }
.archive-btn { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; }
.archive-btn svg { width: 18px; height: 18px; }
.add-sub-wrap { display: inline-flex; gap: 6px; align-items: center; }

/* When an item has children and the list is collapsed, tint the arrow */
.icon-btn.chev.has-children.collapsed {
  color: #1d4ed8;           /* blue-700 */
  border-color: #93c5fd;    /* blue-300 */
  background: #eff6ff;      /* blue-50 */
}

/* Schedule panel */
.schedule-panel { display: none; margin-top: 6px; }
.schedule-panel.open { display: block; }
.chip-btn { background: #eef2ff; border: 1px solid #dbeafe; color: #1e3a8a; border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.chip-btn:hover { background: #dbeafe; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* Drag reorder indicators */
.item.drop-top { box-shadow: inset 0 3px 0 0 var(--accent); }
/* Removed middle drop indicator in revert */
/* .item.drop-middle { box-shadow: inset 0 0 0 2px var(--accent); } */

/* Badges */
.badge {
  display: inline-block;
  background: #eef2ff;
  border: 1px solid #dbeafe;
  color: #1e3a8a;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}
.badge.today { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

/* Priority dots */
.prio { display: flex; align-items: center; gap: 8px; }
.prio .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border); cursor: pointer; opacity: 0.5; transition: transform 0.12s ease, opacity 0.12s ease; }
.prio .dot:hover { transform: scale(1.15); opacity: 0.8; }
.prio .dot.active { transform: scale(1.2); opacity: 1; }
.prio .dot.p1 { background: #ff8a7a; }
.prio .dot.p2 { background: #ffc24b; }
.prio .dot.p3 { background: #6ad18a; }
/* Ensure colors apply for single-dot and popup menu */
.prio-one .dot.p1, .prio-menu .dot.p1 { background: #ff8a7a; }
.prio-one .dot.p2, .prio-menu .dot.p2 { background: #ffc24b; }
.prio-one .dot.p3, .prio-menu .dot.p3 { background: #6ad18a; }

/* Single-dot priority with popup menu */
.prio-one { display: inline-flex; align-items: center; }
.prio-one .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border); cursor: pointer; }
.prio-menu { position: fixed; display: none; background: var(--elev); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px; gap: 8px; z-index: 1000; box-shadow: 0 8px 24px rgba(0,0,0,0.15); }
.prio-menu.open { display: flex; }
.prio-menu .dot { width: 14px; height: 14px; }

/* Goal select menu */
.goal-menu { position: fixed; display: none; background: var(--elev); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px; z-index: 1000; box-shadow: 0 8px 24px rgba(0,0,0,0.15); min-width: 180px; }
.goal-menu.open { display: block; }
.goal-menu .goal-menu-item { display: block; width: 100%; text-align: left; background: transparent; border: none; padding: 6px 8px; cursor: pointer; border-radius: 6px; }
.goal-menu .goal-menu-item:hover { background: #f3f4f6; }

/* Floating formatting menu (appears on right-click selection) */
.fmt-menu {
  position: fixed;
  display: none;
  background: var(--elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 4px;
  z-index: 1000;
}
.fmt-menu.open { display: block; }
.fmt-menu button { margin: 2px; font-size: 12px; padding: 4px 8px; }

.droptarget { min-height: 40px; }
.droptarget.dragover { outline: 2px dashed var(--accent); outline-offset: 4px; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--elev);
  color: var(--text);
}
.list .item { margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; }

.form-note { font-size: 12px; margin: 4px 0; color: var(--muted); }
.form-error { color: #dc2626; font-size: 12px; margin: 4px 0; }

.hidden { display: none; }

@media (max-width: 720px) {
  /* Layout: make columns taller (no nested scroll) */
  .column { min-width: 260px; max-height: none; }
  .col-body { overflow: visible; }

  /* Header: wrap controls and trim non-essentials */
  .top-actions { gap: 6px; flex-wrap: wrap; }
  .top-actions .spacer { display: none; }
  .top-actions label { display: none; } /* hide filter checkboxes on small screens */
  .hide-label { display: none; }

  .brand { font-size: 16px; }
  main { padding: 8px; }
}

/* Theming enhancements */
:root {
  --today-bg: #fff1f2;    /* rose-50 */
  --today-br: #fca5a5;    /* red-300 */
  --week-bg: #eff6ff;     /* blue-50 */
  --week-br: #93c5fd;     /* blue-300 */
  --month-bg: #fffbeb;    /* amber-50 */
  --month-br: #fcd34d;    /* amber-300 */
  --backlog-bg: #f9fafb;  /* gray-50 */
  --backlog-br: #e5e7eb;  /* gray-200 */
  --goal-bg: #f5f3ff;     /* violet-50 */
  --goal-br: #c4b5fd;     /* violet-300 */
  --task-bg: #f0fdf4;     /* green-50 */
  --task-br: #86efac;     /* green-300 */
}

.brand { color: #1e3a8a; }
.add-btn { background: var(--accent); color: #ffffff; border-color: var(--accent); }
.add-btn:hover { filter: brightness(0.95); }
.ghost { background: transparent; }
.ghost:hover { background: rgba(59,130,246,0.08); border-color: #bfdbfe; }

.column { border-width: 2px; }
.column[data-col="today"] { border-color: var(--today-br); }
.column[data-col="today"] .col-header { background: var(--today-bg); border-bottom-color: var(--today-br); }
.column[data-col="week"] { border-color: var(--week-br); }
.column[data-col="week"] .col-header { background: var(--week-bg); border-bottom-color: var(--week-br); }
.column[data-col="month"] { border-color: var(--month-br); }
.column[data-col="month"] .col-header { background: var(--month-bg); border-bottom-color: var(--month-br); }
.column[data-col="backlog"] { border-color: var(--backlog-br); }
.column[data-col="backlog"] .col-header { background: var(--backlog-bg); border-bottom-color: var(--backlog-br); }

.item.goal { border-left: 4px solid var(--goal-br); background: linear-gradient(0deg, var(--goal-bg), #fff); }
.item.task { border-left: 4px solid var(--task-br); background: linear-gradient(0deg, var(--task-bg), #fff); }

.super-goals { background: #f5f3ff; border: 1px solid #e9d5ff; border-radius: 12px; padding: 10px; }
.super-goal { border-color: var(--goal-br); background: var(--goal-bg); }

/* Compact Super Goals header: title inline with chips */
.super-goals {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.super-goals h3 {
  margin: 0;
  margin-right: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.super-goals-list { align-items: center; }

/* Make anchors look clickable inside editable areas */
.goal-notes a,
.super-goal-notes a,
.goal-title a,
.item-title .title-edit a { cursor: pointer; }
