/* TaskNotes Web Companion — tokens and the wide layout (≥ 1100 px).
 *
 * Token values follow the approved mockups (Design canvas "TaskNotes Web
 * Companion Mockups", artboards Main, Tasks, RibbonStates, States). The
 * medium (760–1099) and narrow (< 760) layouts arrive in W4; until then a
 * narrower window keeps the wide layout and scrolls horizontally.
 * No component hard-codes a colour — always a token — and state is never
 * conveyed by colour alone (feasibility §D).
 */

:root {
  color-scheme: light dark;

  /* Colour */
  --color-bg: #ffffff;
  --color-surface: hsl(240 5% 96%);         /* sidebar, gate ground */
  --color-surface-subtle: hsl(240 5% 98%);  /* status strip */
  --color-surface-raised: #ffffff;
  --color-text: hsl(240 10% 15%);
  --color-text-secondary: hsl(240 4% 46%);
  --color-text-meta: hsl(240 10% 25%);
  --color-separator: hsl(240 5% 88%);
  --color-separator-subtle: hsl(240 5% 92%);
  --color-control-border: hsl(240 5% 84%);
  --color-hover: rgba(0, 0, 0, 0.04);
  --color-accent: hsl(211 100% 50%);        /* system blue */
  --color-accent-strong: hsl(211 100% 40%); /* selection fill: white text passes 4.5:1 here, not on 50% */
  --color-accent-text: #ffffff;
  --color-accent-tint: hsl(211 100% 50% / 0.12);
  --color-accent-tint-border: hsl(211 100% 50% / 0.5);
  --color-accent-on-tint: hsl(211 100% 32%);
  --color-success: hsl(152 69% 26%);
  --color-success-tint: hsl(152 69% 31% / 0.12);
  --color-success-tint-border: hsl(152 69% 31% / 0.5);
  --color-warning: hsl(32 90% 30%);         /* amber text: "Organization Required" */
  --color-warning-tint: hsl(43 100% 50% / 0.18);
  --color-danger: hsl(348 80% 40%);         /* overdue date */
  --color-priority-low: hsl(240 4% 46%);
  --color-priority-medium: #c2410c;         /* orange flag, darkened for 3:1 as a graphic */
  --color-priority-high: hsl(348 90% 50%);
  --color-focus: hsl(211 100% 45%);
  --color-env: hsl(32 90% 30%);
  --color-env-tint: hsl(43 100% 50% / 0.18);

  /* Taxonomy swatches — FocusPane UI/Shared/SwatchColor.swift (Apple system colours) */
  --swatch-red: #ff3b30;
  --swatch-orange: #ff9500;
  --swatch-yellow: #ffcc00;
  --swatch-green: #34c759;
  --swatch-teal: #30b0c7;
  --swatch-blue: #007aff;
  --swatch-indigo: #5856d6;
  --swatch-purple: #af52de;
  --swatch-pink: #ff2d55;
  --swatch-brown: #a2845e;
  --swatch-graphite: #8e8e93;
  --swatch-neutral: #bfbfbf;

  /* Type */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-2xs: 11px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 15px;
  --text-xl: 20px;
  --leading: 1.45;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* Space, shape, targets */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --target-min: 44px;                 /* narrow-width minimum hit target (C1) */
  --focus-ring: 2px solid var(--color-focus);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);

  /* Layout (feasibility §D, ≥ 1100 px) */
  --toolbar-h: 56px;
  --sidebar-w: 208px;
  --list-w: 380px;
  /* Breakpoints (CSS variables cannot be used in @media — recorded for W4) */
  --bp-medium: 760px;
  --bp-wide: 1100px;

  /* Motion */
  --duration-fast: 120ms;
  --duration-drawer: 200ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1c1c1e;
    --color-surface: #232325;
    --color-surface-subtle: #232325;
    --color-surface-raised: #2c2c2e;
    --color-text: #f5f5f7;
    --color-text-secondary: #a1a1a6;
    --color-text-meta: #d1d1d6;
    --color-separator: #3a3a3c;
    --color-separator-subtle: #333335;
    --color-control-border: #48484a;
    --color-hover: rgba(255, 255, 255, 0.06);
    --color-accent: #0a84ff;
    --color-accent-strong: #0a6fd6;
    --color-accent-tint: hsl(211 100% 60% / 0.18);
    --color-accent-tint-border: hsl(211 100% 60% / 0.5);
    --color-accent-on-tint: #8cc4ff;
    --color-success: #5fd38a;
    --color-success-tint: hsl(152 60% 45% / 0.18);
    --color-success-tint-border: hsl(152 60% 45% / 0.5);
    --color-warning: #ffcc66;
    --color-warning-tint: hsl(43 100% 50% / 0.16);
    --color-danger: #ff8a80;
    --color-priority-low: #a1a1a6;
    --color-priority-medium: #ff9f0a;
    --color-priority-high: #ff6961;
    --color-focus: #4c9bff;
    --color-env: #ffcc66;
    --color-env-tint: hsl(43 100% 50% / 0.16);
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0ms;
    --duration-drawer: 0ms;
  }
}

