/* DPI Site Monitoring.
 *
 * Reference lock: Linear's issue list (the screenshot Enzo supplied) for the
 * dense list — left sidebar with counts, collapsible groups with a count in the
 * header, quiet rows where colour appears only on the status glyph. The mobile
 * editor borrows Asana's iOS task sheet (rounded top, drag handle, stacked
 * field rows, primary action at the bottom).
 *
 * Role rules kept from the DPI guardrails: red is brand and alert only, never a
 * surface. Working tools stay in neutral greys. Status colours live on status
 * marks and date text, nowhere else.
 */

/* ============================== TOKENS ============================== */
:root {
  color-scheme: light;

  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --raised: #FAFAFA;
  --subtle: #F4F4F5;
  --border: #EBEBEF;
  --border-strong: #DCDCE3;

  --text-1: #17171A;
  --text-2: #5C5C66;
  --text-3: #8E8E99;

  --accent: #E31E32;

  --c-done: #059669;
  --c-ongoing: #2563EB;
  --c-overdue: #DC2626;
  --c-late: #D97706;
  --c-pending: #71717A;
  --c-purple: #7C3AED;

  --c-done-bg: color-mix(in srgb, var(--c-done) 10%, transparent);
  --c-ongoing-bg: color-mix(in srgb, var(--c-ongoing) 10%, transparent);
  --c-overdue-bg: color-mix(in srgb, var(--c-overdue) 10%, transparent);
  --c-late-bg: color-mix(in srgb, var(--c-late) 10%, transparent);
  --c-pending-bg: color-mix(in srgb, var(--c-pending) 10%, transparent);
  --c-purple-bg: color-mix(in srgb, var(--c-purple) 10%, transparent);

  --shadow-pop: 0 4px 12px rgba(0,0,0,.08), 0 16px 40px rgba(0,0,0,.12);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --r: 6px;
  --r-lg: 10px;

  --side-w: 232px;
  --row-h: 36px;

  --t: 120ms ease;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0C0C0E;
  --surface: #131316;
  --raised: #17171B;
  --subtle: #1D1D22;
  --border: #26262C;
  --border-strong: #35353D;

  --text-1: #F4F4F5;
  --text-2: #A0A0AB;
  --text-3: #6E6E7A;

  --accent: #F04A5C;

  --c-done: #34D399;
  --c-ongoing: #60A5FA;
  --c-overdue: #F87171;
  --c-late: #FBBF24;
  --c-pending: #8B8B96;
  --c-purple: #A78BFA;

  --c-done-bg: color-mix(in srgb, var(--c-done) 16%, transparent);
  --c-ongoing-bg: color-mix(in srgb, var(--c-ongoing) 16%, transparent);
  --c-overdue-bg: color-mix(in srgb, var(--c-overdue) 16%, transparent);
  --c-late-bg: color-mix(in srgb, var(--c-late) 16%, transparent);
  --c-pending-bg: color-mix(in srgb, var(--c-pending) 16%, transparent);
  --c-purple-bg: color-mix(in srgb, var(--c-purple) 16%, transparent);

  --shadow-pop: 0 8px 24px rgba(0,0,0,.6), 0 24px 60px rgba(0,0,0,.7);
}

/* ============================== BASE ============================== */
* { box-sizing: border-box; }

/* A class with `display` beats the UA stylesheet's [hidden], so say it here. */
[hidden] { display: none !important; }

/* One long word must never widen the page on a phone. */
.row, .row-main, .grp, .card { min-width: 0; }
.row-item, .row-note, .sheet-item { overflow-wrap: anywhere; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-size: inherit; font-weight: inherit; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; }

/* ============================== SHELL ============================== */
.app { display: flex; min-height: 100%; }

.side {
  width: var(--side-w); flex: none;
  border-right: 1px solid var(--border);
  background: var(--raised);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-top { padding: 12px 12px 8px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 6px; }
.brand-mark { width: 18px; height: 18px; }
.brand-name { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }

.side-nav { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px 12px; }
.nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-3);
  padding: 14px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 8px; border-radius: var(--r);
  color: var(--text-2); font-weight: 500;
  transition: background var(--t), color var(--t);
  cursor: pointer; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--subtle); color: var(--text-1); }
