/* ==========================================================================
   Work Log — application styles
   ========================================================================== */

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
ul, ol { list-style: none; }
a { color: inherit; text-decoration: none; }

/* `hidden` must win over component rules that set an explicit display
   (.field, .sidebar__section, .sched-panel all use display:flex). */
[hidden] { display: none !important; }

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- App shell ------------------------------------------------------------ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* --- Sidebar -------------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  padding: var(--sp-5) var(--sp-4);
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); }

.brand__mark {
  width: 30px; height: 30px;
  flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--color-teal);
  color: var(--on-accent);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand__name { font-size: var(--text-md); font-weight: 650; letter-spacing: -0.01em; }
.brand__sub { font-size: var(--text-xs); color: var(--ink-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav__label {
  padding: 0 var(--sp-2) var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.nav__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 7px var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--text-base);
  color: var(--ink-2);
  text-align: left;
  transition: background .12s ease, color .12s ease;
}
.nav__item:hover { background: var(--surface-hover); color: var(--ink); }
.nav__item[aria-current="page"] {
  background: var(--color-teal-pale);
  color: var(--color-teal-deep);
  font-weight: 600;
}
.nav__item svg { flex: none; opacity: .85; }
.nav__count { margin-left: auto; font-size: var(--text-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }

.sidebar__section { display: flex; flex-direction: column; gap: var(--sp-1); }

.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-2); }

.sidebar__hint {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  font-size: var(--text-xs);
  color: var(--ink-3);
}
.sidebar__hint > div { display: flex; align-items: center; gap: var(--sp-2); }
.sidebar__hint dt { flex: none; width: 20px; }
.sidebar__hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-2);
}

/* --- Project rail (sidebar) ---------------------------------------------- */
.rail__item {
  display: flex; align-items: center; gap: var(--sp-2);
  width: 100%; padding: 6px var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--text-base); color: var(--ink-2); text-align: left;
}
.rail__item:hover { background: var(--surface-hover); color: var(--ink); }
.rail__item[aria-current="page"] { background: var(--surface-hover); color: var(--ink); font-weight: 600; }
.rail__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail__count { margin-left: auto; font-size: var(--text-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }

.dot {
  width: 9px; height: 9px; flex: none;
  border-radius: var(--r-pill);
  background: var(--dot, var(--color-teal));
}

/* --- Notes rail (sidebar) ------------------------------------------------- */
/* Structural teal only. Mustard and coral stay reserved for status and
   priority — a note has neither. */
.notes-rail__head { display: flex; align-items: center; gap: var(--sp-2); }
.notes-rail__head .nav__label { flex: 1; }
.notes-rail__new {
  width: 22px; height: 22px; flex: none;
  font-size: var(--text-md); line-height: 1; color: var(--ink-3);
}
.notes-rail__new:hover { color: var(--color-teal-deep); background: var(--surface-hover); }

.notes-rail__input {
  width: 100%;
  padding: 6px var(--sp-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: transparent;
  font-size: var(--text-sm);
  color: var(--ink);
}
.notes-rail__input::placeholder { color: var(--ink-3); }
.notes-rail__input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--color-teal-light);
  background: var(--surface);
  box-shadow: var(--ring);
}

/* One line per note, whatever its length. */
.note-line {
  display: block;
  width: 100%;
  padding: 5px var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--ink-2);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-line:hover { background: var(--surface-hover); color: var(--ink); }

.notes-rail__empty { padding: 0 var(--sp-2); font-size: var(--text-xs); color: var(--ink-3); }

.notes-rail__all {
  align-self: flex-start;
  padding: 4px var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-teal-deep);
}
.notes-rail__all:hover { background: var(--surface-hover); }

/* --- Notes view ----------------------------------------------------------- */
.notes-list { display: flex; flex-direction: column; gap: var(--sp-3); max-width: 760px; }

