/* ================================================================
   Eisenhower Matrix — Styles
   Flat, minimal design. No gradients, no box-shadows.
   ================================================================ */

/* ── CSS custom properties (variables) ─────────────────────────── */
:root {
  /* Quadrant accent colours — used on headers and archive labels */
  --q1-color: #b45309;   /* amber:  Urgent, Not Important */
  --q2-color: #b91c1c;   /* red:    Urgent + Important    */
  --q3-color: #1d4ed8;   /* blue:   Important, Not Urgent */
  --q4-color: #6b7280;   /* grey:   Neither               */

  /* Very light background tints for each quadrant */
  --q1-bg: #fffbeb;
  --q2-bg: #fef2f2;
  --q3-bg: #eff6ff;
  --q4-bg: #f9fafb;

  /* General palette */
  --border:       #e5e7eb;
  --border-dark:  #d1d5db;
  --text:         #111827;
  --text-muted:   #6b7280;
  --text-faint:   #9ca3af;
  --bg-page:      #f3f4f6;
  --bg-white:     #ffffff;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-size-base: 14px;
  --font-size-sm:   12px;
  --font-size-xs:   11px;

  /* Layout */
  --header-height: 52px;
  --quadrant-gap:  2px;
}

/* ── Reset & base ───────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: var(--font-size-base);
  color: var(--text);
  background: var(--bg-page);
  /* Prevent iOS rubber-band scroll on the page itself */
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

textarea, input {
  font-family: inherit;
  font-size: inherit;
}

.hidden {
  display: none !important;
}

/* ── App shell ──────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* dvh = dynamic viewport height, accounts for iPhone browser chrome */
}

/* ── Header ─────────────────────────────────────────────────────── */
#app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  /* Expand height to include the notch/status-bar area on iPhone */
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  padding: 0 16px 12px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#app-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Sync status indicator ──────────────────────────────────────── */
.sync-status {
  font-size: var(--font-size-xs);
  color: var(--text-faint);
}
.sync-status.saving { color: #d97706; }
.sync-status.saved  { color: #16a34a; }
.sync-status.error  { color: #dc2626; font-weight: 500; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn-secondary {
  padding: 5px 12px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text);
  background: var(--bg-white);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
}
.btn-secondary:hover {
  background: var(--bg-page);
}

.btn-small {
  padding: 3px 9px;
  font-size: var(--font-size-xs);
}

/* Icon-style buttons used inside task rows */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  border-radius: 4px;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-icon:hover {
  color: var(--text);
  background: var(--border);
}

/* ── Matrix grid ─────────────────────────────────────────────────── */
#main-view {
  flex: 1;
  min-height: 0; /* Needed so flex children can scroll independently */
}

.matrix-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  /* Fill the full remaining height below the header */
  height: 100%;
  gap: var(--quadrant-gap);
  background: var(--border); /* The gap colour shows through as a grid line */
}

/* Assign each quadrant to its grid position */
#q2 { grid-area: 1 / 1; }
#q1 { grid-area: 1 / 2; }
#q3 { grid-area: 2 / 1; }
#q4 { grid-area: 2 / 2; }

/* ── Individual quadrant ─────────────────────────────────────────── */
.quadrant {
  display: flex;
  flex-direction: column;
  background: var(--bg-white);
  overflow: hidden;
  /* Subtle drag-over highlight — toggled by JS */
  transition: background 0.1s;
}

.quadrant.drag-over-quadrant {
  background: #f0f9ff;
}

/* Quadrant header */
.quadrant-header {
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.quadrant-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.quadrant-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: 1.3;
}