/* ---- Base ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--weight-regular) var(--text-md) / var(--leading) var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

p, h1, h2, h3, ul { margin: 0; }
ul { padding: 0; list-style: none; }

.muted { color: var(--color-text-secondary); }

.caps {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font: inherit;
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.btn:hover { background: var(--color-hover); }

pre, code { font-family: var(--font-mono); font-size: var(--text-xs); }

[data-kind="ok"] { color: var(--color-text-secondary); }
[data-kind="busy"] { color: var(--color-text-secondary); }
[data-kind="warn"] { color: var(--color-warning); }
[data-kind="error"] { color: var(--color-danger); }

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  flex: none;
  background: var(--swatch-graphite);
}
.dot[data-swatch="red"] { background: var(--swatch-red); }
.dot[data-swatch="orange"] { background: var(--swatch-orange); }
.dot[data-swatch="yellow"] { background: var(--swatch-yellow); }
.dot[data-swatch="green"] { background: var(--swatch-green); }
.dot[data-swatch="teal"] { background: var(--swatch-teal); }
.dot[data-swatch="blue"] { background: var(--swatch-blue); }
.dot[data-swatch="indigo"] { background: var(--swatch-indigo); }
.dot[data-swatch="purple"] { background: var(--swatch-purple); }
.dot[data-swatch="pink"] { background: var(--swatch-pink); }
.dot[data-swatch="brown"] { background: var(--swatch-brown); }
.dot[data-swatch="graphite"], .dot[data-swatch="gray"] { background: var(--swatch-graphite); }
.dot[data-swatch="neutral"] { background: var(--swatch-neutral); }

/* ---- Brand ------------------------------------------------------------------- */

.brand { display: flex; align-items: center; gap: 10px; }
/* The TaskNotes brand mark — FocusPane Design/AppIcon/Exports/brand-mark[-dark].png
   (transparent derivative of the approved app icon; the dark variant via <picture>). */
.brand-mark {
  display: inline-flex; flex: none;
  width: 32px; height: 32px;
  padding: 3px;
  border: 1px solid var(--color-accent);     /* the mark's own blue, so the tile reads on light and dark grounds */
  border-radius: 22%;
  background: var(--color-surface-raised);
}
.brand-mark img { width: 100%; height: 100%; display: block; }
.brand-mark-lg { width: 44px; height: 44px; padding: 5px; border-width: 1.25px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: var(--weight-semibold); }
.brand-text .brand-name { font-size: 18px; }
.brand-text .muted, .brand-sub { font-size: var(--text-xs); }
.env-tag {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--color-env);
  background: var(--color-env-tint);
}

/* ---- Gate (artboard Main) ---------------------------------------------------- */