.note {
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.note__title { font-size: var(--text-md); font-weight: 640; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.note__text {
  margin-top: 5px;
  font-size: var(--text-base);
  color: var(--ink-2);
  white-space: pre-wrap;        /* the note's own line breaks are the format */
  overflow-wrap: anywhere;
}
.note__foot {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line);
}
.note__meta { font-size: var(--text-xs); color: var(--ink-3); }
.note__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-left: auto; }
/* Coral for the destructive action only — same rule as everywhere else. */
.note__actions .btn--icon.is-danger { color: var(--ink-3); }
.note__actions .btn--icon.is-danger:hover { color: var(--color-coral-deep); background: var(--color-coral-pale); }

/* --- Topbar --------------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--sp-4);
  height: var(--topbar-h);
  padding: 0 var(--sp-8);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar__title { font-size: var(--text-lg); font-weight: 650; letter-spacing: -0.015em; }
.topbar__meta { font-size: var(--text-sm); color: var(--ink-3); }
.topbar__spacer { flex: 1; }

/* Light / dark switch. The knob slides right for dark; the icon on the
   active side takes the teal, and aria-label + title name the control. */
.theme-switch {
  flex: none;
  position: relative;
  display: inline-flex; align-items: center; justify-content: space-between;
  width: 58px; height: 30px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-3);
}
.theme-switch:hover { border-color: var(--color-teal-light); }
.theme-switch:focus-visible { border-radius: var(--r-pill); }
.theme-switch svg { position: relative; z-index: 1; transition: color .15s ease; }
.theme-switch__knob {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: var(--r-pill);
  background: var(--color-teal-pale);
  border: 1px solid var(--color-teal-light);
  transition: transform .2s cubic-bezier(.2, .8, .3, 1);
}
.theme-switch[aria-checked="false"] .theme-switch__sun,
.theme-switch[aria-checked="true"] .theme-switch__moon { color: var(--color-teal-deep); }
.theme-switch[aria-checked="true"] .theme-switch__knob { transform: translateX(28px); }

.search {
  position: relative;
  display: flex; align-items: center;
  width: 236px;
}
.search svg { position: absolute; left: 10px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%;
  padding: 7px var(--sp-3) 7px 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--text-base);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: none; border-color: var(--color-teal-light); box-shadow: var(--ring); }

.view { padding: var(--sp-6) var(--sp-8) var(--sp-10); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--text-base);
  font-weight: 550;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { background: var(--surface-hover); color: var(--ink); border-color: var(--line-strong); }
.btn:active { transform: translateY(0.5px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn--primary {
  background: var(--color-teal);
  border-color: var(--color-teal);
  color: var(--on-accent);
}
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-accent); }
.btn--primary:active { background: var(--color-teal-press); }

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-hover); }

.btn--danger { color: var(--color-coral-deep); border-color: var(--color-coral-light); background: var(--color-coral-pale); }
.btn--danger:hover { background: var(--color-coral); border-color: var(--color-coral); color: var(--on-accent); }

.btn--icon { padding: 6px; width: 30px; height: 30px; }
.btn--sm { padding: 4px var(--sp-2); font-size: var(--text-sm); }

/* --- Segmented control ---------------------------------------------------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.segmented button {
  padding: 5px var(--sp-3);
  border-radius: 6px;
  font-size: var(--text-base);
  font-weight: 550;
  color: var(--ink-2);
  transition: background .12s ease, color .12s ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-selected="true"] {
  background: var(--color-teal-pale);
  color: var(--color-teal-deep);
}

/* --- Toolbar -------------------------------------------------------------- */
.toolbar {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.toolbar__spacer { flex: 1; }

.range-nav { display: inline-flex; align-items: center; gap: var(--sp-2); }
.range-nav__label {
  margin-right: var(--sp-2);
  text-align: right;
  font-size: var(--text-md);
  font-weight: 620;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.range-nav__label span { display: block; font-size: var(--text-xs); font-weight: 400; color: var(--ink-3); letter-spacing: 0; }

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
}
.card__title { font-size: var(--text-md); font-weight: 620; letter-spacing: -0.01em; }
.card__body { padding: var(--sp-4) var(--sp-5); }

.section-title {
  display: flex; align-items: center; gap: var(--sp-2);
  margin: 0 0 var(--sp-3);
  font-size: var(--text-sm);
  font-weight: 620;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.section-title__hint { font-weight: 400; text-transform: none; letter-spacing: 0; }

/* --- Stat tiles ----------------------------------------------------------- */
/* A plain text strip, not cards — the numbers read as one line across the
   top instead of five boxes competing with the task list below. */
.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-2) var(--sp-5);
  margin-bottom: var(--sp-5);
}

