:root {
  color-scheme: light;
  --green: #17805a;
  --green-dark: #0f6446;
  --green-tint: #e5f5ee;
  --blue: #1560a8;
  --blue-dark: #0e4a82;
  --blue-tint: #e8f1fb;
  --amber: #b5790f;
  --amber-tint: #fbf1de;
  --white: #ffffff;
  --black: #12151a;

  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --border: #dbe0dd;
  --text: #12151a;
  --text-muted: #59635e;
  --accent: var(--green);
  --accent-2: var(--blue);
  --danger: #ad2a20;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(12, 18, 15, 0.04), 0 6px 20px rgba(12, 18, 15, 0.05);
  --focus: 0 0 0 3px rgba(21, 96, 168, 0.3);
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1113;
    --surface: #161a1d;
    --surface-2: #1d2226;
    --border: #2b3136;
    --text: #eef1ef;
    --text-muted: #99a29d;
    --green: #3fc189;
    --green-dark: #29936a;
    --green-tint: #142620;
    --blue: #62a9ef;
    --blue-dark: #3f86d0;
    --blue-tint: #131f2c;
    --amber: #e0ac47;
    --amber-tint: #2a2213;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1113;
  --surface: #161a1d;
  --surface-2: #1d2226;
  --border: #2b3136;
  --text: #eef1ef;
  --text-muted: #99a29d;
  --green: #3fc189;
  --green-dark: #29936a;
  --green-tint: #142620;
  --blue: #62a9ef;
  --blue-dark: #3f86d0;
  --blue-tint: #131f2c;
  --amber: #e0ac47;
  --amber-tint: #2a2213;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16.5px;
  line-height: 1.5;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.01em; }

img { max-width: 100%; }
[hidden] { display: none !important; }

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 14px 24px;
  padding-top: calc(14px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: 4px; }
.brand-mark { font-size: 24px; line-height: 1; }
.brand-text h1 { font-size: 18px; margin: 0; color: var(--text); font-weight: 800; letter-spacing: -0.02em; }
.brand-text p {
  font-size: 11px;
  margin: 1px 0 0;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1 1 320px;
  min-width: 0;
  scrollbar-width: thin;
  border-bottom: 1px solid transparent;
}

.tab-btn {
  flex: 0 0 auto;
  border: none;
  border-bottom: 2.5px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 9px 12px;
  border-radius: 0;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.tab-btn.active {
  background: transparent;
  color: var(--green);
  border-bottom-color: var(--green);
}

.tab-btn .count {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  font-family: var(--font-mono);
  margin-left: 6px;
}
.tab-btn.active .count { color: var(--green); opacity: 0.75; }

.settings-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
}
.settings-btn:hover { border-color: var(--green); color: var(--green); }
.settings-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.settings-label { display: inline; }

/* ---------- Settings panel ---------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 10, 0.5);
  z-index: 29;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(400px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 30;
  overflow-y: auto;
  padding: calc(16px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.2);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.settings-header h2 { margin: 0; font-size: 18px; font-weight: 800; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
}

.settings-section {
  border-top: 1px solid var(--border);
  padding: 14px 0;
}
.settings-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 800;
  font-family: var(--font-mono);
}
.hint { font-size: 13px; color: var(--text-muted); margin: 0 0 8px; line-height: 1.45; }

.theme-toggle { display: flex; gap: 6px; flex-wrap: wrap; }
.theme-opt {
  flex: 1 1 auto;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.theme-opt[aria-checked="true"] {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Compact drag-to-reorder lists */
.reorder-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.reorder-item {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  cursor: grab;
  font-size: 13px;
}
.reorder-item.dragging { opacity: 0.5; }
.reorder-handle { color: var(--text-muted); font-size: 12px; flex: 0 0 auto; }
.reorder-item span:not(.reorder-handle) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.manage-list .reorder-item { padding: 5px 6px 5px 8px; }
.manage-item-name {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 5px;
  border-radius: 4px;
}
.manage-item-name:focus { outline: none; box-shadow: var(--focus); background: var(--surface); }
.manage-item-delete {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}
.manage-item-delete:hover { color: var(--danger); background: rgba(173, 42, 32, 0.1); }