.quadrant-hint {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* Per-quadrant accent on the label text */
#q2 .quadrant-label { color: var(--q2-color); }
#q1 .quadrant-label { color: var(--q1-color); }
#q3 .quadrant-label { color: var(--q3-color); }
#q4 .quadrant-label { color: var(--q4-color); }

/* Per-quadrant very subtle header tint */
#q2 .quadrant-header { background: var(--q2-bg); }
#q1 .quadrant-header { background: var(--q1-bg); }
#q3 .quadrant-header { background: var(--q3-bg); }
#q4 .quadrant-header { background: var(--q4-bg); }

/* ── Task list (scrollable area) ─────────────────────────────────── */
.task-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  /* Give a bit of breathing room at the top/bottom */
  padding: 4px 0;
  /* Smooth momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

/* ── Task item ───────────────────────────────────────────────────── */
.task-item {
  border-bottom: 1px solid var(--border);
  user-select: none; /* Prevent text selection while dragging */
}

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

/* The main row: drag handle | checkbox | text | action buttons */
.task-main {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 6px 4px;
  min-height: 36px;
}

/* Drag handle — hidden on mobile */
.drag-handle {
  color: var(--text-faint);
  cursor: grab;
  padding: 2px 4px;
  font-size: 14px;
  flex-shrink: 0;
  line-height: 1;
}
.drag-handle:active {
  cursor: grabbing;
}

/* Checkbox */
.task-checkbox {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #374151;
}

/* Task text — grows to fill available space, clickable to expand note */
.task-text {
  flex: 1;
  font-size: var(--font-size-base);
  line-height: 1.4;
  word-break: break-word;
  cursor: pointer;
  padding: 2px 0;
}

/* Note indicator dot — shows when the task has a saved note */
.note-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  margin-left: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Strikethrough for completed tasks */
.task-item.completed .task-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Task action buttons container */
.task-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

/* Visual feedback during drag */
.task-item.dragging {
  opacity: 0.4;
}
.task-item.drag-over {
  border-top: 2px solid #3b82f6;
}

/* ── Move dropdown menu ──────────────────────────────────────────── */
.move-menu {
  display: flex;
  flex-direction: column;
  background: var(--bg-white);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  margin: 0 8px 6px;
  overflow: hidden;
}

.move-option {
  text-align: left;
  padding: 8px 12px;
  font-size: var(--font-size-sm);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.move-option:last-child {
  border-bottom: none;
}
.move-option:hover, .move-option:active {
  background: var(--bg-page);
}

/* ── Note textarea ───────────────────────────────────────────────── */
.task-note {
  padding: 0 8px 8px;
}

.note-input {
  width: 100%;
  min-height: 60px;
  padding: 6px 8px;
  font-size: var(--font-size-sm);
  color: var(--text);
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 4px;
  resize: vertical;
  line-height: 1.5;
}
.note-input:focus {
  outline: 2px solid #3b82f6;
  outline-offset: -1px;
  background: var(--bg-white);
}

/* ── Add task input row ──────────────────────────────────────────── */
.add-task-row {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.add-task-input {
  width: 100%;
  padding: 5px 6px;
  font-size: var(--font-size-sm);
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
}
.add-task-input::placeholder {
  color: var(--text-faint);
}
.add-task-input:focus {
  outline: none;
  border-color: var(--border-dark);
  background: var(--bg-white);
}

/* ── Archive view ────────────────────────────────────────────────── */
#archive-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  -webkit-overflow-scrolling: touch;
}

.archive-header {
  margin-bottom: 20px;
}

.archive-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.archive-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.empty-archive {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  padding: 20px 0;
}

.archive-group {
  margin-bottom: 24px;
}

.archive-group-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* Colour the archive group titles to match quadrant colours */
.archive-group-title.q1-color { color: var(--q1-color); }
.archive-group-title.q2-color { color: var(--q2-color); }
.archive-group-title.q3-color { color: var(--q3-color); }
.archive-group-title.q4-color { color: var(--q4-color); }

.archive-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.archive-item:last-child {
  border-bottom: none;
}

.archive-task-text {
  flex: 1;
  font-size: var(--font-size-sm);
  word-break: break-word;
}

.archive-item.completed .archive-task-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.archive-date {
  font-size: var(--font-size-xs);
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ================================================================
   Mobile styles — stack quadrants vertically
   At ≤ 640px we switch from a 2×2 grid to a single column.
   ================================================================ */
@media (max-width: 640px) {

  /* Stack quadrants vertically by switching grid to flex column */
  .matrix-grid {
    display: flex;
    flex-direction: column;
    height: auto; /* Let the page scroll naturally on mobile */
    gap: 0;
    background: var(--bg-page);
  }

  /* Mobile stacking order (clockwise from top-right as specified):
     1. Q1 — Urgent, Not Important (was top-right on desktop)
     2. Q2 — Urgent + Important    (was top-left on desktop)
     3. Q3 — Important, Not Urgent (was bottom-left on desktop)
     4. Q4 — Neither               (was bottom-right on desktop)  */
  #q2 { order: 1; }
  #q1 { order: 2; }
  #q3 { order: 3; }
  #q4 { order: 4; }

  /* On mobile each quadrant shows its full task list (no clipping) */
  .quadrant {
    min-height: 160px;
    border-bottom: 3px solid var(--border);
  }

  /* On mobile the task list is NOT height-constrained — scrolls with the page */
  .task-list {
    overflow: visible;
    flex: none;
  }

  /* Hide drag handle on touch screens — DnD is unreliable on iOS */
  .drag-handle {
    display: none;
  }

  /* Make the "Move →" button a bit more tappable on mobile */
  .btn-icon {
    padding: 6px 8px;
    min-width: 36px;
    min-height: 36px;
  }

  /* Make checkboxes slightly easier to tap */
  .task-checkbox {
    width: 18px;
    height: 18px;
  }

  /* Quadrant label wraps gracefully on narrow screens */
  .quadrant-label {
    font-size: var(--font-size-xs);
  }

  /* Archive view gets slightly less padding */
  #archive-view {
    padding: 16px 12px;
  }
}