.stat { display: flex; align-items: baseline; gap: 6px; }
/* In the dashboard toolbar the strip sits inline with the controls. It must
   stay shrinkable — `flex: none` here sizes it to max-content, which on a
   narrow screen drags the whole page sideways. */
.toolbar .stats {
  margin-bottom: 0;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: var(--sp-2) var(--sp-6);
  margin-left: var(--sp-2);
}

/* Wide only: one unbroken left-aligned line, the spacer pushing the date
   nav right. Below this the strip wraps instead of overflowing. */
@media (min-width: 861px) {
  .toolbar .stats { flex: none; flex-wrap: nowrap; }
}
.toolbar .stat { white-space: nowrap; }
.stat__label {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.stat__value {
  font-size: var(--text-lg);
  font-weight: 640;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat__foot { font-size: var(--text-xs); color: var(--ink-3); }

/* A dot per status — the one place the full-strength colour is readable,
   and it matches the chips used on task rows. Always beside its label. */
.stat--todo .stat__label::before,
.stat--progress .stat__label::before,
.stat--done .stat__label::before {
  content: "";
  width: 8px; height: 8px; flex: none;
  border-radius: var(--r-pill);
}
.stat--todo .stat__label::before     { background: var(--status-todo-dot); }
.stat--progress .stat__label::before { background: var(--status-progress-dot); }
.stat--done .stat__label::before     { background: var(--status-done-dot); }

.stat--todo .stat__value { color: var(--status-todo-fg); }
.stat--progress .stat__value { color: var(--status-progress-fg); }
.stat--done .stat__value { color: var(--status-done-fg); }
/* Completion is progress, not a status — it keeps the structural teal. */
.stat--accent .stat__value { color: var(--color-teal-deep); }
.stat--overdue .stat__value,
.stat--overdue .stat__label { color: var(--overdue-fg); }

/* --- Meter (progress bar) ------------------------------------------------- */
.meter {
  position: relative;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--color-teal);
  transition: width .3s cubic-bezier(.4, 0, .2, 1);
}
.meter__fill--progress { background: var(--color-mustard); }

.meter-row { display: flex; align-items: center; gap: var(--sp-3); }
.meter-row .meter { flex: 1; }
.meter-row__value {
  font-size: var(--text-sm);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  color: var(--color-teal-deep);
  min-width: 34px;
  text-align: right;
}

/* Stacked completion bar with a 2px surface gap between segments */
.stackbar { display: flex; gap: 2px; height: 8px; }
.stackbar__seg { border-radius: 2px; min-width: 0; }
.stackbar__seg:first-child { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.stackbar__seg:last-child { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.stackbar__seg--todo { background: var(--status-todo-line); }
.stackbar__seg--progress { background: var(--status-progress-dot); }
.stackbar__seg--done { background: var(--status-done-dot); }
.stackbar--empty { background: var(--surface-sunken); border: 1px solid var(--line); border-radius: 4px; }

.legend {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--sp-1) var(--sp-4);
  font-size: var(--text-xs);
  color: var(--ink-2);
}
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.legend__swatch--todo { background: var(--status-todo-line); }
.legend__swatch--progress { background: var(--status-progress-dot); }
.legend__swatch--done { background: var(--status-done-dot); }

/* --- Chips ---------------------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface-sunken);
  font-size: var(--text-xs);
  font-weight: 550;
  color: var(--ink-2);
  white-space: nowrap;
  line-height: 1.7;
}
.chip__dot { width: 6px; height: 6px; border-radius: var(--r-pill); flex: none; }

.chip--status-todo { background: var(--status-todo-bg); border-color: var(--status-todo-line); color: var(--status-todo-fg); }
.chip--status-todo .chip__dot { background: var(--status-todo-dot); }
.chip--status-in-progress { background: var(--status-progress-bg); border-color: var(--status-progress-line); color: var(--status-progress-fg); }
.chip--status-in-progress .chip__dot { background: var(--status-progress-dot); }
.chip--status-done { background: var(--status-done-bg); border-color: var(--status-done-line); color: var(--status-done-fg); }
.chip--status-done .chip__dot { background: var(--status-done-dot); }

.chip--tag { background: var(--surface); color: var(--ink-3); font-weight: 500; }
.chip--overdue { background: var(--overdue-bg); border-color: var(--overdue-line); color: var(--overdue-fg); }

.priority {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.priority__bars { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 10px; }
.priority__bars i { width: 3px; border-radius: 1px; background: var(--line-strong); }
.priority__bars i:nth-child(1) { height: 4px; }
.priority__bars i:nth-child(2) { height: 7px; }
.priority__bars i:nth-child(3) { height: 10px; }
.priority--high { color: var(--priority-high-fg); }
.priority--high .priority__bars i { background: var(--priority-high); }
.priority--medium { color: var(--priority-medium-fg); }
.priority--medium .priority__bars i:nth-child(-n+2) { background: var(--priority-medium); }
.priority--low { color: var(--priority-low-fg); }
.priority--low .priority__bars i:nth-child(1) { background: var(--color-teal); }

/* --- Task list ------------------------------------------------------------ */
.task-group { margin-bottom: var(--sp-5); }
.task-group__head {
  display: flex; align-items: baseline; gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  padding: 0 var(--sp-1);
}
.task-group__date { font-size: var(--text-base); font-weight: 620; letter-spacing: -0.01em; }
.task-group__meta { font-size: var(--text-xs); color: var(--ink-3); }

.task-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.task {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s ease;
}
.task:last-child { border-bottom: none; }
.task:hover { background: var(--surface-hover); }
.task:hover .task__actions,
.task:focus-within .task__actions { opacity: 1; }

.task__check {
  width: 18px; height: 18px;
  margin-top: 2px;
  flex: none;
  display: grid; place-items: center;
  border: 1.5px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: transparent;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.task__check:hover { border-color: var(--color-teal); }
.task__check[data-status="in-progress"] { border-color: var(--color-mustard); background: var(--color-mustard-pale); color: var(--color-mustard-deep); }
.task__check[data-status="done"] { border-color: var(--status-done-dot); background: var(--status-done-dot); color: var(--on-accent); }

.task__body { min-width: 0; }
.task__name {
  font-size: var(--text-base);
  font-weight: 550;
  overflow-wrap: anywhere;
}
.task--done .task__name { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line-strong); }

.task__memo {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--ink-3);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.task__tags {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.task__project { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-xs); color: var(--ink-2); font-weight: 550; }

.task__side {
  display: flex; align-items: center; gap: var(--sp-3);
  padding-top: 1px;
}
.task__date { font-size: var(--text-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.task__date--overdue { color: var(--overdue-fg); font-weight: 620; }

.task__actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s ease; }
.task__actions .btn--icon { color: var(--ink-3); }
.task__actions .btn--icon:hover { color: var(--ink); }
.task__actions .btn--icon.is-danger:hover { color: var(--color-coral-deep); background: var(--color-coral-pale); }

/* --- Week board ----------------------------------------------------------- */
.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(150px, 1fr));
  gap: var(--sp-2);
  overflow-x: auto;
  padding-bottom: var(--sp-2);
}

.day {
  display: flex; flex-direction: column;
  min-height: 190px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.day { cursor: pointer; transition: border-color .12s ease, box-shadow .12s ease; }
.day:hover { border-color: var(--line-strong); }
.day:focus-visible { outline: none; box-shadow: var(--ring), var(--shadow-sm); }

/* Today is a soft marker; the selected day is the loud one, since it drives
   the list below. When a day is both, selected wins. */
.day--today { border-color: var(--color-teal-light); box-shadow: 0 0 0 1px var(--color-teal-light), var(--shadow-sm); }
.day--selected,
.day--today.day--selected {
  border-color: var(--color-teal);
  box-shadow: 0 0 0 2px var(--color-teal), var(--shadow-sm);
}
.day--selected .day__dow { color: var(--color-teal-deep); }
.day--empty .day__list { opacity: .55; }

.day__head {
  display: flex; align-items: baseline; gap: 6px;
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}
.day__dow { font-size: var(--text-xs); font-weight: 620; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.day--today .day__dow { color: var(--color-teal-deep); }
.day__num { font-size: var(--text-md); font-weight: 640; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.day__count { margin-left: auto; font-size: var(--text-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.day__bar { padding: 0 var(--sp-3) var(--sp-2); }
.day__list { display: flex; flex-direction: column; gap: 4px; padding: 0 var(--sp-2) var(--sp-2); }

.mini {
  display: flex; align-items: flex-start; gap: 6px;
  width: 100%;
  padding: 5px 6px;
  border-radius: 6px;
  border-left: 2px solid var(--proj, var(--color-teal));
  background: var(--surface-sunken);
  font-size: var(--text-sm);
  text-align: left;
  line-height: 1.4;
  transition: background .12s ease;
}
.mini:hover { background: var(--surface-hover); }
.mini__dot { width: 6px; height: 6px; border-radius: var(--r-pill); flex: none; margin-top: 5px; }
.mini__dot[data-status="todo"] { background: var(--status-todo-dot); }
.mini__dot[data-status="in-progress"] { background: var(--status-progress-dot); }
.mini__dot[data-status="done"] { background: var(--status-done-dot); }
.mini__name { min-width: 0; overflow-wrap: anywhere; }
.mini--done .mini__name { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line-strong); }

.day__add {
  margin: auto var(--sp-2) var(--sp-2);
  padding: 4px;
  border-radius: 6px;
  font-size: var(--text-xs);
  color: var(--ink-3);
  text-align: center;
  opacity: 0;
  transition: opacity .12s ease, background .12s ease;
}
.day:hover .day__add { opacity: 1; }
.day__add:hover { background: var(--color-teal-pale); color: var(--color-teal-deep); }

/* --- Selected day panel --------------------------------------------------- */
.daypanel { margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: 1px solid var(--line); }
.daypanel__head {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.daypanel__title { font-size: var(--text-xl); font-weight: 640; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.daypanel__meta { margin-top: 2px; font-size: var(--text-sm); color: var(--ink-3); }

/* --- Month calendar ------------------------------------------------------- */
.calendar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.calendar__dows {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--line);
  background: var(--surface-sunken);
}
.calendar__dow {
  padding: var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 620;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: center;
}
.calendar__grid { display: grid; grid-template-columns: repeat(7, 1fr); }

.cell {
  display: flex; flex-direction: column; gap: 4px;
  min-height: 108px;
  padding: 6px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--cell-bg, transparent);
  text-align: left;
  transition: box-shadow .12s ease;
}
.cell:nth-child(7n) { border-right: none; }
.calendar__grid > .cell:nth-last-child(-n+7) { border-bottom: none; }
.cell:hover { box-shadow: inset 0 0 0 1.5px var(--color-teal-light); }
.cell--out { background: var(--surface-sunken); }
.cell--out .cell__num { color: var(--ink-disabled); }

.cell__head { display: flex; align-items: center; gap: 4px; }
.cell__num { font-size: var(--text-xs); font-weight: 620; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.cell--today .cell__num {
  display: grid; place-items: center;
  width: 19px; height: 19px;
  border-radius: var(--r-pill);
  background: var(--color-teal);
  color: var(--on-accent);
}
.cell__flag { margin-left: auto; width: 6px; height: 6px; border-radius: var(--r-pill); background: var(--color-coral); }
.cell__items { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cell__item {
  display: flex; align-items: center; gap: 4px;
  font-size: var(--text-xs);
  color: var(--ink-2);
  line-height: 1.45;
  min-width: 0;
}
.cell__item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell__item--done span { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.cell__more { font-size: var(--text-xs); color: var(--ink-3); padding-left: 10px; }

/* --- Project cards -------------------------------------------------------- */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
  gap: var(--sp-4);
}

.pcard {
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.pcard:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); transform: translateY(-1px); }

.pcard__head { display: flex; align-items: flex-start; gap: var(--sp-2); }
.pcard__name { font-size: var(--text-md); font-weight: 640; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.pcard__desc {
  font-size: var(--text-sm); color: var(--ink-3); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pcard__pct { margin-left: auto; font-size: var(--text-lg); font-weight: 640; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--color-teal-deep); }
.pcard__counts { display: flex; flex-wrap: wrap; gap: 6px; }
.pcard__foot {
  display: flex; align-items: center; gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line);
  font-size: var(--text-xs); color: var(--ink-3);
}

.pcard--add {
  align-items: center; justify-content: center;
  min-height: 172px;
  gap: var(--sp-2);
  border-style: dashed;
  border-color: var(--line-strong);
  background: transparent;
  box-shadow: none;
  color: var(--ink-3);
  font-weight: 550;
}
.pcard--add:hover { background: var(--surface); color: var(--color-teal-deep); border-color: var(--color-teal-light); }

/* --- Empty state ---------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: var(--sp-10) var(--sp-5);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  text-align: center;
}
.empty__icon { color: var(--color-teal-light); margin-bottom: var(--sp-1); }
.empty__title { font-size: var(--text-md); font-weight: 620; }
.empty__text { font-size: var(--text-base); color: var(--ink-3); max-width: 40ch; }
.empty .btn { margin-top: var(--sp-2); }

/* --- Filter bar ----------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.filters select, .filters input {
  padding: 6px var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--text-base);
  color: var(--ink-2);
}
.filters select:focus, .filters input:focus { outline: none; border-color: var(--color-teal-light); box-shadow: var(--ring); }

/* --- Dialog / form -------------------------------------------------------- */
dialog {
  padding: 0;
  border: none;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
}
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }

.dialog__head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
}
.dialog__title { font-size: var(--text-md); font-weight: 640; letter-spacing: -0.01em; }
.dialog__close { margin-left: auto; color: var(--ink-3); }
.dialog__close:hover { color: var(--ink); }

.dialog__body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); max-height: min(64vh, 560px); overflow-y: auto; }
.dialog__foot {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--line);
  background: var(--surface-sunken);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.dialog__foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field__label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); }