.gate {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-6);
  padding: 48px 16px;
  background: var(--color-surface);
}
.gate-card {
  width: 100%; max-width: 440px;
  display: flex; flex-direction: column; gap: var(--space-5);
  padding: 36px 32px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.gate-copy { display: flex; flex-direction: column; gap: 6px; }
.gate-title { font-size: var(--text-xl); font-weight: var(--weight-semibold); }
.gate-copy p { line-height: 1.5; }
/* Our own sign-in / sign-out buttons, adopted by CloudKit JS (it looks for
   "#<id> > .apple-auth-button", sets its onclick and toggles inline
   display block/none and opacity 1/0.5). Hidden until CloudKit JS shows them. */
.apple-auth-button { display: none; }
.btn-apple {
  width: 100%;
  height: 44px;
  padding: 0 18px;
  border: 1px solid #000;
  border-radius: var(--radius-md);
  background: #000;
  color: #fff;
  font: inherit;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}
.btn-apple:hover { background: #222; }
.btn-apple-inner { display: flex; align-items: center; justify-content: center; gap: var(--space-2); }
.btn-signout { height: 32px; }
@media (prefers-color-scheme: dark) {
  /* Apple's white style for dark backgrounds */
  .btn-apple { background: #fff; border-color: #fff; color: #000; }
  .btn-apple:hover { background: #e8e8ed; }
}
.gate-status { font-size: var(--text-sm); }
.gate-notes {
  display: flex; flex-direction: column; gap: 10px;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-separator-subtle);
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--color-text-secondary);
}
.gate-notes li { display: flex; gap: 10px; align-items: flex-start; }
.gate-notes svg { flex: none; margin-top: 1px; }
.gate-foot { font-size: var(--text-xs); }

/* ---- App frame (artboard Tasks) ------------------------------------------------ */

.app {
  height: 100%;
  display: flex; flex-direction: column;
}
.toolbar {
  height: var(--toolbar-h);
  flex: none;
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-separator);
}
.toolbar-end { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.sync-status { font-size: var(--text-xs); }
.toolbar-divider { width: 1px; height: 24px; background: var(--color-separator); }

.columns { flex: 1; min-height: 0; display: flex; }
.workspace { flex: 1; min-width: 0; display: flex; }

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

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  overflow-y: auto;
  padding: var(--space-4) var(--space-2);
  background: var(--color-surface);
  border-right: 1px solid var(--color-separator);
  display: flex; flex-direction: column; gap: var(--space-5);
}
.sec { display: flex; flex-direction: column; gap: 2px; }
.sec-heading { margin: 0; }
.sec-toggle {
  all: unset;
  box-sizing: border-box;
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%;
  height: 24px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
}
.sec-toggle:focus-visible { outline: var(--focus-ring); outline-offset: 0; }
.sec-title {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sec-toggle svg { margin-left: auto; }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav {
  display: flex; align-items: center; gap: 10px;
  min-height: 32px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: inherit;
  text-decoration: none;
}
a.nav:hover { background: var(--color-hover); }
a.nav[aria-current="page"] { background: var(--color-accent-strong); color: var(--color-accent-text); }
a.nav[aria-current="page"] .count { color: inherit; opacity: 0.9; }
a.nav[aria-current="page"] .dot { box-shadow: 0 0 0 1.5px var(--color-accent-text); }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-static { color: var(--color-text); }
.count { font-size: var(--text-xs); color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.nav-empty { padding: 0 var(--space-3); font-size: var(--text-xs); color: var(--color-text-secondary); }
.sidebar-note { margin: auto var(--space-3) 0; font-size: var(--text-2xs); line-height: 1.5; color: var(--color-text-secondary); }

/* ---- List ---------------------------------------------------------------------- */

.list-col {
  width: var(--list-w);
  flex: 0 0 var(--list-w);
  display: flex; flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--color-separator);
}
.list-header { padding: var(--space-3) var(--space-3) var(--space-2); border-bottom: 1px solid var(--color-separator-subtle); }
.list-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.list-subtitle { font-size: var(--text-xs); color: var(--color-text-secondary); }
.list-empty { padding: var(--space-6) var(--space-4); color: var(--color-text-secondary); text-align: center; }
.task-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 6px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.task-row {
  display: flex; gap: 10px;
  flex-shrink: 0;                     /* a min-height (narrow) would otherwise let the list squeeze rows */
  padding: 10px 12px 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.task-row:hover { background: var(--color-hover); }
.task-row:focus-visible { outline: var(--focus-ring); outline-offset: -2px; }
.task-row[aria-selected="true"] { background: var(--color-accent-strong); color: var(--color-accent-text); }
.task-row[aria-selected="true"] .row-date,
.task-row[aria-selected="true"] .row-meta,
.task-row[aria-selected="true"] .meta-overdue,
.task-row[aria-selected="true"] .sep { color: inherit; opacity: 0.92; }
.task-row[aria-selected="true"] .badge-amber { background: rgba(255, 255, 255, 0.22); color: inherit; }
.task-row[aria-selected="true"]:focus-visible { outline-color: var(--color-text); }
.check {
  width: 18px; height: 18px;
  margin-top: 2px;
  flex: none;
  border-radius: 999px;
  border: 1.5px solid var(--color-control-border);
  display: inline-flex; align-items: center; justify-content: center;
}
.check-done { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.row-name { flex: 1; min-width: 0; font-weight: var(--weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-row[data-completed="1"] .row-name { text-decoration: line-through; font-weight: var(--weight-medium); }
.task-row[data-untitled="1"] .row-name { font-style: italic; font-weight: var(--weight-medium); }
.row-attention { width: 14px; flex: none; }
.row-icon { display: inline-flex; align-self: center; color: var(--color-text-secondary); flex: none; }
.task-row[aria-selected="true"] .row-icon { color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.row-date { font-size: var(--text-xs); color: var(--color-text-secondary); white-space: nowrap; }
.row-date.overdue { color: var(--color-danger); font-weight: var(--weight-semibold); }
.row-meta { font-size: var(--text-xs); color: var(--color-text-meta); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.row-meta .meta { display: inline-flex; align-items: center; gap: 5px; }
.row-meta .sep { margin: 0 5px; color: var(--color-text-secondary); }
.row-meta .dot { width: 7px; height: 7px; }
.meta-overdue { color: var(--color-danger); font-weight: var(--weight-semibold); }
.row-snippet { align-items: center; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  line-height: 1.4;
  white-space: nowrap;
}
.badge-amber { background: var(--color-warning-tint); color: var(--color-warning); }

/* ---- Reading pane --------------------------------------------------------------- */

.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
.ribbon {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--color-separator-subtle);
}
.tb {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--color-control-border);
  border-radius: 7px;
  background: var(--color-surface-raised);
  color: inherit;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.tb[aria-disabled="true"] { cursor: default; }
.tb[aria-pressed="true"] { background: var(--color-accent-tint); border-color: var(--color-accent-tint-border); color: var(--color-accent-on-tint); }
.tb[data-done="1"] { background: var(--color-success-tint); border-color: var(--color-success-tint-border); color: var(--color-success); }
.tb-val { font-weight: var(--weight-semibold); }
.tb-val-none { font-weight: var(--weight-medium); color: var(--color-text-secondary); }
.tb[data-priority="low"] .priority-flag { color: var(--color-priority-low); }
.tb[data-priority="medium"] .priority-flag { color: var(--color-priority-medium); }
.tb[data-priority="high"] .priority-flag { color: var(--color-priority-high); }
.ribbon-sep { width: 1px; height: 22px; margin: 0 2px; background: var(--color-control-border); }
.pane-status {
  display: flex; align-items: center; gap: 6px;
  padding: 6px var(--space-4);
  border-bottom: 1px solid var(--color-separator-subtle);
  background: var(--color-surface-subtle);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}
.pane-header {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px var(--space-6) 14px;
  border-bottom: 1px solid var(--color-separator-subtle);
}
.pane-name { font-size: var(--text-xl); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.pane-name.untitled { font-style: italic; color: var(--color-text-secondary); }
.org-line { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--color-text-secondary); }
.org-missing { color: var(--color-warning); }
.pane-content { padding: var(--space-5) var(--space-6) var(--space-6); display: flex; flex-direction: column; gap: 28px; }
.on-ios { display: flex; flex-direction: column; gap: 10px; }
.on-ios-box {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6);
  padding: var(--space-3) 14px;
  border: 1px dashed var(--color-control-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  font-size: var(--text-sm);
  color: var(--color-text-meta);
}
.on-ios-box li { display: inline-flex; align-items: center; gap: var(--space-2); }
.pane-empty { margin: auto; text-align: center; color: var(--color-text-secondary); display: flex; flex-direction: column; gap: 4px; }
.pane-empty-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); color: var(--color-text); }

/* ---- W3: controls, editors, menus, dialog ------------------------------------- */

.btn-primary { background: var(--color-accent-strong); border-color: var(--color-accent-strong); color: var(--color-accent-text); }
.btn-primary:hover { background: var(--color-accent); }
.btn-small { height: 30px; padding: 0 12px; font-size: var(--text-sm); }
.btn-icon { width: 36px; padding: 0; justify-content: center; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.pending-tag { font-weight: var(--weight-regular); color: var(--color-text-secondary); }
.tb.pending { opacity: 0.7; }
.tb:not([aria-disabled="true"]) { cursor: pointer; }
.tb:not([aria-disabled="true"]):hover { background: var(--color-hover); }
.tb[aria-pressed="true"]:not([aria-disabled="true"]):hover { background: var(--color-accent-tint); }
.attention { outline: 2px solid var(--color-warning) !important; outline-offset: 2px; }

/* Status line states (artboards States, SyncStates) */
.status-ok { color: var(--color-success); display: inline-flex; }
.pane-status.status-conflict, .pane-status.status-failed { align-items: flex-start; gap: 10px; padding: 10px var(--space-4) 12px; font-size: var(--text-sm); }
.status-conflict { background: var(--color-warning-tint); color: var(--color-warning); border-bottom-color: var(--color-warning-tint); }
.status-failed { background: var(--color-surface); color: var(--color-text); }
.status-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.status-values { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: var(--text-xs); align-items: center; }
.status-values dt { opacity: 0.85; }
.status-values dd { margin: 0; }
.status-values .val { font-family: var(--font-mono); padding: 2px 6px; border-radius: 4px; background: var(--color-surface-raised); color: var(--color-text); }
.status-actions { display: flex; gap: var(--space-2); flex: none; }

/* Header name editor */
.name-input {
  width: 100%;
  height: 42px;
  padding: 0 4px;
  margin-left: -4px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
}
.name-input:hover { border-color: var(--color-separator); }
.name-input:focus-visible { outline: var(--focus-ring); outline-offset: 0; }
.name-input.untitled::placeholder { font-style: italic; }
.field-error { color: var(--color-danger); font-size: var(--text-sm); }

/* Schedule / Organisation sections */
.pane-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; align-items: start; }
.pane-grid .on-ios { grid-column: 1 / -1; }
.pane-section { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.help { font-size: var(--text-2xs); line-height: 1.5; color: var(--color-text-secondary); }
.trow {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 52px;
  padding: 8px var(--space-3);
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
}
.trow > svg { flex: none; color: var(--color-text-secondary); }
.trow-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.trow-title { font-weight: var(--weight-medium); }
.trow-value { font-size: var(--text-xs); color: var(--color-accent-on-tint); }
.trow-value.muted { color: var(--color-text-secondary); }
.switch {
  position: relative; flex: none;
  width: 44px; height: 26px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--color-control-border);
  cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 999px;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: left var(--duration-fast);
}
.switch[aria-checked="true"] { background: var(--color-accent-strong); }
.switch[aria-checked="true"]::after { left: 21px; }
.switch[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font: inherit;
}
.input-lg { height: 42px; font-size: 16px; }
.input[disabled] { opacity: 0.5; }
.field { display: flex; flex-direction: column; gap: 6px; position: relative; min-width: 0; }
.field-label { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--color-text-secondary); }
.required { color: var(--color-danger); }

/* Pickers */
.combo { position: relative; display: flex; align-items: center; }
.combo .input { padding-left: 32px; padding-right: 30px; }
.combo-ico, .combo-chev { position: absolute; display: inline-flex; color: var(--color-text-secondary); pointer-events: none; }
.combo-ico { left: 10px; }
.combo-chev { right: 10px; }
.picker-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 5;
  margin-top: 4px;
  max-height: 280px; overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  display: flex; flex-direction: column; gap: 2px;
}
.picker-opt { display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 0 8px; border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; }
.picker-opt.active { background: var(--color-accent-tint); }
.picker-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-tick { width: 14px; display: inline-flex; color: var(--color-accent-on-tint); }
.cb { width: 16px; height: 16px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 1.5px solid var(--color-control-border); border-radius: 4px; }
.cb.on { background: var(--color-accent-strong); border-color: var(--color-accent-strong); color: #fff; }
.picker-empty { padding: 6px 8px; color: var(--color-text-secondary); font-size: var(--text-sm); }
.picker-foot { padding: 6px 8px 2px; border-top: 1px solid var(--color-separator-subtle); font-size: var(--text-2xs); color: var(--color-text-secondary); }
mark { background: var(--color-warning-tint); color: inherit; border-radius: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
.chips-empty { font-size: var(--text-xs); color: var(--color-text-secondary); align-self: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 6px 0 10px;
  border: 1px solid var(--color-accent-tint-border);
  border-radius: 999px;
  background: var(--color-accent-tint);
  color: var(--color-accent-on-tint);
  font-size: var(--text-sm);
}
.chip-remove { all: unset; display: inline-flex; width: 20px; height: 20px; border-radius: 999px; align-items: center; justify-content: center; cursor: pointer; }
.chip-remove:hover { background: var(--color-accent-tint); }
.chip-remove:focus-visible { outline: var(--focus-ring); }

/* List row attention glyph (artboard SyncStates) */
.row-attention.on {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  align-self: center;
  border-radius: 5px;
  background: var(--color-warning-tint);
  color: var(--color-warning);
}
.task-row[aria-selected="true"] .row-attention.on { background: rgba(255, 255, 255, 0.28); color: inherit; }

/* Menus (artboard ContextMenus) */
.menu-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.menu {
  position: fixed;
  pointer-events: auto;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--color-control-border);
  border-radius: 10px;
  background: var(--color-surface-raised);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  display: flex; flex-direction: column; gap: 1px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 30px; padding: 0 10px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: inherit;
  font: inherit; font-size: var(--text-sm);
  text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus { background: var(--color-accent-strong); color: var(--color-accent-text); outline: none; }
.menu-item[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.menu-item[aria-disabled="true"]:hover, .menu-item[aria-disabled="true"]:focus { background: var(--color-hover); color: inherit; }
.menu-item svg:last-child:not(:first-child) { margin-left: auto; }
.menu-check { width: 14px; display: inline-flex; flex: none; }
.menu-label { flex: 1; }
.menu-hint { font-size: var(--text-2xs); opacity: 0.75; }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--color-separator); }

/* New Task dialog (artboard NewTask) */
.dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  margin-top: 48px;
  padding: 0;
  border: 1px solid var(--color-separator);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  color: var(--color-text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}
.dialog::backdrop { background: rgba(20, 20, 30, 0.32); }
.dialog-form { display: flex; flex-direction: column; max-height: inherit; }
.dialog-head { display: flex; align-items: center; gap: var(--space-3); padding: 18px 22px 0; }
.dialog-title { font-size: 18px; font-weight: var(--weight-semibold); }
.dialog-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); align-items: start; }
.dialog-sep { height: 1px; background: var(--color-separator-subtle); }
.dialog-org { display: flex; flex-direction: column; gap: 14px; }
.dialog-org-head { display: flex; align-items: center; gap: 10px; font-size: var(--text-xs); }
.org-preview { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--color-warning); }
.org-preview.ok { color: var(--color-success); }
.dialog-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--color-separator-subtle);
  background: var(--color-surface-subtle);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  font-size: var(--text-xs);
}
.dialog-foot > :first-child { flex: 1; }
.dialog-error { color: var(--color-danger); font-size: var(--text-sm); }

