@font-face {
  font-family: 'Baron Neue';
  src: url('../assets/fonts/BaronNeue.otf') format('opentype');
  font-weight: normal;
  font-display: swap;
}

/* ========== CSS Variables & Base ========== */
:root {
  --bg: #f5f3f0;
  --surface: #ffffff;
  --text: #2d2d2d;
  --text-secondary: #555;
  --shadow: 0 8px 30px rgba(0,0,0,0.08);
  --border: rgba(0,0,0,0.06);
  --btn-bg: #fff;
  --btn-hover: #f0f0f0;
  --overlay: rgba(0,0,0,0.5);
  --focus: #1a73e8;  /* keyboard focus ring */

  /* Ike App Colors — matrix layout: [red][blue] / [yellow][green] */
  --q1: #EE544F;  /* Focus (Urgent & Important)        — top-left,  red    */
  --q2: #00B9D5;  /* Goals (Not Urgent & Important)     — top-right, blue   */
  --q3: #FBB028;  /* Fit In (Urgent & Not Important)    — bottom-left, yellow */
  --q4: #01C0A6;  /* Backburner (Not Urgent & Not Imp.) — bottom-right, green */

  /* Darker shade of each quadrant colour — used for the progress-ring track. */
  --q1-dark: #CC4643;
  --q2-dark: #0090A5;
  --q3-dark: #CC8E21;
  --q4-dark: #008C7B;

  /* Pale pastel tints — shown on the non-target quadrants while dragging the +. */
  --q1-pale: #f8c9c7;
  --q2-pale: #bfe9f1;
  --q3-pale: #fde7bd;
  --q4-pale: #bfeae3;

  --q1-text: #ffffff;
  --q2-text: #ffffff;
  --q3-text: #ffffff;
  --q4-text: #ffffff;

  /* Task list page light backgrounds (lighter versions) */
  --q1-light: #ffebeb;  /* red    */
  --q2-light: #e0f0ff;  /* blue   */
  --q3-light: #fffde0;  /* yellow */
  --q4-light: #ebffeb;  /* green  */

  --quadrant-label: #ffffff;

  /* Progress-ring inner disc + centre text. */
  --ring-disc: #ffffff;
  --ring-number: #4a4a4a;
  --ring-caption: #8a8a8a;

  transition: background 0.3s, color 0.3s;
}

body.dark-mode {
  --bg: #1a1a1a;
  --surface: #2b2b2b;
  --text: #eaeaea;
  --text-secondary: #aaa;
  --shadow: 0 8px 30px rgba(0,0,0,0.4);
  --border: rgba(255,255,255,0.08);
  --btn-bg: #3a3a3a;
  --btn-hover: #4a4a4a;
  --overlay: rgba(0,0,0,0.7);
  --focus: #8ab4f8;

  --q1: #EE544F;  /* red    */
  --q2: #00B9D5;  /* blue   */
  --q3: #FBB028;  /* yellow */
  --q4: #01C0A6;  /* green  */

  --q1-light: #5c3232;  /* red    */
  --q2-light: #283b4f;  /* blue   */
  --q3-light: #4b4428;  /* yellow */
  --q4-light: #2d422d;  /* green  */

  --quadrant-label: #1a1a1a;

  --ring-number: #f0f0f0;
  --ring-caption: #cfcfcf;

  /* Per-quadrant darkened disc fills for dark mode. */
  --q1-disc: #6e2320;  /* red    */
  --q2-disc: #0a4a55;  /* blue   */
  --q3-disc: #6b4a10;  /* yellow */
  --q4-disc: #0a4d43;  /* green  */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The [hidden] attribute is how views are toggled in JS, and any class rule
   that sets `display` would otherwise win over the UA default. */
[hidden] { display: none !important; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  user-select: none;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

/* ========== Top ribbon ========== */
.app-ribbon {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
/* Centred title, so the corner buttons stay pinned to the edges. */
.ribbon-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin-top: calc(env(safe-area-inset-top, 0) / 2);
  font-family: 'Baron Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 1.35rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text);
  pointer-events: none;
}
.ribbon-btn {
  background: none;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s;
}
.ribbon-btn:hover { background: var(--btn-hover); }
.ribbon-btn svg { width: 24px; height: 24px; fill: var(--text); }
/* Hamburger strokes use currentColor, not fill. */
.menu-btn svg { fill: none; }

/* ========== Settings drawer ========== */
.drawer::backdrop {
  background: var(--overlay);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(-100%); } }

.drawer {
  inset: 0 auto 0 0;
  margin: 0;
  border: 0;
  max-height: none;
  height: 100%;
  width: min(84vw, 320px);
  color: inherit;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: calc(16px + env(safe-area-inset-top, 0)) 18px 18px;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}
.drawer[open] { display: flex; animation: slideIn 0.25s ease; }

.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-title {
  font-family: 'Baron Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 1.2rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text);
}
.drawer-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 6px;
}

