:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f2f4;
  --list-bg: #f1f2f4;
  --card-bg: #ffffff;
  --text: #172b4d;
  --muted: #626f86;
  --border: #dcdfe4;
  --accent: #0c66e4;
  --accent-text: #ffffff;
  --hover: rgba(9, 30, 66, 0.08);
  --shadow: 0 1px 1px rgba(9, 30, 66, 0.2), 0 0 1px rgba(9, 30, 66, 0.3);
  --overlay: rgba(9, 30, 66, 0.55);
  --danger: #c9372c;
  --ok: #1f845a;
  --warn: #b38600;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d2125;
    --surface: #22272b;
    --surface-2: #2c333a;
    --list-bg: #101204;
    --card-bg: #22272b;
    --text: #b6c2cf;
    --muted: #8c9bab;
    --border: #38414a;
    --accent: #579dff;
    --accent-text: #1d2125;
    --hover: rgba(166, 197, 226, 0.12);
    --shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
    --overlay: rgba(0, 0, 0, 0.6);
    --danger: #f87168;
    --ok: #4bce97;
    --warn: #f5cd47;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1d2125;
  --surface: #22272b;
  --surface-2: #2c333a;
  --list-bg: #101204;
  --card-bg: #22272b;
  --text: #b6c2cf;
  --muted: #8c9bab;
  --border: #38414a;
  --accent: #579dff;
  --accent-text: #1d2125;
  --hover: rgba(166, 197, 226, 0.12);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
  --overlay: rgba(0, 0, 0, 0.6);
  --danger: #f87168;
  --ok: #4bce97;
  --warn: #f5cd47;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