.nav-item[aria-current="true"] { background: var(--subtle); color: var(--text-1); font-weight: 600; }
.nav-item .n-txt { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .n-count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-item svg { width: 15px; height: 15px; flex: none; }

.side-foot { border-top: 1px solid var(--border); padding: 8px; }
.who {
  display: flex; align-items: center; gap: 8px; width: 100%;
  height: 34px; padding: 0 8px; border-radius: var(--r);
  color: var(--text-2); cursor: pointer; font-weight: 500;
}
.who:hover { background: var(--subtle); color: var(--text-1); }
.who .av {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
}

.side-scrim { display: none; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
}
.bar-title { font-weight: 600; font-size: 13px; flex: 1 1 auto; }
.bar-right { display: flex; align-items: center; gap: 4px; }

.status {
  font-size: 11px; font-weight: 500; color: var(--text-3);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.status[data-kind="live"] { color: var(--c-done); background: var(--c-done-bg); }
.status[data-kind="err"] { color: var(--c-overdue); background: var(--c-overdue-bg); }

.iconbtn {
  width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: var(--r); color: var(--text-2); cursor: pointer;
  transition: background var(--t), color var(--t);
}
.iconbtn:hover { background: var(--subtle); color: var(--text-1); }
.iconbtn svg { width: 15px; height: 15px; }
.i-moon { display: none; }
html[data-theme="dark"] .i-sun { display: none; }
html[data-theme="dark"] .i-moon { display: block; }
#refresh.spin svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.only-narrow { display: none; }
.view { flex: 1 1 auto; }

.seg {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--subtle); border-radius: var(--r); flex: none;
}
.seg button {
  padding: 4px 10px; border-radius: 4px; cursor: pointer;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  transition: background var(--t), color var(--t);
}
.seg button:hover { color: var(--text-1); }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--text-1); font-weight: 600;
}

/* ============================== GROUPS + ROWS ============================== */
.grp { border-bottom: 1px solid var(--border); }
.grp-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  height: 34px; padding: 0 12px; cursor: pointer;
  background: var(--raised);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 44px; z-index: 5;
}
.grp-head:hover { background: var(--subtle); }
.grp-caret { width: 12px; height: 12px; color: var(--text-3); transition: transform var(--t); flex: none; }
.grp[data-open="false"] .grp-caret { transform: rotate(-90deg); }
.grp-name { font-weight: 600; font-size: 12px; }
.grp-count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.grp[data-open="false"] .grp-body { display: none; }

.row {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--row-h); padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background var(--t);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--raised); }
.row[data-saving="1"] { opacity: .5; }
.row[data-done="1"] .row-item { color: var(--text-3); }

