.timeline-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.timeline-view-toggle {
  display: inline-grid;
  min-width: 180px;
}

.timeline-view-btn {
  padding: 7px 16px;
  border-radius: 9px;
  color: var(--body);
  font-size: 0.86rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.timeline-view-btn:hover {
  color: var(--ink);
}

.timeline-view-btn.active {
  background: var(--surface);
  color: var(--teal-ink);
  box-shadow: var(--shadow-sm);
}

.timeline-date-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timeline-date-label {
  min-width: 190px;
}

.timeline-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}

.timeline-day {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
}

.timeline-day .empty-state {
  margin-bottom: 12px;
}

.timeline-grid {
  position: relative;
}

/* Row tops and heights come from TimelineHelper::DayLayout: rows keep the
   base hour height and grow when an hour holds many items. */
.timeline-hour {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--line-soft);
}

.timeline-hour-label {
  position: absolute;
  top: -9px;
  left: 0;
  font-size: 0.75rem;
  color: var(--faint);
  background: white;
  padding-right: 8px;
  font-variant-numeric: tabular-nums;
}

.timeline-block {
  position: absolute;
  left: 64px;
  right: 8px;
  background: linear-gradient(90deg, var(--indigo-wash) 0%, #ffffff 100%);
  border: 1px solid #d4d9fc;
  border-left: 4px solid var(--indigo);
  border-radius: 8px;
  padding: 6px 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timeline-block.overdue {
  border-left-color: var(--danger);
}

.timeline-block.completed {
  opacity: 0.55;
}

.timeline-block.completed .timeline-block-title {
  text-decoration: line-through;
}

.timeline-block-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.timeline-block-time {
  flex: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--indigo);
  font-variant-numeric: tabular-nums;
}

.timeline-block-toggle {
  display: inline-flex;
  flex: none;
  margin: 0;
}

.timeline-block-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-block-title:hover {
  color: var(--indigo);
}

.timeline-block.in-progress {
  border-left-color: var(--amber);
}

.timeline-block-badge {
  flex: none;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--amber-wash);
  color: #b45309;
  font-size: 0.65rem;
  font-weight: 600;
  white-space: nowrap;
}

.timeline-block-start-form {
  display: inline-flex;
  flex: none;
  margin: 0;
}

.timeline-block-start {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 4px;
}

.timeline-block-start:hover,
.timeline-block-start:focus-visible {
  color: var(--amber);
}

.timeline-block-unschedule-form {
  display: inline-flex;
  flex: none;
  margin: 0;
}

.timeline-block-unschedule {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}

.timeline-block-unschedule:hover {
  color: var(--danger);
}

.timeline-block-note {
  display: block;
  font-size: 0.72rem;
  font-style: italic;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-block-context {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-block[draggable="true"],
.tray-task-info[draggable="true"] {
  cursor: grab;
}
.timeline-block.is-dragging,
.tray-task-info.is-dragging {
  opacity: 0.45;
}
.is-timeline-dragging .timeline-block:not(.is-dragging) {
  pointer-events: none;
}
.timeline-drop-indicator {
  position: absolute;
  left: 56px;
  right: 0;
  height: 0;
  border-top: 2px solid var(--indigo);
  z-index: 3;
  pointer-events: none;
}
.timeline-drop-indicator::before {
  content: attr(data-time);
  position: absolute;
  top: -10px;
  left: -48px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--indigo);
  background: white;
  padding-right: 4px;
  font-variant-numeric: tabular-nums;
}
.timeline-drop-indicator[hidden] {
  display: none;
}
/* Tap to place, for touch screens (see timeline_drag_controller.js). */
.timeline-block.is-selected,
.tray-task-info.is-selected {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}
.is-placing {
  padding-bottom: 96px;
}
.is-placing .timeline-block {
  pointer-events: none;
}
.timeline-place-bar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--indigo);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(10, 16, 32, 0.18);
}
.timeline-place-bar[hidden],
.timeline-place-bar [hidden] {
  display: none;
}
.timeline-place-text {
  flex: 1 1 12rem;
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
}
.timeline-place-bar button {
  min-height: 44px;
}
.tray-hint-touch {
  display: none;
}
@media (pointer: coarse) {
  .tray-hint-pointer {
    display: none;
  }
  .tray-hint-touch {
    display: block;
  }
}
.timeline-tray.is-drop-target {
  border-color: var(--indigo);
  background: var(--indigo-wash);
}
.tray-status {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
}
.tray-status:empty {
  display: none;
}
.tray-hint {
  font-size: 0.75rem;
  color: var(--faint);
  margin: -4px 0 8px;
}

.timeline-tray {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  position: sticky;
  top: 100px;
}

.timeline-tray h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.tray-empty {
  font-size: 0.85rem;
  color: var(--faint);
}

.tray-task {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.tray-task:last-child {
  border-bottom: none;
}

.tray-task-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  text-decoration: none;
}

.tray-task-title:hover {
  color: var(--indigo);
}

.tray-task-note {
  display: block;
  font-size: 0.75rem;
  font-style: italic;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tray-task-context {
  display: block;
  font-size: 0.75rem;
  color: var(--faint);
}

.tray-schedule-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tray-schedule-form input[type="time"] {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}

.tray-schedule-form input[type="time"]:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(15, 181, 166, 0.18);
}

.timeline-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.timeline-week-day {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 160px;
}

.timeline-week-day.today {
  border-color: var(--indigo);
  box-shadow: 0 0 0 2px rgba(91, 108, 240, 0.15);
}

