:root {
  --bg: #F7F7F8;
  --panel: #FFFFFF;
  --border: #E8E8EB;
  --text: #14161A;
  --text-dim: #6B7280;
  --text-faint: #9CA3AF;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 8px 20px rgba(16,24,40,0.05);

  --dsa: #2DD4BF;
  --dsa-tint: #ECFDF9;
  --ai: #A78BFA;
  --ai-tint: #F5F1FE;
  --apps: #60A5FA;
  --apps-tint: #EFF6FF;
  --gym: #FB923C;
  --gym-tint: #FFF4EB;
  --project: #4ADE80;
  --project-tint: #F0FDF4;
  --water: #38BDF8;
  --water-tint: #EFF9FF;
  --neutral-tint: #F4F4F5;

  --ink: #14161A;
  --radius: 16px;

  --tl-time-w: 92px;
  --tl-line-w: 20px;
  --tube-fill: #9AA5B1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  font-size: 14px;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  padding: 4px 8px 24px;
}

.brand-mark { color: #6366F1; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text-dim);
  text-align: left;
  font-size: 14px;
}

.nav-item:not(:disabled):hover { background: var(--neutral-tint); }

.nav-item.is-active {
  background: var(--neutral-tint);
  color: var(--text);
  font-weight: 600;
}

.nav-item:disabled { cursor: default; opacity: 0.55; }

.nav-icon { width: 16px; height: 16px; display: inline-block; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 16px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--neutral-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
}

.user-name { font-weight: 600; font-size: 13px; }

/* ---------- Main ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 20px 32px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

.icon-btn:hover { background: var(--neutral-tint); }

.date-label { min-width: 160px; text-align: center; }

.btn-primary {
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 600;
}

.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  color: var(--text);
}

.btn-secondary:hover { background: var(--neutral-tint); }

.view-toggle {
  margin-left: auto;
  display: flex;
  gap: 2px;
  background: var(--neutral-tint);
  border-radius: 10px;
  padding: 3px;
}

.view-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 600;
}

.view-btn.is-active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.view-btn:disabled { opacity: 0.5; cursor: default; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.page-title { font-size: 30px; margin: 0; font-weight: 800; }
.page-subtitle { color: var(--text-dim); margin: 4px 0 24px; }

/* ---------- Rings ---------- */

.rings {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.ring-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.ring-svg { width: 72px; height: 72px; }

.ring-track { fill: none; stroke: var(--neutral-tint); stroke-width: 7; }
.ring-progress {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}
.ring-progress.is-predicted { stroke-dasharray: 3 4 !important; opacity: 0.6; }

.ring-pct {
  font-size: 15px;
  font-weight: 800;
  fill: var(--text);
}

.ring-label { font-weight: 700; margin-top: 8px; font-size: 13px; }
.ring-sub { color: var(--text-faint); font-size: 11px; margin-top: 2px; line-height: 1.3; }

/* ---------- Plan card / timeline ---------- */

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

.card h2 { font-size: 15px; margin: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* A continuous vertical line runs behind every row's dot, from the first
   entry to the last -- individual rows only draw their own dot; the line
   itself is one element so it never breaks at the gaps between rows. */
.timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timeline::before {
  content: "";
  position: absolute;
  left: calc(var(--tl-time-w) + var(--tl-line-w) / 2 - 0.75px);
  top: 22px;
  bottom: 22px;
  width: 1.5px;
  background: var(--border);
}

.timeline-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
}

.tl-time-col {
  flex-shrink: 0;
  width: var(--tl-time-w);
  padding: 15px 10px 0 0;
  text-align: right;
}

.tl-line-col {
  flex-shrink: 0;
  width: var(--tl-line-w);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* Stretch to the row's full height (which varies once a row is
     expanded) so the tube can be centered vertically within it, rather
     than pinned to a fixed top offset. */
  align-self: stretch;
}

/* A slim vertical capsule per row, filling from the top down as that
   row's own scheduled time block elapses -- purely a "where is now"
   read at a glance, deliberately one quiet neutral tone rather than a
   busy per-category palette, and independent of the done/undone status
   circle on the other side of the row. */