.mark { width: 14px; height: 14px; flex: none; }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-item {
  font-weight: 500; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-sub { display: flex; align-items: center; gap: 6px; margin-top: 1px; }
.row-meta { display: flex; align-items: center; gap: 8px; flex: none; }

.chip {
  font-size: 11px; font-weight: 500; padding: 1px 7px;
  border-radius: 999px; white-space: nowrap; flex: none;
}
.chip-out {
  font-size: 11px; font-weight: 500; padding: 1px 7px;
  border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border-strong); color: var(--text-2);
}
.who-txt { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.who-none { color: var(--text-3); font-style: normal; }

.when { font-size: 12px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.when[data-flag="overdue"] { color: var(--c-overdue); font-weight: 600; }
.when[data-flag="soon"] { color: var(--c-late); font-weight: 500; }

.row-edit {
  width: 28px; height: 28px; flex: none; border-radius: var(--r);
  display: grid; place-items: center; color: var(--text-3);
  opacity: 0; transition: opacity var(--t), background var(--t);
}
.row:hover .row-edit, .row-edit:focus-visible { opacity: 1; }
.row-edit:hover { background: var(--subtle); color: var(--text-1); }
.row-edit svg { width: 14px; height: 14px; }

/* ============================== PAGE BITS ============================== */
.pagehead {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 12px 12px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.pagehead h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
.pagehead-sub { font-size: 12px; color: var(--text-2); margin-top: 3px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pagehead-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.tiles { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tile { flex: 1 1 0; padding: 14px 12px; border-right: 1px solid var(--border); }
.tile:last-child { border-right: 0; }
.tile-n { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1;
  font-variant-numeric: tabular-nums; }
.tile-l { font-size: 12px; color: var(--text-2); margin-top: 1px; }
.tile[data-tone="bad"] .tile-n { color: var(--c-overdue); }
.tile[data-tone="warn"] .tile-n { color: var(--c-late); }
.tile[data-tone="ok"] .tile-n { color: var(--text-3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 11px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-1); font-size: 12px; font-weight: 500; cursor: pointer;
  transition: background var(--t), border-color var(--t);
}
.btn:hover { background: var(--subtle); }
.btn svg { width: 13px; height: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }

.setup {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--raised); font-size: 12px; color: var(--text-2);
}
.setup select {
  height: 30px; border-radius: var(--r); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-1); font: inherit; padding: 0 8px;
}
.setup-out { color: var(--text-2); }

.empty { padding: 40px 16px; text-align: center; color: var(--text-2); font-size: 13px; }
.empty b { display: block; color: var(--text-1); font-size: 14px; margin-bottom: 4px; font-weight: 600; }

.note { padding: 8px 12px; font-size: 12px; border-radius: var(--r); margin: 8px 12px; }
.note-warn { background: var(--c-late-bg); color: var(--c-late); }

.bigerror { padding: 28px 16px; max-width: 620px; }
.bigerror h2 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.bigerror p, .bigerror li { color: var(--text-2); margin: 0 0 8px; }
.bigerror ol { padding-left: 18px; }
.bigerror code { background: var(--subtle); padding: 1px 5px; border-radius: 4px; color: var(--text-1); }

.skel { height: 36px; border-bottom: 1px solid var(--border); position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text-3) 10%, transparent), transparent);
  transform: translateX(-100%); animation: sweep 1.3s infinite;
}
@keyframes sweep { to { transform: translateX(100%); } }

/* ============================== CALENDAR ============================== */
.cal-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.cal-title {
  font-weight: 600; font-size: 13px; min-width: 140px; text-align: center;
}
.cal-bar .btn { margin-left: 4px; }

.cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border-left: 1px solid var(--border);
}
.cal-dow {
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--text-3);
  padding: 6px 8px; background: var(--raised);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.cal-day {
  min-height: 108px; padding: 5px 6px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}
.cal-day[data-has="1"] { cursor: pointer; }
.cal-day[data-has="1"]:hover { background: var(--raised); }
.cal-day[data-muted="1"] { background: var(--subtle); }
.cal-day[data-muted="1"] .cal-n { color: var(--text-3); }
.cal-n {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.cal-day[data-today="1"] .cal-n {
  background: var(--accent); color: #fff;
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
}

.cal-items { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-item {
  display: block; width: 100%; text-align: left;
  font-size: 11px; line-height: 1.3; padding: 2px 5px;
  border-radius: 4px; cursor: pointer;
  background: var(--subtle); color: var(--text-2);
  border-left: 2px solid var(--c-pending);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-item:hover { color: var(--text-1); }
.cal-item[data-flag="overdue"] {
  border-left-color: var(--c-overdue); background: var(--c-overdue-bg);
  color: var(--c-overdue); font-weight: 500;
}
.cal-item[data-flag="soon"] { border-left-color: var(--c-late); background: var(--c-late-bg); }
.cal-item[data-flag="done"] { opacity: .55; border-left-color: var(--c-done); }
.cal-more {
  font-size: 11px; color: var(--text-3); text-align: left;
  padding: 1px 5px; cursor: pointer;
}
.cal-more:hover { color: var(--text-1); }

/* Dots stand in for the chips once a cell is too narrow to read them. */
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; }

/* ============================== EDITOR SHEET ============================== */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.35); opacity: 0; transition: opacity var(--t);
}
.sheet-scrim.open { opacity: 1; }

.sheet {
  position: fixed; z-index: 51; background: var(--surface);
  display: flex; flex-direction: column;
  top: 0; right: 0; bottom: 0; width: 420px; max-width: 100vw;
  border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 180ms ease;
  box-shadow: var(--shadow-pop);
}
.sheet.open { transform: none; }