.week-day-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
  color: inherit;
  text-decoration: none;
}

.week-day-header:hover .week-day-date {
  color: var(--indigo);
}

.week-day-open {
  display: none;
}

.week-day-name {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--body);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.week-day-date {
  font-size: 0.8rem;
  color: var(--faint);
}

.week-day-empty {
  text-align: center;
  color: var(--line-strong);
}

.week-task {
  padding: 6px;
  border-radius: 6px;
  background: var(--surface-soft);
  margin-bottom: 6px;
  border-left: 3px solid var(--indigo);
}

.week-task.completed {
  opacity: 0.55;
}

.week-task.completed .week-task-title {
  text-decoration: line-through;
}

.week-task-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.week-task-time {
  flex: none;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--indigo);
  font-variant-numeric: tabular-nums;
}

.week-task-title {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-task-title:hover {
  color: var(--indigo);
}

.week-task-unschedule-form {
  display: inline-flex;
  flex: none;
  margin: 0;
}

.week-task-unschedule {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}

.week-task-unschedule:hover {
  color: var(--danger);
}

.week-task-note {
  display: block;
  font-size: 0.68rem;
  font-style: italic;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.week-task-objective {
  font-size: 0.68rem;
  color: var(--faint);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-week-note {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
}

.timeline-week-note a {
  color: var(--indigo);
  font-weight: 600;
  text-decoration: none;
}

.timeline-week-note a:hover {
  text-decoration: underline;
}

/* Recurring habits share the block layout but get a teal accent. */
.timeline-block.habit {
  background: linear-gradient(90deg, var(--teal-wash) 0%, #ffffff 100%);
  border-color: #b8ebe3;
  border-left-color: var(--teal);
}

.timeline-block.habit .timeline-block-time {
  color: var(--teal-ink);
}

.timeline-block.habit .timeline-block-title:hover {
  color: var(--teal-ink);
}

.week-task.habit {
  background: var(--teal-wash);
  border-left-color: var(--teal);
}

.week-task.habit .week-task-time {
  color: var(--teal-ink);
}

.week-task.habit .week-task-title:hover {
  color: var(--teal-ink);
}

@media (max-width: 900px) {
  /* minmax(0, …) so a long one-line title is cut short instead of
     widening the column, and with it the page, past the screen. */
  .timeline-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .timeline-tray {
    position: static;
  }

  .timeline-week {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.tray-task-heading {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.tray-task-heading .tray-task-title {
  flex: 1;
  min-width: 0;
}

.tray-task-badge {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--indigo-wash);
  color: var(--indigo);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.tray-task-left-over {
  background: var(--danger-wash);
  color: var(--danger);
}

.tray-task-priority {
  display: inline-flex;
  flex: none;
  gap: 2px;
}

.tray-priority-btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
}

.tray-priority-btn:hover {
  color: var(--indigo);
  border-color: var(--indigo);
}

.tray-priority-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(91, 108, 240, 0.25);
}

/* The line marking the current time on today's grid. */
.timeline-now {
  position: absolute;
  left: 56px;
  right: 0;
  height: 2px;
  margin-top: -1px;
  background: var(--coral);
  z-index: 3;
  pointer-events: none;
}

.timeline-now::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--coral);
}

/* Touch screens: a tap on a task or block opens its action sheet, so the
   per-item buttons it holds (start, unschedule, priority, time) leave the
   items, and their titles get the room. */
.tray-task-more {
  display: none;
}

@media (pointer: coarse) {
  .timeline-block-start-form,
  .timeline-block-unschedule-form,
  .tray-task-priority,
  .tray-schedule-form {
    display: none;
  }

  .timeline-block,
  .tray-task-info {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .timeline-block:active,
  .tray-task-info:active {
    filter: brightness(0.97);
  }

  .tray-task {
    padding-block: 4px;
  }

  .tray-task-info {
    position: relative;
    padding-right: 24px;
    min-height: 44px;
  }

  .tray-task-more {
    display: block;
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--faint);
    font-size: 1.4rem;
    line-height: 1;
  }

  .timeline-block .task-checkbox {
    width: 22px;
    height: 22px;
  }
}

/* Phones: the day grid scrolls in its own box, opening at the current time,
   so In progress, the tray and habits are a short scroll away instead of
   below eighteen hours of grid. */
@media (max-width: 640px) {
  .timeline-day {
    padding: 10px 8px 0 10px;
  }

  .timeline-scroll {
    max-height: max(360px, 58dvh);
    overflow-y: auto;
    overscroll-behavior: contain;
    margin-right: -8px;
    padding-right: 8px;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .timeline-block-end {
    display: none;
  }

  .timeline-block-time {
    font-size: 0.7rem;
  }

  .timeline-block-title {
    font-size: 0.92rem;
  }

  .timeline-week {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  /* Above the tab bar. */
  .has-tab-bar .timeline-place-bar {
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 120;
  }

  .timeline-week-day {
    min-height: 0;
  }

  .week-day-header {
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
    min-height: 32px;
  }

  .week-day-open {
    display: block;
    margin-left: auto;
    color: var(--faint);
    font-size: 1.3rem;
    line-height: 1;
  }
}

/* The week view's × is a small target on touch screens; a day's view (its
   header links there) unschedules from the task's sheet instead. */
@media (pointer: coarse) {
  .week-task-unschedule-form {
    display: none;
  }
}