.field__hint { font-size: var(--text-xs); color: var(--ink-3); }
.field__row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }

.input, .textarea, .select {
  width: 100%;
  padding: 8px var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--text-base);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--color-teal); box-shadow: var(--ring); }
.textarea { resize: vertical; min-height: 78px; line-height: 1.6; font-family: inherit; }
.input--lg { font-size: var(--text-md); font-weight: 550; padding: 10px var(--sp-3); }

/* Radio pill groups */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.pills label:hover { background: var(--surface-hover); }
.pills input:focus-visible + label { box-shadow: var(--ring); }

.pills input:checked + label[data-value="todo"] { background: var(--status-todo-bg); border-color: var(--color-teal); color: var(--status-todo-fg); }
.pills input:checked + label[data-value="in-progress"] { background: var(--status-progress-bg); border-color: var(--status-progress-dot); color: var(--status-progress-fg); }
.pills input:checked + label[data-value="done"] { background: var(--status-done-bg); border-color: var(--ink-3); color: var(--ink); }
.pills input:checked + label[data-value="high"] { background: var(--color-coral-pale); border-color: var(--color-coral); color: var(--color-coral-deep); }
.pills input:checked + label[data-value="medium"] { background: var(--color-mustard-pale); border-color: var(--color-mustard); color: var(--color-mustard-deep); }
.pills input:checked + label[data-value="low"] { background: var(--color-teal-pale); border-color: var(--color-teal); color: var(--color-teal-deep); }