.sheet-grab { display: none; }
.sheet-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.sheet-item { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.sheet-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 20px; }
.sheet-foot {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); display: flex; gap: 8px;
  background: var(--surface);
}
.sheet-foot .btn { flex: 1 1 auto; height: 40px; font-size: 14px; }

.field { margin-bottom: 16px; }
.field > label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 6px;
}
/* 16px on every control: anything smaller makes iOS Safari zoom on focus. */
.field input, .field select, .field textarea {
  width: 100%; font-family: var(--font); font-size: 16px;
  padding: 9px 10px; border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-1);
  min-height: 42px;
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: -1px; border-color: var(--accent);
}

.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 12px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text-2);
}
.opt:hover { background: var(--subtle); }
.opt[aria-pressed="true"] {
  border-color: currentColor; background: var(--subtle); color: var(--text-1); font-weight: 600;
}

.done-btn { width: 100%; height: 46px; font-size: 15px; margin-bottom: 18px; }

.namegrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.namegrid .opt { justify-content: center; min-height: 46px; }

.toastbar {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--text-1); color: var(--bg);
  padding: 9px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-pop); max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 10px;
}
.toastbar[data-tone="bad"] { background: var(--c-overdue); color: #fff; }
.toastbar button { font-weight: 700; text-decoration: underline; cursor: pointer; }

/* ============================== TABBAR (phones) ============================== */
.tabbar { display: none; }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 860px) {
  .side {
    position: fixed; z-index: 41; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform 180ms ease;
    box-shadow: var(--shadow-pop);
  }
  .side.open { transform: none; }
  .side-scrim {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(0,0,0,.35); opacity: 0; pointer-events: none;
    transition: opacity var(--t);
  }
  .side-scrim.open { opacity: 1; pointer-events: auto; }
  .only-narrow { display: grid; }
  .grp-head { top: 44px; }
}

@media (max-width: 900px) {
  /* Cells stop being wide enough to read a task name — switch to dots and let
     tapping the day open the list. */
  .cal-day { min-height: 62px; }
  .cal-items { display: none; }
  .cal-dots { display: flex; }
}

@media (max-width: 560px) {
  .status { display: none; }
  .bar-title { font-size: 12px; }
  .seg#viewmode button { padding: 6px 10px; font-size: 12px; }
  .cal-day { min-height: 54px; padding: 4px; }
  .cal-title { min-width: 108px; font-size: 12px; }
  .cal-dow { padding: 5px 4px; font-size: 10px; }
  .row-edit { opacity: 1; width: 40px; height: 40px; }

  /* Stack: the task name gets the full width and wraps, everything else drops
     to a second line. Truncating the name is the one thing that makes a phone
     list useless — two rows called "Omnibus Vid..." are indistinguishable. */
  .row { padding: 9px 12px; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
  .mark { margin-top: 2px; }
  /* basis 0, not auto: with auto the intrinsic width of a long title exceeds the
     line and wraps the whole block, stranding the status mark on a line alone. */
  .row-main { flex: 1 1 0; }
  .row-item { white-space: normal; overflow: visible; }
  .row-meta {
    order: 3; width: 100%; gap: 8px; padding-left: 24px;
    flex-wrap: wrap; align-items: center;
  }
  .row-edit { order: 2; margin-left: auto; margin-top: -4px; }
  .tile-n { font-size: 22px; }
  .pagehead { padding: 12px; }

  /* Bottom sheet, per the Asana iOS pattern: rounded top, drag handle,
     primary action within thumb reach. */
  .sheet {
    top: auto; right: 0; left: 0; bottom: 0; width: 100%;
    max-height: 92vh; border-left: 0;
    border-top-left-radius: 14px; border-top-right-radius: 14px;
    transform: translateY(100%);
  }
  .sheet-grab {
    display: block; width: 36px; height: 4px; border-radius: 999px;
    background: var(--border-strong); margin: 8px auto 0;
  }
  .sheet-head { padding-top: 10px; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(52px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--raised); border-top: 1px solid var(--border);
  }
  .tabbar a {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; font-size: 11px; color: var(--text-3);
    font-weight: 500;
  }
  .tabbar a[aria-current="true"] { color: var(--text-1); }
  .tabbar svg { width: 18px; height: 18px; }
  .view { padding-bottom: 64px; }
}
