/* Daily Task Tracker: one stylesheet, token-driven, light + dark. */

:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --surface-3: #e7e6e1;
  --border: rgba(11, 11, 11, 0.1);
  --grid: #e1e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --danger: #d03b3b;
  --danger-ink: #b42c2c;
  --warning: #fab219;
  --inbox: #8a8f98;

  /* Task statuses (validated as a set for the stacked bars). */
  --st-todo: #4a3aa7;
  --st-in_progress: #2a78d6;
  --st-blocked: #d03b3b;
  --st-done: #0ca30c;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.18);
  --topbar-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --surface-3: #2e2e2b;
    --border: rgba(255, 255, 255, 0.1);
    --grid: #2c2c2a;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --accent: #3987e5;
    --accent-soft: #184f95;
    --danger-ink: #e66767;
    --st-todo: #9085e9;
    --st-in_progress: #3987e5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --surface-3: #2e2e2b;
  --border: rgba(255, 255, 255, 0.1);
  --grid: #2c2c2a;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --accent-soft: #184f95;
  --danger-ink: #e66767;
  --st-todo: #9085e9;
  --st-in_progress: #3987e5;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* --- Base ------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.icon { flex: none; vertical-align: -3px; }

.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--inbox));
}
.dot.lg { width: 14px; height: 14px; }

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

/* --- Layout ----------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
}

.nav, .folder-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }

.nav a, .folder-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
}
.nav a:hover, .folder-list a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.is-active, .folder-list a.is-active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.folder-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-list .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 6px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.sidebar-account, .sidebar-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}
.sidebar-account { padding: 12px 4px 0 10px; border-top: 1px solid var(--border); color: var(--text-2); }
.account-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 10px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#page-title { display: flex; align-items: center; gap: 10px; min-width: 0; }

.view-container { flex: 1; overflow-y: auto; padding: 24px 28px 48px; }
.view { display: flex; flex-direction: column; gap: 20px; max-width: 1280px; margin: 0 auto; }
.view-calendar { max-width: none; }

/* --- Cards, buttons, forms -------------------------------------------------------- */

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