.tl-tube {
  width: 6px;
  height: 26px;
  border-radius: 3px;
  /* --neutral-tint is nearly the same shade as the page background it
     sits on, which made the empty tube invisible -- needs its own
     visible-but-quiet track color regardless of what's behind it. */
  background: #E4E6EA;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tl-tube-fill {
  width: 100%;
  background: var(--tube-fill);
  border-radius: 2px;
  transition: height 0.4s ease;
}

.tl-card {
  flex: 1;
  min-width: 0;
  border-radius: 12px;
  overflow: hidden;
}

.tl-row-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.timeline-row.is-row-done,
.timeline-row.is-row-fail {
  opacity: 0.6;
}

.timeline-row.is-row-done .tl-card,
.timeline-row.is-row-fail .tl-card {
  background: var(--neutral-tint) !important;
}

.timeline-row.is-row-done .tl-title,
.timeline-row.is-row-fail .tl-title {
  text-decoration: line-through;
  color: var(--text-dim);
}

.timeline-row.is-row-done .tl-icon,
.timeline-row.is-row-fail .tl-icon {
  filter: grayscale(1);
  opacity: 0.6;
}

.tl-chevron {
  color: var(--text-faint);
  font-size: 11px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
  width: 12px;
  text-align: center;
}

.timeline-row.is-expanded .tl-chevron { transform: rotate(90deg); }

.tl-drag-handle {
  color: var(--text-faint);
  cursor: grab;
  flex-shrink: 0;
  font-size: 14px;
  letter-spacing: -2px;
  padding: 0 2px;
  touch-action: none;
}

.tl-drag-handle:active { cursor: grabbing; }

.tl-time {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: text;
  line-height: 1.3;
  white-space: nowrap;
}

.tl-time.is-unset { color: var(--text-faint); font-weight: 400; font-style: italic; }

/* The end time sits on its own line beneath the start time -- a 12-hour
   "2:05 PM – 3:00 PM" is too wide for the column as one nowrap line at a
   readable size. */
.tl-time-end {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
}

.tl-time-inputs {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.tl-time-inputs input {
  width: 100px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 3px;
  background: var(--panel);
}

.timeline-row.is-drag-over .tl-card { outline: 2px dashed var(--accent, var(--text-dim)); outline-offset: -2px; }

/* The dragged row actively follows the pointer (see startRowDrag /
   onRowDragMove in app.js), so it should read as "lifted" -- a shadow
   and a slight scale -- rather than the old heavy dimming, which suited
   a row sitting still mid-reorder but looks broken on something visibly
   moving. */
.timeline-row.is-dragging {
  cursor: grabbing;
}
.timeline-row.is-dragging .tl-card {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
  transform: scale(1.01);
}

.tl-detail {
  padding: 0 14px 14px 56px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.tl-detail dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 0 0 10px;
}

.tl-detail dt { font-weight: 600; color: var(--text); }
.tl-detail dd { margin: 0; }

.tl-note-label {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.tl-stepper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 15px;
}

.tl-stepper button { width: 30px; height: 30px; padding: 0; }

.tl-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  cursor: pointer;
}

.tl-note-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12.5px;
  background: var(--panel);
  resize: vertical;
  min-height: 44px;
}

.tl-note-field { margin-top: 4px; }

.tl-note-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.tl-note-save { padding: 6px 12px; font-size: 12px; }

.tl-note-status {
  color: var(--project);
  font-weight: 700;
  font-size: 12px;
}