/* ---- W4: shared pieces ----------------------------------------------------------- */

.spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--color-accent-on-tint);
  cursor: pointer;
}
.icon-btn:hover { background: var(--color-hover); }
.icon-btn[disabled] { color: var(--color-text-secondary); opacity: 0.45; cursor: default; }
.link-btn {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 32px; padding: 0 6px 0 0;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--color-accent-on-tint);
  font: inherit; font-weight: var(--weight-medium);
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

/* Drawer chrome and the narrow row chevron exist only below the wide layout. */
.drawer-head, .drawer-foot, .row-chevron, .scrim { display: none; }
.list-bar { display: flex; align-items: center; gap: var(--space-1); margin: -4px 0 4px -2px; }
.list-title:focus { outline: none; }
.list-title:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* Which parts show (app.js applyScreen sets these from layout.screenFor). */
.app[data-list="0"] .list-col { display: none; }
.app[data-pane="0"] .pane { display: none; }

/* Expanded view / narrow task screen header (artboards Expanded, NarrowTask). */
.pane-top {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 8px var(--space-4);
  border-bottom: 1px solid var(--color-separator-subtle);
  position: sticky; top: 0; z-index: 2;
  background: var(--color-bg);
}
.back-btn { font-size: var(--text-md); }
.pane-position { font-size: var(--text-xs); color: var(--color-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pane-top .btn-small { margin-left: var(--space-2); }

/* Reading pane as a container: the ribbon goes glyph-only and the content
   stacks when the pane itself is narrow, whatever the window width. */
.pane { container: pane / inline-size; }
.pane-meta { display: none; font-size: var(--text-sm); color: var(--color-text-secondary); }
.pane-meta .sep { margin: 0 6px; }

@container pane (max-width: 639px) {
  .ribbon .tb-label, .ribbon .pending-tag, .ribbon .tb-chev { display: none; }   /* Today keeps its tick: state is never colour alone */
  .ribbon .tb { min-width: 40px; padding: 0 10px; }
  .ribbon .due-icon.has-value { color: var(--color-accent-on-tint); }
  .pane-meta { display: block; }
  .pane-grid { grid-template-columns: minmax(0, 1fr); }
  .pane-content, .pane-header { padding-left: var(--space-4); padding-right: var(--space-4); }
}
@container pane (max-width: 520px) {
  .pane-keys { display: none; }
}

/* An expanded view uses the whole width but keeps a readable measure. */
.app[data-task-screen="1"] .pane > :not(.pane-top) { width: 100%; max-width: 920px; margin-left: auto; margin-right: auto; }

/* ---- W4: wide (≥ 1100) — Expanded view hides the sidebar and list ------------------ */

body[data-layout="wide"] .app[data-sidebar="hidden"] .sidebar { display: none; }

/* ---- W4: medium (760–1099) and narrow (< 760) — the Views drawer -------------------- */

body:not([data-layout="wide"]) .sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
  width: min(320px, 86vw); flex: none;
  padding: 0 var(--space-2) var(--space-3);
  gap: 0;
  border-right: 1px solid var(--color-separator);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform var(--duration-drawer) ease, visibility 0s linear var(--duration-drawer);
}
body:not([data-layout="wide"]) .app[data-sidebar="drawer"] .sidebar {
  transform: none;
  visibility: visible;
  transition: transform var(--duration-drawer) ease;
}
body:not([data-layout="wide"]) .drawer-head {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: 52px; padding: 4px 0 4px var(--space-3);
  position: sticky; top: 0; z-index: 1;
  background: var(--color-surface);
}
.drawer-title { flex: 1; font-size: var(--text-lg); font-weight: var(--weight-semibold); }
body:not([data-layout="wide"]) .sidebar-body { display: flex; flex-direction: column; gap: var(--space-5); padding-top: var(--space-2); }
body:not([data-layout="wide"]) .scrim:not([hidden]) {
  display: block; position: fixed; inset: 0; z-index: 39;
  background: rgba(20, 20, 30, 0.32);
}

/* ---- W4: medium ----------------------------------------------------------------------- */

body[data-layout="medium"] { --list-w: 340px; }
body[data-layout="medium"] .brand-sub,
body[data-layout="medium"] #refresh .btn-label { display: none; }
body[data-layout="medium"] #refresh { width: 36px; padding: 0; justify-content: center; }

/* ---- W4: narrow — one screen at a time ----------------------------------------------- */

body[data-layout="narrow"] { font-size: 15px; }
/* No toolbar (artboard NarrowList): Refresh and + move into the list header,
   Sign out into the drawer. The sync status stays, as a slim strip, so an
   error ("Couldn't reach iCloud") is still seen and announced. */
body[data-layout="narrow"] .toolbar { height: auto; min-height: 0; padding: 2px var(--space-4); border-bottom: 0; }
body[data-layout="narrow"] .toolbar > .brand,
body[data-layout="narrow"] .toolbar-end > :not(.sync-status) { display: none; }
body[data-layout="narrow"] .toolbar-end { margin-left: 0; }
body[data-layout="narrow"] .toolbar:has(.sync-status:empty) { display: none; }
body[data-layout="narrow"] .app[data-task-screen="1"] .toolbar { display: none; }

body[data-layout="narrow"] .list-col { width: 100%; flex: 1; border-right: 0; }
body[data-layout="narrow"] .list-header { padding: 4px var(--space-2) var(--space-2) var(--space-4); }
body[data-layout="narrow"] .list-bar { margin: 0 0 2px -12px; }
body[data-layout="narrow"] .list-title { font-size: 26px; font-weight: 700; line-height: 1.2; }
body[data-layout="narrow"] .list-subtitle { font-size: var(--text-sm); }
body[data-layout="narrow"] .icon-btn { width: var(--target-min); height: var(--target-min); }
body[data-layout="narrow"] .task-list { padding: 0; gap: 0; }
body[data-layout="narrow"] .task-row { padding: 12px var(--space-3) 12px var(--space-4); border-radius: 0; border-bottom: 1px solid var(--color-separator-subtle); min-height: var(--target-min); }
body[data-layout="narrow"] .task-row[aria-selected="true"] { background: transparent; color: inherit; }
body[data-layout="narrow"] .task-row[aria-selected="true"] .row-date,
body[data-layout="narrow"] .task-row[aria-selected="true"] .row-meta,
body[data-layout="narrow"] .task-row[aria-selected="true"] .sep { opacity: 1; color: var(--color-text-secondary); }
body[data-layout="narrow"] .task-row[aria-selected="true"] .row-meta { color: var(--color-text-meta); }
body[data-layout="narrow"] .task-row[aria-selected="true"] .meta-overdue,
body[data-layout="narrow"] .task-row[aria-selected="true"] .row-date.overdue { color: var(--color-danger); }
body[data-layout="narrow"] .task-row[aria-selected="true"] .badge-amber { background: var(--color-warning-tint); color: var(--color-warning); }
body[data-layout="narrow"] .task-row[aria-selected="true"] .row-icon { color: var(--color-text-secondary); }
body[data-layout="narrow"] .check { width: 22px; height: 22px; margin-top: 1px; }
body[data-layout="narrow"] .row-chevron { display: inline-flex; align-self: center; color: var(--color-text-secondary); flex: none; }
body[data-layout="narrow"] .row-meta { font-size: var(--text-sm); }

body[data-layout="narrow"] .pane { width: 100%; }
body[data-layout="narrow"] .pane-top { padding: 2px var(--space-2); min-height: 48px; }
body[data-layout="narrow"] .back-btn { min-height: var(--target-min); font-size: 16px; }
/* Ribbon: four equal 44 px targets (artboard NarrowTask). */
body[data-layout="narrow"] .ribbon { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); padding: 10px var(--space-4); }
body[data-layout="narrow"] .ribbon .tb { height: var(--target-min); min-width: var(--target-min); width: 100%; border-radius: 10px; }
body[data-layout="narrow"] .ribbon .tb svg { width: 20px; height: 20px; }
body[data-layout="narrow"] .input { height: var(--target-min); font-size: 16px; }   /* 16 px: no zoom-on-focus in iOS Safari */
body[data-layout="narrow"] .trow { min-height: 56px; }
body[data-layout="narrow"] .switch { width: 51px; height: 31px; }
body[data-layout="narrow"] .switch::after { width: 27px; height: 27px; top: 2px; left: 2px; }
body[data-layout="narrow"] .switch[aria-checked="true"]::after { left: 22px; }
body[data-layout="narrow"] .chip { height: 32px; }
body[data-layout="narrow"] .chip-remove { width: 28px; height: 28px; }
body[data-layout="narrow"] .btn { min-height: var(--target-min); }
body[data-layout="narrow"] .nav { min-height: var(--target-min); font-size: 15px; gap: 12px; }
body[data-layout="narrow"] .sec-toggle { height: 36px; }
body[data-layout="narrow"] .menu-item { min-height: var(--target-min); font-size: 15px; }
body[data-layout="narrow"] .picker-opt { min-height: var(--target-min); font-size: 15px; }