.drawer-section { display: flex; flex-direction: column; gap: 10px; }
.drawer-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  font-weight: 600;
}
.drawer-hint { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.4; }

.drawer-action {
  align-self: flex-start;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.drawer-action:hover { background: var(--btn-hover); }

.drawer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text);
}
.drawer-row-stack { flex-direction: column; align-items: stretch; gap: 6px; }

/* iOS-style switch built from a checkbox. */
.drawer-switch {
  appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background 0.2s;
}
.drawer-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.drawer-switch:checked { background: var(--q4); }
.drawer-switch:checked::after { transform: translateX(18px); }

.drawer-select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.drawer-close:focus-visible,
.drawer-action:focus-visible,
.drawer-switch:focus-visible,
.drawer-select:focus-visible,
.menu-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ========== Main Matrix Container ========== */
/* Ike look: four full-bleed squares that touch edge-to-edge — no padding, no
   gaps, no rounded corners, no card shadows. */
.matrix-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 0;
}

.matrix-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0;
  position: relative;
  /* Shrink-to-reveal-seams on press: the whole grid scales in and a white gap
     opens between the four cells, exposing the axis labels sitting in the seams. */
  background: var(--bg);
  transition: gap 0.2s ease, transform 0.2s ease;
}
.matrix-grid.pressing {
  gap: 34px;
  transform: scale(0.94);
}

/* Axis labels sit in the white seams that open when the grid is pressed, laid
   out on axes with the centre plus as the origin:
     +y (up) Urgent · -y (down) Not Urgent  — on the vertical seam
     -x (left) Important · +x (right) Not Important — on the horizontal seam
   Hidden at rest; revealed only in the .pressing state. */
.matrix-grid::before,
.matrix-grid::after,
.matrix-grid .axis-horizontal-top,
.matrix-grid .axis-horizontal-bottom {
  position: absolute;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--text-secondary);
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.matrix-grid.pressing::before,
.matrix-grid.pressing::after,
.matrix-grid.pressing .axis-horizontal-top,
.matrix-grid.pressing .axis-horizontal-bottom {
  opacity: 1;
}

/* +y Urgent — vertical seam, upper arm; tilted 90° left (reads bottom-to-top). */
.matrix-grid::before {
  content: "Urgent";
  left: 50%;
  top: 25%;
  transform: translate(-50%, -50%) rotate(-90deg);
}

/* -y Not Urgent — vertical seam, lower arm; tilted 90° left. */
.matrix-grid::after {
  content: "Not Urgent";
  left: 50%;
  top: 75%;
  transform: translate(-50%, -50%) rotate(-90deg);
}

/* -x Important — horizontal seam, left arm. */
.matrix-grid .axis-horizontal-top {
  top: 50%;
  left: 25%;
  transform: translate(-50%, -50%);
}

/* +x Not Important — horizontal seam, right arm. */
.matrix-grid .axis-horizontal-bottom {
  top: 50%;
  left: 75%;
  transform: translate(-50%, -50%);
}

/* Full-bleed Ike-style quadrants: square, touching, no shadow. */
.quadrant {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;   /* label + ring centred in the cell */
  gap: 10px;
  cursor: pointer;
  border-radius: 0;
  box-shadow: none;
  transition: filter 0.25s, background 0.25s;
  overflow: hidden;
  padding: 12px;
}
.quadrant:active { filter: brightness(0.96); }

/* Quadrant backgrounds */
.q1 { background: var(--q1); }
.q2 { background: var(--q2); }
.q3 { background: var(--q3); }
.q4 { background: var(--q4); }

/* Labels — all-caps, white, light, letter-spaced, near the top. */
.quadrant-label {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--quadrant-label);
  text-align: center;
  opacity: 0.95;
}

/* ----- Drag-to-add feedback: fade the non-target quadrants to pale tints ----- */
.matrix-grid.dragging .quadrant:not(.drag-target) { filter: none; }
.matrix-grid.dragging .q1:not(.drag-target) { background: var(--q1-pale); }
.matrix-grid.dragging .q2:not(.drag-target) { background: var(--q2-pale); }
.matrix-grid.dragging .q3:not(.drag-target) { background: var(--q3-pale); }
.matrix-grid.dragging .q4:not(.drag-target) { background: var(--q4-pale); }
/* The target stays vivid and lifts slightly. */
.matrix-grid.dragging .quadrant.drag-target { filter: brightness(1.05); }