/* Personal item schedule pills — teal, matching the rest of the diary. */
.pills input:checked + label[data-value="month"],
.pills input:checked + label[data-value="year"],
.pills input:checked + label[data-value="date"],
.pills input:checked + label[data-value="someday"] {
  background: var(--color-teal-pale);
  border-color: var(--color-teal);
  color: var(--color-teal-deep);
}

.swatches { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.swatches input { position: absolute; opacity: 0; pointer-events: none; }
.swatches label {
  width: 26px; height: 26px;
  border-radius: var(--r-pill);
  background: var(--sw);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 2px transparent;
  transition: box-shadow .12s ease, transform .12s ease;
}
.swatches label:hover { transform: scale(1.08); }
.swatches input:checked + label { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--sw); }

/* --- Toast ---------------------------------------------------------------- */
.toasts {
  position: fixed; bottom: var(--sp-5); left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 9px var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--text-base);
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  animation: toast-in .18s cubic-bezier(.2, .8, .3, 1);
}
.toast button { color: var(--color-teal-light); font-weight: 620; pointer-events: auto; }
.toast button:hover { text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Personal diary ------------------------------------------------------- */
/* The brand area becomes a full-width Work / Personal switch. */
.brand__switch { width: 100%; }
.brand__tab { flex: 1; text-align: center; white-space: nowrap; }

/* "New list" affordance at the foot of the lists rail. */
.rail__item--add { color: var(--ink-3); font-weight: 550; margin-top: 2px; }
.rail__item--add svg { width: 15px; height: 15px; flex: none; }
.rail__item--add:hover { color: var(--color-teal-deep); }

.ptitle { display: inline-flex; align-items: center; gap: 6px; }

.psection { margin-bottom: var(--sp-6); }
.psection:last-child { margin-bottom: 0; }
.psection-gap { margin-top: var(--sp-6); }

.phint {
  padding: var(--sp-4);
  font-size: var(--text-sm); color: var(--ink-3);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  text-align: center;
}

.pgroup { margin-bottom: var(--sp-4); }
.pgroup__head {
  margin: 0 0 var(--sp-2); padding: 0 var(--sp-1);
  font-size: var(--text-sm); font-weight: 620; color: var(--ink-2);
}

/* Item chips carry small inline icons (repeat, calendar, deadline). */
.chip svg { width: 12px; height: 12px; opacity: .8; }
.chip--carried {
  background: var(--color-mustard-pale);
  border-color: var(--color-mustard-light);
  color: var(--color-mustard-deep);
}

/* D-day badge — teal by default, mustard within a week, coral once overdue. */
.dday {
  font-size: var(--text-xs); font-weight: 640;
  font-variant-numeric: tabular-nums;
  color: var(--color-teal-deep);
  background: var(--color-teal-pale);
  border: 1px solid var(--color-teal-light);
  padding: 1px var(--sp-2); border-radius: var(--r-pill);
  white-space: nowrap;
}
.dday--soon { color: var(--color-mustard-deep); background: var(--color-mustard-pale); border-color: var(--color-mustard-light); }
.dday--over { color: var(--overdue-fg); background: var(--overdue-bg); border-color: var(--overdue-line); }

/* Coming-up strip on the current month. */
.coming {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.coming__label {
  display: inline-flex; align-items: center; gap: 6px;
  margin-right: var(--sp-1);
  font-size: var(--text-xs); font-weight: 620;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-3);
}
.coming__label svg { width: 14px; height: 14px; color: var(--color-teal); }
.coming__item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px var(--sp-2);
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface-sunken);
  font-size: var(--text-sm); color: var(--ink-2);
}
.coming__item:hover { background: var(--surface-hover); color: var(--ink); }
.coming__dday { font-weight: 640; font-variant-numeric: tabular-nums; color: var(--color-teal-deep); }
.coming__text { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Item editor: recurrence row + schedule panels. */
.sched-panel { display: flex; flex-direction: column; gap: var(--sp-4); }
.checkbox-line { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.recur-row { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--text-sm); color: var(--ink-2); }
.recur-every { width: 64px; flex: none; }
.recur-unit { width: auto; flex: none; }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 1080px) {
  .view { padding: var(--sp-5) var(--sp-5) var(--sp-10); }
  .topbar { padding: 0 var(--sp-5); }
}