body[data-layout="narrow"] .drawer-foot {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: auto; padding: var(--space-3);
  border-top: 1px solid var(--color-separator);
  position: sticky; bottom: calc(-1 * var(--space-3));   /* Sign out stays in reach (artboard NarrowDrawer) */
  background: var(--color-surface);
}
body[data-layout="narrow"] .drawer-foot .apple-button { margin-left: auto; }

/* ---- W4: New Task at each width (artboards NewTask, NewTaskMedium, NewTaskNarrow) ----- */

.sheet-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-6); align-items: start; }
.sheet-section { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.sheet-close, .head-cancel, .head-cancel-medium, .head-submit, .submit-short, .body-context { display: none; }
.dialog-head .head-context { font-size: var(--text-sm); }
body[data-layout="wide"] .sheet-close { display: inline-flex; order: 99; }   /* wide: × top-right (artboard NewTask) */

/* Medium: a Mail-style compose sheet inset 16 px — × top-left, Cancel / Add Task top-right. */
body[data-layout="medium"] .dialog {
  width: auto; max-width: none; max-height: none;
  inset: 16px; margin: 0; height: calc(100% - 32px);
}
body[data-layout="medium"] .dialog-form { height: 100%; max-height: none; }
body[data-layout="medium"] .dialog-head { padding: 12px 16px; border-bottom: 1px solid var(--color-separator-subtle); }
body[data-layout="medium"] .sheet-close, body[data-layout="medium"] .head-cancel-medium, body[data-layout="medium"] .head-submit { display: inline-flex; }
body[data-layout="medium"] .dialog-body { flex: 1; padding: 20px 24px; }
body[data-layout="medium"] .dialog-foot .foot-btn { display: none; }

/* Narrow: full height, Cancel · New Task · Add fixed at the top, one column, 44 px controls. */
body[data-layout="narrow"] .dialog {
  width: 100%; max-width: none; height: 100%; max-height: none;
  inset: 0; margin: 0;
  border: 0; border-radius: 0;
}
body[data-layout="narrow"] .dialog-form { height: 100%; max-height: none; }
body[data-layout="narrow"] .dialog-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 6px var(--space-2);
  border-bottom: 1px solid var(--color-separator-subtle);
  background: var(--color-surface-raised);
}
body[data-layout="narrow"] .dialog-head > .head-cancel { display: inline-flex; justify-self: start; border: 0; background: transparent; color: var(--color-accent-on-tint); }
body[data-layout="narrow"] .dialog-head > .dialog-title { grid-column: 2; font-size: 17px; }
body[data-layout="narrow"] .dialog-head > .head-context, body[data-layout="narrow"] .dialog-head > .spacer { display: none; }
body[data-layout="narrow"] .dialog-head > .head-submit { display: inline-flex; grid-column: 3; justify-self: end; }
body[data-layout="narrow"] .head-submit .submit-long { display: none; }
body[data-layout="narrow"] .head-submit .submit-short { display: inline; }
body[data-layout="narrow"] .body-context { display: block; font-size: var(--text-sm); }
body[data-layout="narrow"] .dialog-body { flex: 1; padding: var(--space-4); }
body[data-layout="narrow"] .sheet-columns { grid-template-columns: minmax(0, 1fr); gap: var(--space-6); }
body[data-layout="narrow"] .dialog-foot { border-radius: 0; }
body[data-layout="narrow"] .dialog-foot .foot-btn { display: none; }