/* ========== Progress Ring (Ike style) ==========
   A big white inner disc, a track in the quadrant's darker shade, the completed
   arc drawn on top, and a large count + "to go" caption in the centre. */
.progress-container {
  position: relative;
  width: min(42vw, 150px);
  aspect-ratio: 1;
  flex: none;
}
.progress-ring {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}
/* Inner disc behind everything — white in light mode; in dark mode a darkened
   version of each quadrant's own colour (set per-quadrant below). */
.progress-ring-disc { fill: var(--ring-disc); }
body.dark-mode .q1 .progress-ring-disc { fill: var(--q1-disc); }
body.dark-mode .q2 .progress-ring-disc { fill: var(--q2-disc); }
body.dark-mode .q3 .progress-ring-disc { fill: var(--q3-disc); }
body.dark-mode .q4 .progress-ring-disc { fill: var(--q4-disc); }
/* Track: the quadrant's darker shade (set per-quadrant below). */
.progress-ring-bg {
  fill: none;
  stroke: rgba(0,0,0,0.10);
  stroke-width: 9;
}
.q1 .progress-ring-bg { stroke: var(--q1-dark); }
.q2 .progress-ring-bg { stroke: var(--q2-dark); }
.q3 .progress-ring-bg { stroke: var(--q3-dark); }
.q4 .progress-ring-bg { stroke: var(--q4-dark); }
/* Completed arc, drawn in white over the darker track. */
.progress-ring-fill {
  fill: none;
  stroke: #fff;
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}
.remaining-number {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.2rem;
  font-weight: 500;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--ring-number);
}
.total-text {
  position: absolute;
  top: 62%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--ring-caption);
  font-family: 'Segoe UI', system-ui, sans-serif;
}

/* ========== Center Draggable Plus Button ========== */
.plus-button {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  /* Ike-style: understated grey disc with a white plus. */
  background: #cfcfcf;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px rgba(0,0,0,0.28);
  cursor: grab;
  z-index: 20;
  transition: box-shadow 0.2s, transform 0.1s;
  user-select: none;
  border: none;
  /* The button owns the drag gesture: without this, a touch drag is treated as
     a scroll/pan and the pointer events get cancelled mid-drag. */
  touch-action: none;
}
.plus-button:active { cursor: grabbing; }
.plus-button.dragging {
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
  transform: translate(-50%, -50%) scale(1.1);
  transition: none;
}
.plus-button svg {
  width: 32px;
  height: 32px;
  fill: #fff;
}

/* ========== Task List Page ========== */
.task-list-page {
  display: none;
  flex-direction: column;
  /* flex, not 100vh: the page shares the viewport with the bottom nav. */
  flex: 1;
  min-height: 0;
  background: var(--surface);
  padding: 20px;
  animation: fadeSlideIn 0.3s ease;
}
.task-list-page.active {
  display: flex;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.task-list-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.back-btn {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--text);
  margin-right: 16px;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}
.back-btn:hover { background: var(--btn-hover); }
.task-list-title {
  font-size: 1.8rem;
  font-weight: 600;
  flex: 1;
}
.task-count-badge {
  background: var(--border);
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.task-items {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
}

.task-item {
  display: flex;
  align-items: center;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background 0.2s;
  border-radius: 8px;
  margin-bottom: 4px;
}
.task-item.dragging { opacity: 0.4; }
.task-item.drag-over {
  background: var(--btn-hover);
  outline: 2px dashed var(--text-secondary);
}

.drag-handle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: grab;
  padding: 4px;
  margin-right: 8px;
}
.drag-handle:active { cursor: grabbing; }
.dot-row { display: flex; gap: 3px; }
.dot {
  width: 5px;
  height: 5px;
  background: #aaa;
  border-radius: 50%;
}

.task-checkbox {
  appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--text-secondary);
  border-radius: 6px;
  margin-right: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.task-checkbox:checked {
  background: var(--text);
  border-color: var(--text);
}
.task-checkbox:checked::after {
  content: '✓';
  color: var(--surface);
  font-size: 16px;
  font-weight: bold;
}