.card-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.card-header h2 { flex: 1; }
.count {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.section-title { margin-top: 4px;margin-bottom: 8px; }
.subhead { margin: 18px 0 8px; color: var(--text-2); }
.empty { color: var(--muted); padding: 6px 0; }
.empty-state { text-align: center; padding: 32px; color: var(--text-2); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-ghost { color: var(--danger-ink); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn:disabled { opacity: 0.6; cursor: default; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-width: 0;
}
input, select { height: 34px; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

label.stacked { display: flex; flex-direction: column; gap: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
label.stacked input, label.stacked select, label.stacked textarea { font-size: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.quick-add { display: flex; gap: 8px; padding: 10px; }
.quick-add input[name="title"] { flex: 1; font-size: 15px; border-color: transparent; background: transparent; }
.quick-add input[name="title"]:focus { background: var(--surface); }

/* --- KPI tiles -------------------------------------------------------------------- */

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; }
.kpi-value { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.kpi.is-alert .kpi-label .icon { color: var(--danger); }
.kpi-row.compact { gap: 8px; }
.kpi-row.compact .kpi { box-shadow: none; background: var(--surface-2); border-color: transparent; padding: 10px 12px; }
.kpi-row.compact .kpi-value { font-size: 17px; }

/* --- Task rows -------------------------------------------------------------------- */

.task-list { display: flex; flex-direction: column; }

.task-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 8px 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.task-row::before {
  /* folder color stripe */
  content: "";
  position: absolute;
  left: 4px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: var(--c);
}
.task-row + .task-row { border-top: 1px solid var(--grid); }
.task-row:hover { background: var(--surface-2); }
.task-row:hover + .task-row, .task-row:hover { border-top-color: transparent; }

.check {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  padding: 0;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  color: transparent;
  cursor: pointer;
}
.check .icon { width: 12px; height: 12px; }
.check:hover { border-color: var(--st-done); color: var(--st-done); }
.task-row.is-done .check { background: var(--st-done); border-color: var(--st-done); color: #fff; }

.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-row.is-done .task-title { color: var(--muted); text-decoration: line-through; }
.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
.task-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.task-meta .icon { width: 13px; height: 13px; }
.meta-folder { color: var(--text-2); }
.meta-prio { color: var(--text-2); font-weight: 600; }
.meta-prio .icon { color: var(--danger); }
.meta-late { color: var(--danger-ink); font-weight: 500; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  font-weight: 500;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--st); }

.timer-btn { color: var(--muted); }
.task-row:not(:hover) .timer-btn:not(.is-running) { opacity: 0; }
.task-row:focus-within .timer-btn { opacity: 1 !important; }
.timer-btn.is-running { color: var(--danger); }

.task-row.is-compact { padding: 6px 6px 6px 12px; align-items: center; gap: 8px; }
.task-row.is-compact .check { width: 16px; height: 16px; margin: 0; }
.task-row.is-compact .check .icon { width: 10px; height: 10px; }
.task-row.is-compact .task-title { font-size: 13px; font-weight: 400; }
.task-row.is-compact::before { top: 8px; bottom: 8px; }

/* --- Status colors ----------------------------------------------------------------- */

.st-todo { --st: var(--st-todo); }
.st-in_progress { --st: var(--st-in_progress); }
.st-blocked { --st: var(--st-blocked); }
.st-done { --st: var(--st-done); }

/* Stacked status bar: 2px surface gaps, square at the baseline, 4px round at the end. */
.status-bar {
  display: flex;
  gap: 2px;
  height: 12px;
  margin: 10px 0;
}
.status-bar .seg {
  min-width: 4px;
  background: var(--st);
  cursor: default;
}
.status-bar .seg:last-child { border-radius: 0 4px 4px 0; }
.status-bar .seg:hover, .status-bar .seg:focus-visible { filter: brightness(1.12); outline-offset: 1px; }
.status-bar.is-empty { background: var(--surface-2); border-radius: 0 4px 4px 0; }

.status-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}
.status-legend li { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.status-legend .lg-label { flex: 1; }
.status-legend .lg-count { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.status-legend .lg-pct { width: 36px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.swatch { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 2px; background: var(--st); }

.completion { display: flex; align-items: baseline; gap: 8px; }
.completion-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }

/* --- Overview --------------------------------------------------------------------- */

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-top:20px; }
.stack { display: flex; flex-direction: column; gap: 20px; }

.schedule { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.schedule-item {
  display: grid;
  grid-template-columns: 96px 4px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.schedule-item:hover { background: var(--surface-2); }
.sch-time { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.sch-bar { height: 22px; border-radius: 2px; background: var(--c); }
.sch-bar.kind-planned { background: color-mix(in srgb, var(--c) 35%, var(--surface)); box-shadow: inset 0 0 0 1px var(--c); }
.sch-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sch-duration { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.kind-tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
}
.kind-tag.kind-running { background: var(--danger); color: #fff; }

.days-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.day-card { padding: 12px 12px 8px; }
.day-card-header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.day-card-meta { margin: 2px 0 6px; color: var(--muted); font-size: 12px; }

/* --- Projects & folder ------------------------------------------------------------ */

.page-intro { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.project-card { display: flex; flex-direction: column; gap: 6px; cursor: pointer; border-top: 3px solid var(--c); }
.project-card:hover { border-color: var(--border); border-top-color: var(--c); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.project-header { display: flex; align-items: center; gap: 10px; }
.project-header h3 { flex: 1; font-size: 16px; }
.project-header a { color: var(--text); }
.project-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--text-2); font-size: 12px; }
.project-foot span { display: inline-flex; align-items: center; gap: 5px; }

.folder-header { display: flex; align-items: center; gap: 8px; }
.folder-stats { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1.4fr); gap: 24px; align-items: center; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: -8px; }
.toolbar input[type="search"] { width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.is-active { border-color: var(--text); color: var(--text); font-weight: 600; }
.chip-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.view-folder [data-list] { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow); }
.view-folder [data-list] .empty { padding: 16px 12px; }

/* --- Top bar timer ---------------------------------------------------------------- */

.timer-widget { display: flex; align-items: center; min-width: 0; }
.timer-idle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.timer-running {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  min-width: 0;
}
.timer-task {
  max-width: 260px;
  overflow: hidden;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.timer-elapsed { font-variant-numeric: tabular-nums; font-weight: 600; }
.timer-running .btn { border-radius: 999px; }
.pulse { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--c); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* --- Drawer ----------------------------------------------------------------------- */

.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.28); }
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(480px, 100vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.16s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.drawer-panel:focus { outline: none; }
.drawer-header { display: flex; align-items: flex-start; gap: 10px; padding: 14px 12px 14px 20px; border-bottom: 1px solid var(--border); }
.drawer-heading { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }
.drawer-kicker { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.drawer-title-row { display: flex; align-items: flex-start; gap: 4px; }
.drawer-title { flex: 1; min-width: 0; padding: 3px 0; font-size: 20px; line-height: 1.3; overflow-wrap: anywhere; }
.drawer-title-row .icon-btn { margin-top: 3px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.drawer-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }

.title-input {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  margin-left: -7px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  resize: none;
  overflow: hidden;
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 12px; font-weight: 500; }

.drawer-section { padding-top: 14px; border-top: 1px solid var(--grid); }
.drawer-section h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.time-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.time-summary > div, .summary-totals > div { display: flex; flex-direction: column; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.time-summary .label, .summary-totals .label { color: var(--text-2); font-size: 12px; }
.time-summary strong, .summary-totals strong { font-size: 16px; }

/* Meter: accent fill on a lighter step of the same hue; warning once over estimate. */
.meter { height: 8px; margin-top: 12px; background: var(--accent-soft); border-radius: 0 4px 4px 0; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.meter.is-over { background: color-mix(in srgb, var(--warning) 30%, var(--surface)); }
.meter.is-over span { background: var(--warning); }
.meter-caption { display: flex; align-items: center; gap: 5px; margin-top: 6px; color: var(--text-2); font-size: 12px; }
.meter-caption .icon { color: var(--warning); }

.block-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.block-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.block-item:hover { background: var(--surface-2); }
.block-item .kind-tag { text-align: center; }

.comment-list { margin: 0 0 12px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.comment-list li { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.comment-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; margin: -4px -6px 2px 0; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.comment-form textarea { width: 100%; }

/* --- Dialogs ---------------------------------------------------------------------- */

dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog.confirm { width: min(420px, calc(100vw - 32px)); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 0 20px; }
.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 16px 20px 20px; }
.dialog-footer { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.confirm .dialog-footer { padding: 0 20px 18px; }
.confirm-message { font-size: 15px; }

.segmented { display: inline-flex; padding: 3px; border-radius: 8px; background: var(--surface-2); align-self: flex-start; }
.segmented label { display: flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 6px; color: var(--text-2); font-weight: 500; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.segmented + .hint { margin-top: -8px; }
.appointment-fields { display: flex; flex-direction: column; gap: 14px; }

.repeat-fields, .repeat-details { display: flex; flex-direction: column; gap: 14px; }
.inline-field { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; font-weight: 400; }
.inline-field input { width: 72px; }
.weekday-picker { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.weekday-picker legend { padding: 0; margin-bottom: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
.weekday-picker label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}
.weekday-picker input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-picker label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.weekday-picker label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.series-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
}

.choice-list { display: flex; flex-direction: column; gap: 2px; }
.choice { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.choice:hover { background: var(--surface-2); }
.choice input { margin: 0; height: auto; accent-color: var(--accent); }

.color-field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.color-field legend { padding: 0; margin-bottom: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.swatch-btn.is-selected { box-shadow: 0 0 0 2px var(--text); }
.custom-color { position: relative; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: conic-gradient(#e34948, #eda100, #1baf7a, #2a78d6, #4a3aa7, #e87ba4, #e34948); cursor: pointer; box-shadow: 0 0 0 1px var(--border); }
.custom-color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.color-preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.color-preview .preview-planned, .color-preview .preview-tracked { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; }
.preview-planned { background: color-mix(in srgb, var(--c) 18%, var(--surface)); border: 1px solid var(--c); border-left-width: 3px; color: var(--text); }
.preview-tracked { background: var(--c); color: var(--c-ink); }

/* --- Calendar --------------------------------------------------------------------- */

.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; align-items: start; }
.calendar-main { height: calc(100vh - var(--topbar-h) - 50px); min-height: 560px; padding: 14px; }
.calendar-side { display: flex; flex-direction: column; gap: 16px; }
.calendar-side h3 { margin-bottom: 8px; }
.calendar-side input[type="search"] { width: 100%; margin-bottom: 8px; }

.toggle { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--text); cursor: pointer; }
.toggle input { margin: 0; height: auto; accent-color: var(--accent); }
.legend-swatch { display: inline-block; flex: none; width: 18px; height: 12px; border-radius: 3px; vertical-align: -1px; --c: var(--text-2); }
.legend-swatch.planned { background: color-mix(in srgb, var(--c) 18%, var(--surface)); border: 1px solid var(--c); border-left-width: 3px; }
.legend-swatch.tracked { background: var(--c); }
.legend-swatch.daytask { background: var(--surface); border: 1px solid var(--grid); border-left: 3px solid var(--c); }
.hint .legend-swatch { width: 14px; height: 8px; margin: 0 2px 0 6px; }
.hint .legend-swatch:first-child { margin-left: 0; }

.summary-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.time-bars { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.tb-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 13px; }
.tb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-values { font-weight: 600; font-variant-numeric: tabular-nums; }
.tb-track { height: 6px; margin-top: 2px; }
.tb-bar { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.tb-bar.tracked { background: var(--c); }
.tb-bar.planned { background: color-mix(in srgb, var(--c) 30%, var(--surface)); }

.drag-list { display: flex; flex-direction: column; gap: 4px; max-height: 360px; overflow-y: auto; }
.drag-task {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  grid-template-areas: "grip dot title" "grip . meta";
  align-items: center;
  gap: 0 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--c);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: grab;
  user-select: none;
}
.drag-task:hover { background: var(--surface-2); }
.drag-task .grip { grid-area: grip; color: var(--muted); }
.drag-task .dot { grid-area: dot; }
.drag-task .drag-title { grid-area: title; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.drag-task .drag-meta { grid-area: meta; color: var(--muted); font-size: 12px; }

/* FullCalendar theme */
.fc {
  --fc-border-color: var(--grid);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-neutral-text-color: var(--text-2);
  --fc-today-bg-color: color-mix(in srgb, var(--accent) 7%, transparent);
  --fc-now-indicator-color: var(--danger);
  --fc-highlight-color: color-mix(in srgb, var(--accent) 16%, transparent);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-button-text-color: var(--text);
  --fc-button-bg-color: var(--surface);
  --fc-button-border-color: var(--border);
  --fc-button-hover-bg-color: var(--surface-2);
  --fc-button-hover-border-color: var(--border);
  --fc-button-active-bg-color: var(--surface-3);
  --fc-button-active-border-color: var(--border);
  --fc-event-border-color: transparent;
  --fc-event-bg-color: transparent;
  font-size: 13px;
}
.fc .fc-toolbar-title { font-size: 17px; font-weight: 600; }
.fc .fc-button { font-weight: 500; text-transform: none; box-shadow: none !important; padding: 5px 12px; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: var(--text); font-weight: 600; }
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number { color: var(--text-2); font-weight: 500; }
.fc .fc-timegrid-slot-label-cushion, .fc .fc-timegrid-axis-cushion { color: var(--muted); font-size: 12px; }
.fc .fc-timegrid-slot { height: 2.1em; }
.fc a:hover { text-decoration: none; }

/* Planned: tinted fill in the folder color. Time spent: solid folder color. */
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev { border-radius: 5px; box-shadow: 0 0 0 1px var(--surface); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-planned {
  background: color-mix(in srgb, var(--ev) 18%, var(--surface));
  border-width: 1px 1px 1px 3px;
  border-style: solid;
}
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-planned .fc-event-main { color: var(--text); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-tracked { background: var(--ev); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-tracked .fc-event-main { color: var(--ev-ink); }
.fc :is(.fc-timegrid-event, .fc-daygrid-event).ev-daytask {
  background: var(--surface);
  border-width: 1px 1px 1px 3px;
  border-style: solid;
}
.fc .ev-daytask .fc-event-main { color: var(--text); font-weight: 500; }
.fc .ev-daytask.is-done .fc-event-title { color: var(--muted); text-decoration: line-through; }
.fc .ev-running { animation: pulse 1.6s ease-in-out infinite; }
.fc .fc-event-main { padding: 2px 5px; }
.fc .fc-event-time { font-size: 11px; font-weight: 500; opacity: 0.85; }
.fc .fc-event-title { font-weight: 500; }
.fc .fc-event-mirror { opacity: 0.85; }
.fc .fc-list-event-title { color: var(--text); }

/* --- Tooltip & toast -------------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--text);
  color: var(--surface);
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.tooltip strong { font-size: 13px; }
.tooltip span { opacity: 0.75; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* --- Reports ---------------------------------------------------------------------- */

.range-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
a.btn, a.btn:hover { text-decoration: none; }
.report { display: flex; flex-direction: column; gap: 20px; transition: opacity 0.15s; }
.report.is-loading { opacity: 0.6; }
.report-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.report-grid.is-single { grid-template-columns: minmax(0, 1fr); }

/* Column chart: one series, thin rounded columns on hairline gridlines. */
.bar-chart { --gutter: 44px; padding-top: 8px; }
.bc-plot { position: relative; height: 200px; margin-left: var(--gutter); }
.bc-gridline { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--grid); }
.bc-tick {
  position: absolute;
  right: calc(100% + 8px);
  top: 0;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bc-columns { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.bc-col { display: flex; flex: 1 1 0; align-items: flex-end; justify-content: center; min-width: 0; height: 100%; border-radius: 4px; }
.bc-col:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.bc-col:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.bc-bar { display: block; width: min(24px, calc(100% - 2px)); background: var(--accent); border-radius: 4px 4px 0 0; }
.bc-col:hover .bc-bar, .bc-col:focus-visible .bc-bar { filter: brightness(1.12); }
.bc-axis { display: flex; height: 16px; margin: 6px 0 0 var(--gutter); }
.bc-axis span { display: flex; flex: 1 1 0; justify-content: center; min-width: 0; color: var(--muted); font-size: 11px; white-space: nowrap; }
.chart-table { margin-top: 12px; }
.chart-table summary { color: var(--text-2); font-size: 13px; cursor: pointer; }
.chart-table table { margin-top: 8px; }

.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th { padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--text-2); font-size: 12px; font-weight: 500; text-align: left; }
.report-table td { padding: 8px; border-bottom: 1px solid var(--grid); }
.report-table tr:last-child td { border-bottom: 0; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table tr.is-link { cursor: pointer; }
.report-table tr.is-link:hover td { background: var(--surface-2); }
.rt-name { display: flex; align-items: center; gap: 8px; }

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

.login-page { display: grid; place-items: center; padding: 24px 16px; }
.login { display: flex; flex-direction: column; align-items: center; gap: 18px; width: min(360px, 100%); }
.login-card { display: flex; flex-direction: column; gap: 14px; width: 100%; padding: 24px; }
.login-card .btn { justify-content: center; margin-top: 4px; }
.login-error { color: var(--danger-ink); font-size: 13px; }

/* --- Responsive ------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .calendar-layout { grid-template-columns: 1fr; }
  .overview-grid, .folder-stats { grid-template-columns: 1fr; margin-bottom: 20px; margin-top: 20px; }
  .report-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); gap: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-section, .sidebar-links { display: none; }
  .sidebar-account { padding-top: 10px; }
  .main { height: auto; }
  .view-container { padding: 16px; overflow: visible; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .quick-add { flex-wrap: wrap; }
  .quick-add input[name="title"] { flex-basis: 100%; }
  .field-grid, .grid-2 { grid-template-columns: 1fr; }
  .schedule-item { grid-template-columns: 84px 4px minmax(0, 1fr) auto; }
  .schedule-item .kind-tag { display: none; }
  .calendar-main { height: 640px; }
  .report-table .hide-sm { display: none; }
}