@media (max-width: 860px) {
  /* minmax(0, …), not 1fr: `1fr` floors at min-content, so any too-wide
     descendant would stretch the page instead of scrolling inside itself. */
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; align-items: center;
    gap: var(--sp-4);
    overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .sidebar__section--rail, .brand__sub, .sidebar__hint { display: none; }
  /* The notes rail collapses to just its View all button — the page behind
     it is where notes are readable at this width anyway. */
  .notes-rail__head, .notes-rail__input, #notes-rail { display: none; }
  .sidebar__section--notes { flex: none; flex-direction: row; }
  .notes-rail__all { align-self: center; white-space: nowrap; }
  .brand { flex: none; }
  .nav { flex-direction: row; }
  .nav__item { white-space: nowrap; }
  .nav__label { display: none; }
  /* Export is the only backup path — it stays reachable, at the row's end. */
  .sidebar__foot { flex: none; flex-direction: row; margin: 0 0 0 auto; }
  .sidebar__foot .btn { white-space: nowrap; }
  .search { width: 160px; }
  .topbar__meta { display: none; }
  .field__row { grid-template-columns: 1fr; gap: var(--sp-3); }
  .week { grid-template-columns: repeat(7, minmax(140px, 1fr)); }
}

/* Phones. The topbar breaks to two rows, and month cells drop their task
   titles — seven columns in ~350px cannot hold readable text. Each cell keeps
   its density tint, its status dots and its overdue flag, and a tap opens the
   day, where the same tasks are listed with labels. */