.danger-btn {
  width: 100%;
  background: transparent;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}
.danger-btn:hover { background: rgba(173, 42, 32, 0.08); }

.roadmap-section .roadmap-note {
  background: var(--blue-tint);
  border: 1px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
}

.sync-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--text-muted);
  margin: 0 0 18px;
}

/* ---------- Main / panels ---------- */
main { max-width: 1000px; margin: 0 auto; padding: 24px 18px 64px; }

.panel-head { margin-bottom: 20px; }
.panel-head h2 { font-size: 26px; margin: 0 0 4px; font-weight: 800; letter-spacing: -0.02em; }
.panel-head .sub { color: var(--text-muted); margin: 0; font-size: 14.5px; }

/* ---------- KPI row ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--kpi-accent, var(--green));
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.kpi-value {
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  font-family: var(--font-mono);
  color: var(--text);
}
.kpi-sub { font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }

/* Overview summary cards */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--card-accent, var(--border));
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
}
.summary-card h4 { margin: 0 0 10px; font-size: 14.5px; font-weight: 700; }
.summary-bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-bottom: 8px; }
.summary-bar-fill { height: 100%; background: var(--green); border-radius: 3px; }
.summary-pct { font-size: 12.5px; color: var(--text-muted); font-weight: 600; font-family: var(--font-mono); }

.todo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.todo-textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  resize: vertical;
  min-height: 130px;
}
.todo-textarea:focus { outline: none; box-shadow: var(--focus); border-color: var(--blue); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.timeline-card { margin-bottom: 18px; }
#timelineOutside { padding: 10px 0 0; font-size: 13px; }
.chart-card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.chart-card-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.chart-hint { color: var(--text-muted); font-size: 12px; font-family: var(--font-mono); }
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; }
.chart-wrap svg rect { transition: opacity 0.15s; }
.chart-wrap svg rect:hover { opacity: 0.8; }
.empty-hint { color: var(--text-muted); text-align: center; padding: 20px 0 4px; font-size: 14px; }

/* Section list */
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.task-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 14px;
  transition: border-color 0.15s, background 0.15s;
}
.task-row.complete { border-left-color: var(--green); background: var(--green-tint); }
.task-row.drag-over { border-left-color: var(--blue); }
.task-row.dragging { opacity: 0.5; }

.task-row-top { display: flex; align-items: flex-start; gap: 10px; }

.task-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 14px;
  padding: 6px 2px;
  user-select: none;
  touch-action: none;
  opacity: 0.6;
}
.task-handle:hover { opacity: 1; }

.task-check {
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  border-radius: 6px;
  border: 2.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 17px;
  font-weight: 900;
  margin-top: 1px;
}
.task-check:hover { border-color: var(--green); }
.task-check:focus-visible { outline: none; box-shadow: var(--focus); }
.task-check.checked {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.task-main { flex: 1 1 auto; min-width: 0; }
.task-name { font-size: 16px; font-weight: 700; margin: 0 0 5px; }
.task-row.complete .task-name { color: var(--green-dark); }
.task-status {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: 4px;
  margin-top: 2px;
}
.status-not-started { background: var(--surface-2); color: var(--text-muted); }
.status-in-progress { background: var(--blue-tint); color: var(--blue-dark); }
.status-complete { background: var(--green-tint); color: var(--green-dark); }

.task-toggle-details {
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 7px 2px 0;
}

.task-details { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); display: grid; gap: 10px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  font-family: var(--font-mono);
}
.field textarea, .field input[type="date"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  color: var(--text);
  font-size: 15px;
  resize: vertical;
}
.field textarea:focus, .field input:focus, .task-check:focus, .tab-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--blue);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

footer.app-footer { text-align: center; color: var(--text-muted); font-size: 13px; padding: 10px 0 30px; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar { padding: 10px 14px; padding-top: calc(10px + var(--safe-top)); gap: 10px; }
  .brand-text h1 { font-size: 16px; }
  .settings-label { display: none; }
  .panel-head h2 { font-size: 22px; }
  .kpi-value { font-size: 1.9rem; }
}