#app { height: 100%; display: flex; flex-direction: column; }
.loading { margin: auto; color: var(--muted); }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--surface-2);
  cursor: pointer;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { background: var(--danger); color: #fff; }
button.icon { background: transparent; padding: 4px 8px; font-size: 16px; line-height: 1; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="text"], input[type="search"], input[type="password"], input[type="date"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}
textarea { resize: vertical; width: 100%; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 6px; padding-right: 8px; }
.brand img { width: 22px; height: 22px; }
.nav { color: var(--text); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav:hover { background: var(--hover); }
.nav.active { background: var(--hover); font-weight: 600; }
.topbar .search { width: 220px; max-width: 40vw; }

/* -------------------------------------------------------------- board bar */

.board-page { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--board-bg, var(--bg)); }
.board-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.18);
  color: #fff;
}
.board-bar button, .board-bar .board-name { color: #fff; }
/* Buttons that sit directly on the coloured board background. */
.board-bar button, .cal-head button, .tl-toolbar button, .filter-bar > button { background: rgba(255, 255, 255, 0.16); color: #fff; }
.board-bar button:hover, .cal-head button:hover, .tl-toolbar button:hover, .filter-bar > button:hover { background: rgba(255, 255, 255, 0.28); }
.board-bar button.active, .tl-toolbar button.active { background: #fff; color: #172b4d; }
.board-name { font-size: 18px; font-weight: 700; padding: 4px 8px; border-radius: 6px; cursor: text; }
.board-name:hover { background: rgba(255, 255, 255, 0.16); }
.view-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.12);
  color: #fff;
}
.filter-bar input[type="search"] { width: 180px; }
.filter-bar select, .filter-bar input[type="search"] { color: var(--text); }
.chip-toggle {
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #172b4d;
  opacity: 0.55;
}
.chip-toggle.on { opacity: 1; box-shadow: 0 0 0 2px #fff; }

.view { flex: 1; min-height: 0; overflow: auto; }
.view-board, .view-timeline { overflow: hidden; }

/* ----------------------------------------------------------------- kanban */

.kanban {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
}
.list {
  flex: 0 0 272px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--list-bg);
  border-radius: 12px;
  scroll-snap-align: start;
}
.list.dragging { opacity: 0.4; }
.list.drop-before { box-shadow: -6px 0 0 -2px #fff; }
.list-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px 12px; cursor: grab; }
.list-title { font-weight: 600; flex: 1; padding: 4px 6px; border-radius: 6px; cursor: text; overflow-wrap: anywhere; }
.list-head .count { color: var(--muted); font-size: 12px; }
.list-cards { padding: 4px 8px; overflow-y: auto; min-height: 12px; display: flex; flex-direction: column; gap: 8px; }
.add-card, .add-list-btn {
  margin: 4px 8px 8px;
  text-align: left;
  background: transparent;
  color: var(--muted);
}
.add-list {
  flex: 0 0 272px;
  background: rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  padding: 8px;
}
.add-list .add-list-btn { margin: 0; width: 100%; color: #fff; }

.card {
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
}
.card:hover { border-color: var(--accent); }
.card.dragging { opacity: 0.35; }
.card .cover { margin: -8px -10px 8px; height: 32px; }
.card-title { overflow-wrap: anywhere; padding-right: 18px; }
.card.done .card-title { color: var(--muted); }
.card .tick {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  background: transparent;
  padding: 0;
  opacity: 0;
}
.card:hover .tick, .card.done .tick { opacity: 1; }
.card.done .tick { background: var(--ok); border-color: var(--ok); }
.card.done .tick::after { content: "✓"; color: #fff; font-size: 11px; position: absolute; inset: 0; line-height: 13px; }
.card .cover + .tick, .card .cover ~ .tick { top: 48px; }
.placeholder { height: 36px; border-radius: 8px; background: var(--hover); border: 2px dashed var(--border); }

.labels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.label {
  display: inline-block;
  min-width: 40px;
  height: 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #172b4d;
  line-height: 16px;
}
.labels.named .label { height: 16px; padding: 0 6px; }
.label-pill { display: inline-block; border-radius: 4px; padding: 0 6px; font-size: 12px; font-weight: 600; color: #172b4d; line-height: 20px; }

.badges { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 3px; border-radius: 4px; padding: 1px 4px; }
.badge.due.overdue { background: var(--danger); color: #fff; }
.badge.due.soon { background: #f5cd47; color: #172b4d; }
.badge.due.done { background: var(--ok); color: #fff; }
.badge.complete { color: var(--ok); }

.composer textarea { min-height: 60px; border-radius: 8px; box-shadow: var(--shadow); border: 0; background: var(--card-bg); }
.composer { padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.add-list .composer { padding: 0; }
.add-list .composer input { width: 100%; }

/* -------------------------------------------------------------- list mode */

.list-mode { max-width: 860px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.lm-section { background: var(--surface); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.lm-section h3 { margin: 0 0 8px; font-size: 15px; display: flex; gap: 8px; align-items: baseline; }
.lm-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-top: 1px solid var(--border); cursor: pointer; }
.lm-row:first-of-type { border-top: 0; }
.lm-row:hover { background: var(--hover); }
.lm-row .title { flex: 1; overflow-wrap: anywhere; }
.lm-row.done .title { text-decoration: line-through; color: var(--muted); }
.lm-row .dots { display: flex; gap: 3px; }
.lm-row .dot { width: 10px; height: 10px; border-radius: 50%; }
.lm-add { width: 100%; margin-top: 6px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--ok); cursor: pointer; margin: 0; }

/* ------------------------------------------------------------------ table */

.table-wrap { padding: 12px; }
table.cards-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cards-table th, .cards-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.cards-table th { font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; background: var(--surface-2); }
.cards-table th .arrow { opacity: 0.7; }
.cards-table tr:hover td { background: var(--hover); }
.cards-table td.title { font-weight: 500; cursor: pointer; min-width: 200px; }
.cards-table tr.done td.title { color: var(--muted); text-decoration: line-through; }
.cards-table input[type="date"], .cards-table select { padding: 3px 4px; }

/* --------------------------------------------------------------- calendar */

.calendar { display: flex; height: 100%; min-height: 520px; }
.cal-main { flex: 1; display: flex; flex-direction: column; padding: 12px; gap: 8px; min-width: 0; }
.cal-head { display: flex; align-items: center; gap: 8px; color: #fff; }
.cal-head h2 { margin: 0; font-size: 18px; min-width: 170px; }
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto repeat(6, minmax(96px, 1fr)); gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--surface-2); padding: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
.cal-grid .cal-dow-row { display: contents; }
.cal-day { background: var(--surface); padding: 4px; display: flex; flex-direction: column; gap: 3px; min-height: 0; overflow: hidden; position: relative; }
.cal-day.other { background: var(--surface-2); }
.cal-day.today .num { background: var(--accent); color: var(--accent-text); border-radius: 50%; }
.cal-day.drop { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day .num { font-size: 12px; width: 22px; height: 22px; display: grid; place-items: center; }
.cal-day .add { position: absolute; top: 2px; right: 2px; padding: 0 6px; opacity: 0; background: transparent; }
.cal-day:hover .add { opacity: 1; }
.cal-chip { font-size: 12px; border-radius: 4px; padding: 2px 6px; background: var(--surface-2); border-left: 4px solid var(--accent); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip.done { text-decoration: line-through; opacity: 0.7; }
.cal-chip.overdue { border-left-color: var(--danger); }
.cal-side { width: 230px; padding: 12px; background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; }
.cal-side h3 { margin: 4px 0 8px; font-size: 13px; }
.cal-side .cal-chip { margin-bottom: 4px; }

/* --------------------------------------------------------------- timeline */

.timeline-wrap { display: flex; flex-direction: column; height: 100%; }
.tl-toolbar { display: flex; gap: 6px; align-items: center; padding: 8px 12px; color: #fff; flex-wrap: wrap; }
.timeline { flex: 1; overflow: auto; position: relative; background: var(--surface); margin: 0 12px 12px; border-radius: var(--radius); box-shadow: var(--shadow); }
.tl-grid { position: relative; }
.tl-row { display: flex; height: 34px; border-bottom: 1px solid var(--border); }
.tl-row.group { height: 30px; background: var(--surface-2); font-weight: 600; }
.tl-name { position: sticky; left: 0; z-index: 3; width: 240px; flex: 0 0 240px; background: var(--surface); border-right: 1px solid var(--border); padding: 0 10px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.tl-row.group .tl-name { background: var(--surface-2); cursor: default; }
.tl-name span.t { overflow: hidden; text-overflow: ellipsis; }
.tl-track { position: relative; flex: 0 0 auto; cursor: crosshair; }
.tl-header { position: sticky; top: 0; z-index: 4; background: var(--surface); }
.tl-header .tl-row { height: auto; }
.tl-header .tl-name { z-index: 5; font-size: 12px; color: var(--muted); }
.tl-scale { position: relative; height: 44px; }
.tl-month { position: absolute; top: 2px; font-size: 12px; font-weight: 600; padding-left: 4px; border-left: 1px solid var(--border); height: 20px; white-space: nowrap; }
.tl-day { position: absolute; top: 22px; font-size: 11px; color: var(--muted); text-align: center; height: 22px; line-height: 22px; }
.tl-day.weekend { background: var(--hover); }
.tl-day.is-today { color: var(--accent); font-weight: 700; }
.tl-bar {
  position: absolute;
  top: 6px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  line-height: 22px;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: var(--shadow);
}
.tl-bar.done { opacity: 0.55; }
.tl-bar.overdue { background: var(--danger); }
.tl-bar .grip { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }
.tl-bar .grip.l { left: 0; }
.tl-bar .grip.r { right: 0; }
.tl-ghost { position: absolute; top: 6px; height: 22px; border-radius: 6px; background: var(--hover); border: 2px dashed var(--accent); pointer-events: none; }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.tl-hint { font-size: 12px; color: var(--muted); padding-left: 8px; pointer-events: none; line-height: 34px; }

/* -------------------------------------------------------------- dashboard */

.dashboard { padding: 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-content: start; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tile h3 { margin: 0 0 12px; font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; grid-column: 1 / -1; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 32px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 7px; background: var(--accent); }
.bar-row .v { text-align: right; color: var(--muted); }

/* ---------------------------------------------------------------- home */

.home { padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; overflow-y: auto; }
.home h2 { font-size: 16px; margin: 24px 0 12px; }
.board-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.board-tile { height: 96px; border-radius: var(--radius); padding: 10px 12px; color: #fff; font-weight: 700; text-decoration: none; display: flex; align-items: flex-start; box-shadow: var(--shadow); background: #0c66e4; position: relative; }
.board-tile:hover { filter: brightness(1.1); }
.board-tile.new { background: var(--surface-2); color: var(--text); font-weight: 500; align-items: center; justify-content: center; border: 0; }
.board-tile .meta { position: absolute; bottom: 8px; left: 12px; font-weight: 400; font-size: 12px; opacity: 0.85; }

/* --------------------------------------------------------------- planner */

.planner { max-width: 860px; margin: 0 auto; padding: 16px; width: 100%; overflow-y: auto; }
.planner h1 { font-size: 22px; margin: 4px 0 12px; }
.quick-add { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; background: var(--surface); padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow); }
.quick-add input[type="text"] { flex: 1; min-width: 200px; }
.bucket { margin-bottom: 18px; }
.bucket h2 { font-size: 14px; margin: 0 0 6px; display: flex; gap: 8px; align-items: baseline; }
.bucket h2.overdue { color: var(--danger); }
.bucket .lm-section { padding: 4px 12px; }
.where { font-size: 12px; color: var(--muted); white-space: nowrap; }
.where .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }

/* ----------------------------------------------------------------- modal */

.overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; z-index: 50; }
.dialog { background: var(--surface); border-radius: 12px; width: min(768px, 100%); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35); position: relative; overflow: hidden; }
.dialog.narrow { width: min(440px, 100%); }
.dialog .cover-strip { height: 80px; }
.dialog-body { padding: 16px 20px 20px; }
.dialog .close { position: absolute; top: 8px; right: 8px; z-index: 2; }
.card-title-input { font-size: 20px; font-weight: 600; width: calc(100% - 40px); border: 0; background: transparent; resize: none; padding: 4px 6px; border-radius: 6px; overflow: hidden; }
.card-title-input:focus { background: var(--surface-2); }
.card-layout { display: grid; grid-template-columns: 1fr 180px; gap: 20px; margin-top: 12px; }
.card-layout .side { display: flex; flex-direction: column; gap: 6px; }
.card-layout .side button { text-align: left; }
.section { margin-bottom: 20px; }
.section h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.md { overflow-wrap: anywhere; }
.md:empty::before { content: "Add a more detailed description…"; color: var(--muted); }
.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.md-view { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; cursor: text; min-height: 56px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; flex: 1; }
.progress > div { height: 100%; background: var(--accent); }
.progress.full > div { background: var(--ok); }
.check-item { display: flex; align-items: center; gap: 8px; padding: 4px 4px; border-radius: 6px; }
.check-item:hover { background: var(--hover); }
.check-item .t { flex: 1; overflow-wrap: anywhere; }
.check-item.done .t { text-decoration: line-through; color: var(--muted); }
.check-item .x { opacity: 0; }
.check-item:hover .x { opacity: 1; }
.comment { padding: 8px 10px; background: var(--surface-2); border-radius: 8px; margin-bottom: 8px; }
.comment .meta { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 32px; height: 24px; border-radius: 4px; border: 2px solid transparent; padding: 0; }
.swatch.on { border-color: var(--text); }
.label-toggle { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: transparent; padding: 4px; }
.label-toggle .label-pill { flex: 1; min-height: 24px; }

/* -------------------------------------------------------------- popovers */

.popover { position: fixed; z-index: 60; background: var(--surface); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); padding: 6px; min-width: 200px; max-width: 320px; }
.popover .item { display: block; width: 100%; text-align: left; background: transparent; padding: 7px 10px; }
.popover .item.danger { color: var(--danger); }
.popover h5 { margin: 4px 8px 8px; font-size: 12px; color: var(--muted); text-align: center; }
.popover hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #172b4d; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 70; max-width: 90vw; }
#toast.show { opacity: 1; }

.login { margin: auto; background: var(--surface); padding: 28px; border-radius: 12px; box-shadow: var(--shadow); width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 20px; }

.empty { color: var(--muted); padding: 24px; text-align: center; }

@media (max-width: 700px) {
  .topbar .search { width: 100%; max-width: none; order: 10; }
  .card-layout { grid-template-columns: 1fr; }
  .cal-side { display: none; }
  .cal-grid { grid-template-rows: auto repeat(6, minmax(70px, 1fr)); }
  .cal-chip { font-size: 10px; padding: 1px 3px; }
  .tl-name { width: 140px; flex-basis: 140px; }
  .overlay { padding: 0; }
  .dialog { border-radius: 0; min-height: 100%; }
  .list { flex-basis: 85vw; }
}

/* ================================================================ studio */

:root {
  --studio: linear-gradient(120deg, #7c3aed, #c026d3 55%, #db2777);
  --st-new: #8b5cf6; --st-scheduled: #3b82f6; --st-confirmed: #16a34a; --st-rescheduled: #ea580c;
  --st-cancelled: #dc2626; --st-completed: #64748b; --st-no-show: #a8a29e;
}
input[type="email"], input[type="tel"], input[type="url"], input[type="number"], input[type="time"] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
.grow { flex: 1; min-width: 0; }
.prewrap { white-space: pre-wrap; }
.clip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dim { opacity: 0.55; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }
.empty { padding: 24px 0; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.nbadge { background: var(--st-new); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 0 6px; margin-left: auto; }

.studio { flex: 1; display: flex; min-height: 0; }
.snav { width: 210px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.snav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.snav-logo { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 10px; background: var(--studio); color: #fff; font-size: 18px; flex-shrink: 0; }
.snav-logo.small { width: 24px; height: 24px; font-size: 13px; border-radius: 7px; }
.snav-logo.big { width: 64px; height: 64px; font-size: 32px; border-radius: 18px; margin: 0 auto; }
.snav-name { font-weight: 700; line-height: 1.2; }
.snav-item { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.snav-item:hover { background: var(--hover); }
.snav-item.active { background: var(--studio); color: #fff; }
.spage { flex: 1; overflow-y: auto; padding: 22px 26px 60px; min-width: 0; }
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.phead h2 { margin: 0; font-size: 22px; }
.phead p { margin: 4px 0 0; }
.toolbar { margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button { background: transparent; }
.seg button.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats.three { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; color: var(--text); text-decoration: none; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat.warn .stat-value { color: var(--danger); }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.panels .panel { margin-bottom: 0; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }

.avatar { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  background: color-mix(in srgb, #a855f7 16%, var(--surface)); color: #9333ea; font-weight: 700; }
.avatar.big { width: 44px; height: 44px; border-radius: 12px; font-size: 18px; }
.lrow { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.lrow:last-child { border-bottom: 0; }
.lrow-main { flex: 1; min-width: 150px; }
.lrow { flex-wrap: wrap; }
.lrow-title { font-weight: 600; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 2px 8px; border-radius: 99px; white-space: nowrap;
  background: color-mix(in srgb, var(--c, #888) 16%, var(--surface)); color: var(--c, var(--muted)); }
.st-new { --c: var(--st-new); } .st-scheduled { --c: var(--st-scheduled); } .st-confirmed { --c: var(--st-confirmed); }
.st-rescheduled { --c: var(--st-rescheduled); } .st-cancelled { --c: var(--st-cancelled); } .st-completed { --c: var(--st-completed); }
.st-no-show { --c: var(--st-no-show); }
.st-active { --c: var(--st-confirmed); } .st-prospect { --c: var(--st-new); } .st-paused { --c: var(--st-completed); } .st-former { --c: var(--st-no-show); }
.inv-paid { --c: var(--st-confirmed); } .inv-unpaid { --c: var(--warn); } .inv-overdue { --c: var(--st-cancelled); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.status-select { color: var(--c); font-weight: 600; }

/* calendar */
.scal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 15px; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.wk { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.wk-inner { min-width: 720px; }
.wk-headrow, .wk-body { display: flex; }
.wk-gutter { width: 56px; flex-shrink: 0; position: relative; }
.wk-dayhead { flex: 1; text-align: center; padding: 8px 0; border-left: 1px solid var(--border); display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.wk-dayhead strong { font-size: 18px; color: var(--text); }
.wk-dayhead.today strong { color: #c026d3; }
.wk-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.wk-hour:first-child { transform: none; }
.wk-cols { flex: 1; display: flex; border-top: 1px solid var(--border); }
.wk-col { flex: 1; position: relative; border-left: 1px solid var(--border); cursor: copy;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), var(--border) calc(var(--hour) - 1px), var(--border) var(--hour)); }
.wk-col.today { background-color: color-mix(in srgb, #c026d3 4%, transparent); }
.wk-col.off { background-color: var(--surface-2); }
.wk-off { position: absolute; inset: 4px 4px auto; font-size: 11px; color: var(--muted); text-align: center; }
.wk-avail { position: absolute; left: 0; right: 0; background: color-mix(in srgb, #16a34a 9%, transparent); border-left: 3px solid color-mix(in srgb, #16a34a 45%, transparent); }
.wk-lesson { position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 2px 6px; font-size: 11px; line-height: 1.25; overflow: hidden; cursor: grab; z-index: 2;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c); color: var(--text); display: flex; flex-direction: column; touch-action: none; user-select: none; }
.wk-lesson > * { flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk-lesson.short { flex-direction: row; gap: 4px; align-items: center; }
.wk-lesson.short > span { opacity: 0.8; }
.wk-lesson.st-cancelled, .wk-lesson.st-no-show { opacity: 0.55; text-decoration: line-through; }
.wk-lesson.dragging { z-index: 5; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); cursor: grabbing; overflow: visible; }
.wk-tip { position: absolute; left: 0; top: -22px; background: var(--text); color: var(--surface); padding: 2px 6px; border-radius: 4px; white-space: nowrap; font-size: 11px; }
.mo { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.mo-head { padding: 6px; font-size: 11px; color: var(--muted); text-align: center; border-bottom: 1px solid var(--border); }
.mo-cell { min-height: 96px; padding: 4px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; cursor: copy; min-width: 0; }
.mo-cell.other { background: var(--surface-2); }
.mo-cell.off { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, transparent 6px, transparent 12px); }
.mo-cell.today .mo-date { color: #c026d3; font-weight: 700; }
.mo-cell.drop { outline: 2px solid #c026d3; outline-offset: -2px; }
.mo-date { font-size: 12px; }
.mo-chip { font-size: 11px; padding: 1px 5px; border-radius: 4px; background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: grab; }
.sched-day h4 { margin: 18px 0 4px; }
.sched-time { width: 92px; flex-shrink: 0; font-weight: 600; font-size: 13px; }
.sched .lrow, .portal .lrow { background: var(--surface); border-radius: 8px; padding: 10px 12px; margin-bottom: 6px; border: 0; box-shadow: var(--shadow); }

/* forms and sheets */
.sheet-title { margin: 0 0 14px; padding-right: 30px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form h4 { margin: 8px 0 0; font-size: 13px; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld input, .fld select, .fld textarea { width: 100%; }
.fld-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.grid2, .grid3 { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.sheet-buttons { margin-top: 16px; }
.pick-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0; }
.pick-list.tall { max-height: 300px; }
.pick-list.disabled { opacity: 0.4; pointer-events: none; }
.pick { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.pick:last-child { border-bottom: 0; }
.total-row { font-size: 16px; padding: 4px 2px; }
.callout { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; }
.callout.good { background: color-mix(in srgb, #16a34a 14%, var(--surface)); }
.callout ol { margin: 6px 0; padding-left: 20px; }
code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; font-size: 12px; word-break: break-all; }

/* students, locations */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.scard { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; }
.scard:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); }
.scard-top { display: flex; gap: 12px; align-items: center; }
.scard-name { font-weight: 700; font-size: 15px; }
.scard-lines { display: flex; flex-direction: column; gap: 3px; font-size: 13px; overflow-wrap: anywhere; }
.scard-foot { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; align-items: center; }
.loc-note { background: var(--surface-2); border-radius: 6px; padding: 6px 8px; font-size: 12px; font-style: italic; }

/* availability */
.av-day { display: flex; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.av-day:last-child { border-bottom: 0; }
.av-name { width: 100px; font-weight: 600; padding-top: 6px; }
.av-rows { display: flex; flex-direction: column; gap: 6px; flex: 1; align-items: flex-start; }

/* invoices */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel .table-wrap { box-shadow: none; }
.stable { width: 100%; border-collapse: collapse; }
.stable th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.stable td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.stable tbody tr { cursor: pointer; }
.stable tbody tr:hover { background: var(--hover); }
.stable tr:last-child td { border-bottom: 0; }
.invoice-paper { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 26px; background: var(--surface); }
.inv-top { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid var(--border); padding-bottom: 14px; }
.inv-top h2 { margin: 0; }
.inv-num { text-align: right; }
.inv-word { font-size: 22px; font-weight: 300; text-transform: uppercase; letter-spacing: 0.1em; }
.inv-meta { display: flex; justify-content: space-between; gap: 16px; margin: 16px 0; flex-wrap: wrap; }
.inv-lines { width: 100%; border-collapse: collapse; }
.inv-lines th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border); padding: 6px 4px; }
.inv-lines td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.inv-lines th:last-child, .inv-lines td:last-child { text-align: right; }
.inv-total { display: flex; justify-content: flex-end; gap: 24px; font-size: 18px; padding: 12px 4px; }
.inv-paid { color: var(--st-confirmed); font-weight: 700; text-align: right; }
.inv-pay { margin-top: 14px; font-size: 13px; }

/* messages */
.msg-layout { display: grid; grid-template-columns: 260px 1fr; gap: 14px; height: calc(100vh - 210px); min-height: 380px; }
.msg-people { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; }
.msg-person { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: transparent; border-radius: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; }
.msg-person.active { background: var(--hover); }
.msg-thread { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; padding: 0 14px; }
.msg-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--border); }
.msg-list { flex: 1; overflow-y: auto; padding: 12px 0; display: flex; flex-direction: column; gap: 10px; }
.bubble { align-self: flex-end; max-width: 80%; background: var(--studio); color: #fff; border-radius: 14px 14px 2px 14px; padding: 9px 13px; }
.bubble.note { background: var(--surface-2); color: var(--text); }
.bubble-subject { font-weight: 700; margin-bottom: 3px; }
.bubble-meta { font-size: 11px; opacity: 0.8; margin-top: 4px; }
.msg-compose { display: flex; flex-direction: column; gap: 6px; padding: 10px 0 14px; border-top: 1px solid var(--border); }

/* resources */
.res-list { display: flex; flex-direction: column; gap: 8px; }
.res-row, .res-card { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.res-card { flex-direction: column; align-items: stretch; margin-bottom: 10px; }
.res-card audio, .res-card video { width: 100%; max-height: 60vh; border-radius: 8px; }
.res-icon { font-size: 22px; width: 32px; text-align: center; flex-shrink: 0; }
.drop-hint { display: none; border: 2px dashed #c026d3; border-radius: var(--radius); padding: 26px; text-align: center; margin-bottom: 12px; color: #c026d3; }
.dropping .drop-hint { display: block; }
.upbar { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.upbar progress { flex: 1; }

/* student portal and login */
.portal-bar { background: var(--surface); }
.portal { flex: 1; overflow-y: auto; padding: 22px 16px 60px; width: 100%; max-width: 760px; margin: 0 auto; }
.portal h2 { margin: 0 0 4px; }
.week-nav { justify-content: space-between; margin: 16px 0 6px; }
.slot-days { display: flex; flex-direction: column; gap: 4px; }
.slot-day h4 { margin: 12px 0 6px; }
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.slot { background: var(--surface); box-shadow: var(--shadow); padding: 10px 6px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.slot:hover { background: var(--studio); color: #fff; }
.slot .small { font-weight: 400; opacity: 0.8; }
.policy { margin-top: 20px; }
.login .col { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.studio-login { text-align: center; padding: 34px 28px; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--studio); color: #fff; text-decoration: none; font-weight: 700; padding: 12px; border-radius: 10px; }
.google-btn .g { background: #fff; color: #4285f4; font-weight: 800; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.studio-login details { text-align: left; margin-top: 8px; }
.studio-login summary { cursor: pointer; text-align: center; }

@media (max-width: 760px) {
  .studio { flex-direction: column; }
  .snav { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--border); padding: 6px; overflow-x: auto; flex-shrink: 0; }
  .snav-brand { display: none; }
  .snav-item { white-space: nowrap; padding: 6px 10px; }
  .spage { padding: 16px 16px 60px; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .msg-layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .msg-people { max-height: 200px; }
  .msg-thread { min-height: 420px; }
  .av-day { flex-direction: column; gap: 6px; }
  .mo-cell { min-height: 70px; }
  .mo-chip { font-size: 10px; }
  .hide-narrow { display: none; }
  .panels { grid-template-columns: minmax(0, 1fr); }
  .invoice-paper { padding: 16px; }
}

@media print {
  #app, #toast, .overlay:not(.print-root), .no-print, .print-root .close, .print-root .sheet-title { display: none !important; }
  .print-root { position: static; background: none; padding: 0; overflow: visible; }
  .print-root .dialog { box-shadow: none; width: 100%; }
  .invoice-paper { border: 0; }
  html, body { background: #fff; height: auto; }
}
.slot-none { margin: 12px 0 0; }