@media (max-width: 620px) {
  .view { padding: var(--sp-4) var(--sp-4) var(--sp-10); }

  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
  }
  .topbar__title { flex: 1; min-width: 0; }
  .topbar__spacer { display: none; }
  .search { order: 3; width: 100%; }

  .toolbar { gap: var(--sp-2); margin-bottom: var(--sp-4); }
  .toolbar .stats { gap: var(--sp-2) var(--sp-4); }
  .range-nav { flex-wrap: wrap; }
  .range-nav__label { margin-right: var(--sp-1); }

  /* The board becomes a day picker: all seven visible at once, so the
     selection ring is never scrolled out of sight. Titles would not fit in
     ~48px anyway, and the full list is right below in .daypanel. */
  .week { grid-template-columns: repeat(7, 1fr); gap: 4px; overflow-x: visible; }
  .day { min-height: 0; }
  .day__head { flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; }
  .day__num { font-size: var(--text-base); }
  .day__count { margin-left: 0; }
  .day__bar { padding: 0 4px 6px; }
  .day__list, .day__add { display: none; }

  .calendar__dow { padding: 6px 2px; letter-spacing: 0.02em; }
  .cell { min-height: 62px; padding: 5px 3px; gap: 3px; }
  .cell__head { justify-content: center; gap: 3px; }
  .cell__flag { margin-left: 0; }
  .cell__items { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 3px; }
  .cell__item { gap: 0; }
  .cell__item > span { display: none; }
  .cell__more { display: none; }

  .task { padding: var(--sp-3); gap: var(--sp-2); }
  .btn--icon { width: 34px; height: 34px; }

  dialog { max-width: calc(100vw - 20px); }
  .dialog__body { padding: var(--sp-4); max-height: 68vh; }
  .dialog__foot { padding: var(--sp-3) var(--sp-4); }
}

/* Touch has no hover, so anything hidden behind it must not stay hidden. */
@media (hover: none) {
  .task__actions { opacity: 1; }
  .day__add { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