.tl-note-status.is-error { color: #F87171; }

.tl-reset-override {
  display: block;
  margin-bottom: 10px;
  padding: 6px 12px;
  font-size: 12px;
}

.tl-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tl-icon svg { width: 16px; height: 16px; }

.tl-body { flex: 1; min-width: 0; }
.tl-title { font-weight: 700; font-size: 13.5px; }
.tl-title.is-editable { cursor: text; }
.tl-title.is-editable:hover { text-decoration: underline dotted; text-underline-offset: 3px; }

.tl-title-input {
  font-weight: 700;
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  background: white;
}
.tl-sub { color: var(--text-dim); font-size: 12px; margin-top: 1px; }
.tl-sub.is-predicted { font-style: italic; }

.tl-status {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #D1D5DB;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.tl-status.is-done {
  background: #22C55E;
  border-color: #22C55E;
  color: white;
}

.tl-status.is-fail {
  background: #F87171;
  border-color: #F87171;
  color: white;
}

.tl-status.is-toggleable { cursor: pointer; }
.tl-status.is-toggleable:hover { border-color: var(--text-dim); }

.tl-remove {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 16px;
  padding: 2px 4px;
}
.tl-remove:hover { color: #EF4444; }

.add-todo-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.add-todo-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  background: var(--neutral-tint);
}

.add-todo-row input:focus { outline: 2px solid #C7D2FE; }

.category-select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 13px;
  background: var(--neutral-tint);
  color: var(--text);
  font-family: inherit;
}

/* ---------- Right sidebar ---------- */

.content-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.calendar-nav { display: flex; gap: 6px; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.cal-dow {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 700;
  padding-bottom: 4px;
}

.cal-day {
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 6px 0 8px;
  font-size: 12.5px;
  color: var(--text);
  position: relative;
}

.cal-day.is-muted { color: var(--text-faint); }
.cal-day:hover { background: var(--neutral-tint); }

.cal-day.is-selected {
  background: var(--ink);
  color: white;
  font-weight: 700;
}

.cal-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--dsa);
  margin: 2px auto 0;
}

.cal-day.is-selected .cal-dot { background: white; }

.quick-add-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.quick-add-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text);
}

.quick-add-btn:hover { background: var(--neutral-tint); }
.quick-add-btn.is-on { background: var(--project-tint); border-color: var(--project); }

.qa-icon svg { width: 18px; height: 18px; }

.focus-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

.focus-ring svg { width: 68px; height: 68px; }

.focus-summary { font-size: 13px; color: var(--text-dim); line-height: 1.5; }

/* ---------- Modal ---------- */

[hidden] { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,17,21,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  width: 360px;
}

.modal h3 { margin: 0 0 12px; }

.modal input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  background: var(--neutral-tint);
}

.modal-field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 12px 0 6px;
}

.modal-select { width: 100%; padding: 10px 12px; }

.modal-time-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-time-row input { width: auto; flex: 1; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.focus-modal { width: 300px; text-align: center; }

.focus-timer {
  font-size: 48px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 12px 0 18px;
  letter-spacing: 1px;
}

.focus-timer.is-done { color: var(--project); }

.focus-modal-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

@media (max-width: 1100px) {
  /* minmax(0, 1fr), not a bare 1fr -- a plain 1fr track still sizes to
     its item's max-content width by default, which let a wide row (the
     bigger 12-hour time column pushed this over the edge) blow the
     whole card past the viewport instead of wrapping/shrinking into it. */
  .content-grid { grid-template-columns: minmax(0, 1fr); }
  .rings { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 680px) {
  .sidebar { display: none; }
  .main { padding: 16px; }
  /* Pre-existing overflow, unrelated to the timeline work above: the
     Day/Week/Month toggle doesn't fit next to date-nav + Add Task on a
     narrow screen and was pushing the whole page wider than the
     viewport. Wrapping it to its own line fits everything without
     shrinking any of the buttons. */
  .topbar { flex-wrap: wrap; }
  .view-toggle { margin-left: 0; }

  /* Today's Plan first, progress rings pushed below it. */
  .content-main { display: flex; flex-direction: column; min-width: 0; }
  .page-title, .page-subtitle { order: 0; }
  /* min-width: 0 here too -- a flex column item's default min-width is
     its content's own min-content size, which let a wide timeline row
     force the whole card (and the page) wider than the viewport instead
     of shrinking to fit it. */
  .plan-card { order: 1; min-width: 0; }
  .rings { order: 2; grid-template-columns: repeat(3, 1fr); margin-top: 20px; margin-bottom: 0; }
  .timeline, .timeline-row { min-width: 0; }
  /* The wider desktop time column (for the 12-hour stacked format) eats
     too much of an already-narrow mobile card, leaving little room for
     the title before it wraps hard. Narrower here; the stacked format
     still fits it fine. */
  :root { --tl-time-w: 62px; }
  .tl-time { font-size: 12.5px; }
}