.task-text {
  flex: 1;
  font-size: 1rem;
  word-break: break-word;
  cursor: default;
}
.task-text.completed {
  text-decoration: line-through;
  opacity: 0.5;
}
.task-text[contenteditable="true"] {
  outline: none;
  border-bottom: 2px dashed var(--text-secondary);
  cursor: text;
  background: var(--btn-hover);
  border-radius: 4px;
  padding: 2px 4px;
}

.task-delete-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  margin-left: 8px;
  opacity: 0.5;
  transition: opacity 0.2s, background 0.2s;
}
.task-delete-btn:hover {
  opacity: 1;
  background: var(--btn-hover);
  color: #e55;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px 16px;
  font-size: 0.95rem;
  opacity: 0.85;
}

.add-task-btn {
  margin-top: 16px;
  padding: 12px;
  background: var(--btn-bg);
  border: 2px dashed var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.add-task-btn:hover { background: var(--btn-hover); }

/* Splash overlay */
.splash-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  z-index: 1000;
  pointer-events: none;
  display: none;
  animation: splashFadeIn 0.8s ease-out forwards;
}
@keyframes splashFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Scrollbar */
.task-items::-webkit-scrollbar { width: 6px; }
.task-items::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Keyboard focus visibility (only shows for keyboard users, not mouse clicks) */
.quadrant:focus-visible,
.dark-mode-toggle:focus-visible,
.back-btn:focus-visible,
.add-task-btn:focus-visible,
.task-checkbox:focus-visible,
.task-delete-btn:focus-visible,
.task-text:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Responsive */
@media (max-width: 600px) {
  .quadrant { padding: 10px; }
  .remaining-number { font-size: 1.9rem; }
  .quadrant-label { font-size: 0.9rem; letter-spacing: 2px; }
  /* The plus button stays centred on the grid; only its size shrinks. */
  .plus-button { width: 56px; height: 56px; }
  .plus-button svg { width: 30px; height: 30px; }
  /* Smaller seam gap so the shrunk grid still fills a narrow screen. */
  .matrix-grid.pressing { gap: 24px; }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
/* ========== Task row: schedule affordances ========== */
.task-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.task-main .task-text { flex: none; }

/* Shows when a task has a block on the day view. */
.schedule-chip {
  align-self: flex-start;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.schedule-chip:hover { background: var(--btn-hover); }

.task-schedule-btn {
  background: none;
  border: none;
  font-size: 1.05rem;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s, transform 0.2s;
}
.task-schedule-btn:hover { opacity: 1; transform: scale(1.1); }
.task-schedule-btn.scheduled { opacity: 0.9; }

/* ========== Bottom navigation ========== */
.bottom-nav {
  display: flex;
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
  /* Clear the Android gesture bar / iOS home indicator. */
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-tab svg { width: 22px; height: 22px; fill: currentColor; }
.nav-tab.active { color: var(--text); font-weight: 600; }

/* ========== Day timeline ========== */
.timeline-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 0;
}
.timeline-view[hidden] { display: none; }

.timeline-header {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.day-nav { display: flex; align-items: center; gap: 6px; }
.nav-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.nav-btn:hover { background: var(--btn-hover); }
.day-heading { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.day-label { font-size: 1.15rem; font-weight: 600; }
.day-date { font-size: 0.72rem; color: var(--text-secondary); }
.today-btn {
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
}
.today-btn:hover { background: var(--btn-hover); }

.calendar-status {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.72rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text-secondary);
}
.calendar-status.ok { color: var(--q2); }
.calendar-status.warn { color: var(--q1); }
.calendar-status.muted { color: var(--text-secondary); }

/* ----- Unscheduled tray ----- */
.tray-wrapper { flex: none; margin: 8px 0 6px; }
.tray-head { display: flex; align-items: baseline; gap: 8px; }
.tray-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}
.tray-count { font-size: 0.68rem; color: var(--text-secondary); }

.timeline-tray {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 6px 0 2px;
  /* Vertical drags out of the tray must reach the grid, not scroll the strip. */
  touch-action: pan-x;
}
.timeline-tray::-webkit-scrollbar { height: 4px; }
.timeline-tray::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.tray-chip {
  flex: 0 0 auto;
  max-width: 170px;
  border: none;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-family: inherit;
  color: #fff;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
.tray-chip:active { cursor: grabbing; }
.tray-chip .chip-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tray-chip.q1 { background: var(--q1); }
.tray-chip.q2 { background: var(--q2); }
.tray-chip.q3 { background: var(--q3); }
.tray-chip.q4 { background: var(--q4); }
.tray-empty { font-size: 0.78rem; color: var(--text-secondary); padding: 4px 0; }

/* ----- Scrolling hour grid ----- */
.timeline-scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.timeline-scroller::-webkit-scrollbar { width: 6px; }
.timeline-scroller::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.timeline-grid { position: relative; }

.hour-lines { position: absolute; inset: 0; }
.hour-row {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
}
/* Half-hour tick, so 15-minute snapping has something to read against. */
.hour-row::after {
  content: "";
  position: absolute;
  left: 52px;
  right: 0;
  top: 50%;
  border-top: 1px dashed var(--border);
  opacity: 0.5;
}
.hour-label {
  position: absolute;
  top: -0.55em;
  left: 0;
  width: 46px;
  text-align: right;
  font-size: 0.65rem;
  color: var(--text-secondary);
  background: var(--bg);
  padding-right: 2px;
}

/* Two lanes: the phone's own events on the left, Habita's blocks on the right. */
.device-events-lane {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 56px;
  width: 32%;
}
.task-blocks-lane {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(56px + 33%);
  right: 2px;
}

.device-event {
  position: absolute;
  left: 0;
  right: 4px;
  overflow: hidden;
  padding: 3px 5px;
  border-left: 3px solid var(--text-secondary);
  border-radius: 4px;
  background: var(--btn-hover);
  opacity: 0.85;
  font-size: 0.66rem;
  color: var(--text-secondary);
  pointer-events: none;
}
.device-event-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-event-time { display: block; opacity: 0.75; font-variant-numeric: tabular-nums; }

.task-block {
  position: absolute;
  padding: 4px 6px;
  border-radius: 7px;
  color: #fff;
  overflow: hidden;
  cursor: grab;
  /* The block owns the gesture: dragging it must not scroll the day. */
  touch-action: none;
  box-shadow: 0 1px 5px rgba(0,0,0,0.22);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  font-size: 0.74rem;
  border: 2px solid transparent;
}
.task-block.q1 { background: var(--q1); }
.task-block.q2 { background: var(--q2); }
.task-block.q3 { background: var(--q3); }
.task-block.q4 { background: var(--q4); }
.task-block.completed { opacity: 0.55; }
.task-block.completed .task-block-title { text-decoration: line-through; }
.task-block.selected { border-color: var(--text); }
.task-block.dragging {
  cursor: grabbing;
  opacity: 0.9;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  z-index: 5;
}

.task-block-body { min-width: 0; flex: 1; }
.task-block-title {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-block-time {
  display: block;
  font-size: 0.66rem;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}

.task-block-actions { display: flex; gap: 2px; flex: none; }
.block-btn {
  background: rgba(0,0,0,0.18);
  border: none;
  color: #fff;
  border-radius: 5px;
  width: 20px;
  height: 20px;
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.block-btn:hover { background: rgba(0,0,0,0.32); }

.resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  cursor: ns-resize;
  touch-action: none;
}
.resize-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 26px;
  height: 3px;
  margin-left: -13px;
  border-radius: 2px;
  background: rgba(255,255,255,0.55);
}

.now-line {
  position: absolute;
  left: 46px;
  right: 0;
  height: 0;
  border-top: 2px solid var(--q1);
  pointer-events: none;
  z-index: 4;
}
.now-dot {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--q1);
}

.timeline-empty-hint {
  font-size: 0.76rem;
  color: var(--text-secondary);
  padding: 10px 4px 16px;
  line-height: 1.5;
}

/* ----- Drag feedback ----- */
.drag-ghost {
  position: fixed;
  z-index: 1200;
  transform: translate(-50%, -50%);
  pointer-events: none;
  padding: 6px 12px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.78rem;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.75;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.drag-ghost.over-grid { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
.drag-ghost.q1 { background: var(--q1); }
.drag-ghost.q2 { background: var(--q2); }
.drag-ghost.q3 { background: var(--q3); }
.drag-ghost.q4 { background: var(--q4); }

.drag-tooltip {
  position: fixed;
  z-index: 1300;
  transform: translate(-50%, -160%);
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.nav-tab:focus-visible,
.nav-btn:focus-visible,
.today-btn:focus-visible,
.calendar-status:focus-visible,
.tray-chip:focus-visible,
.task-block:focus-visible,
.block-btn:focus-visible,
.schedule-chip:focus-visible,
.task-schedule-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  .timeline-view { padding: 10px 8px 0; }
  .device-events-lane { width: 26%; }
  .task-blocks-lane { left: calc(56px + 27%); }
  .tray-chip { max-width: 140px; }
}

@media (prefers-reduced-motion: reduce) {
  .drag-ghost.over-grid { transform: translate(-50%, -50%); }
}
