:root {
  --bg: #181b34;
  --panel: #1f2240;
  --row: #2a2d48;
  --row-hover: #33375a;
  --head: #30344f;
  --line: #3d4160;
  --text: #d5d8df;
  --muted: #9699a6;
  --accent: #0073ea;
  --accent-hover: #0060c4;
  --red: #e2445c;
  --green: #00c875;
  --orange: #fdab3d;
  --empty: #4b4f6a;
  --radius: 8px;
  --task-cols: 34px minmax(220px, 1fr) 100px 140px 130px minmax(120px, 200px) 120px 40px;
  --sub-cols: 34px minmax(200px, 1fr) 100px 140px 130px 120px 40px;
  --loan-cols: 34px minmax(200px, 1fr) 130px 130px minmax(150px, 220px) 130px 110px 40px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }

/* ── Top bar ─────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 24px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(24, 27, 52, .92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 7px 14px; border-radius: 6px; color: var(--muted); font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--row); color: var(--text); }
.tab.active { background: var(--row-hover); color: #fff; }
.badge {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 9px; padding: 0 6px; min-width: 18px; line-height: 18px; text-align: center;
}
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.sync { width: 8px; height: 8px; border-radius: 50%; background: var(--green); opacity: .6; }
.sync.busy { background: var(--orange); opacity: 1; }
.sync.err { background: var(--red); opacity: 1; }
.people-stack { display: flex; align-items: center; padding: 2px; border-radius: 20px; }
.people-stack:hover { background: var(--row); }
.people-stack .av + .av { margin-left: -7px; }
.people-stack .gear { margin-left: 6px; color: var(--muted); font-size: 16px; }

main { padding: 20px 24px 80px; max-width: 1500px; }
.loading { color: var(--muted); padding: 40px 0; }

/* ── Board header & toolbar ─────────────────────────── */
.board-title { font-size: 26px; font-weight: 600; margin: 0 0 14px; color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: 6px; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--row); }
.toolbar .btn:not(.primary), .cal-head .btn { border: 1px solid var(--line); }
.pill .ph { font-weight: 400; color: #c3c6d4; }
.btn.primary { background: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.on { background: #1d3b6e; color: #cfe3ff; }
.btn .count { background: var(--accent); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; }
.search {
  height: 34px; width: 190px; padding: 0 10px 0 32px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239699a6' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 9px center;
}
.search:focus { outline: none; border-color: var(--accent); }
.person-filter { display: inline-flex; gap: 4px; align-items: center; padding: 0 4px; }
.person-filter .av { cursor: pointer; opacity: .45; transition: opacity .12s, transform .12s; }
.person-filter .av:hover { opacity: .8; }
.person-filter .av.sel { opacity: 1; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.select {
  height: 34px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px;
}

/* ── Avatars ────────────────────────────────────────── */
.av {
  width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; flex: none; letter-spacing: -.2px;
  box-shadow: 0 0 0 2px var(--row);
}
.av.sm { width: 24px; height: 24px; font-size: 10px; }
.av.empty { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); color: var(--muted); }
.avs { display: inline-flex; align-items: center; }
.avs .av + .av { margin-left: -8px; }

/* ── Groups ─────────────────────────────────────────── */
.group { margin-bottom: 34px; }
.group-head { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.group-head .chev { width: 26px; height: 26px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; }
.group-head .chev:hover { background: var(--row); }
.group-name { font-size: 18px; font-weight: 600; }
.group-name:hover { text-decoration: underline dotted; cursor: text; }
.group-count { color: var(--muted); font-size: 13px; }
.chev svg { transition: transform .15s; }
.collapsed .chev svg, .chev.closed svg { transform: rotate(-90deg); }

.table { border-left: 6px solid var(--gc, var(--accent)); border-radius: var(--radius) 0 0 var(--radius); overflow-x: auto; }
.table-inner { min-width: 900px; }
.row {
  display: grid; grid-template-columns: var(--task-cols);
  min-height: 38px; background: var(--row); border-bottom: 1px solid var(--bg);
}
.row:hover { background: var(--row-hover); }
.row.head { background: var(--head); color: var(--muted); font-size: 13px; min-height: 36px; }
.row.head:hover { background: var(--head); }
.row.head > div { justify-content: center; }
.row.head > div:nth-child(2) { justify-content: flex-start; padding-left: 10px; }
.row > div { display: flex; align-items: center; min-width: 0; border-right: 1px solid var(--bg); }
.row > div:last-child { border-right: 0; }
.row.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { background: #2c4a7d; } 100% { background: var(--row); } }
.loan-row { grid-template-columns: var(--loan-cols); }

.cell-chev { justify-content: center; }
.cell-chev button {
  width: 24px; height: 24px; border-radius: 4px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center;
}
.cell-chev button:hover { background: var(--line); color: #fff; }
.cell-chev button svg { transition: transform .15s; }
.cell-chev button.closed svg { transform: rotate(-90deg); }
.cell-chev button.nosubs { opacity: .35; }
.cell-chev button.nosubs:hover { opacity: 1; }
.ph { display: none; }
.muted { color: var(--muted); }
.cell-name { gap: 6px; padding: 0 6px 0 4px; }
.cell-name input {
  flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 4px;
  padding: 5px 6px; color: var(--text);
}
.cell-name input:hover { border-color: var(--line); }
.cell-name input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.subcount {
  font-size: 11px; color: var(--muted); background: var(--bg); border-radius: 4px; padding: 0 5px; line-height: 18px; flex: none;
}
.cell-owners { justify-content: center; }
.cell-owners button { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.pill {
  width: 100%; height: 100%; min-height: 36px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 13px; text-align: center; padding: 0 6px;
}
.pill:hover { filter: brightness(1.08); }
.pill.empty { background: var(--empty); }
.cell-date button {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px;
}
.cell-date button:hover { background: rgba(255,255,255,.04); }
.date-ico { width: 15px; height: 15px; flex: none; display: inline-flex; }
.date-late { color: #ff8094; }
.date-done { text-decoration: line-through; color: var(--muted); }
.cell-notes input {
  width: 100%; height: 100%; background: transparent; border: 0; padding: 0 10px; text-align: center; color: var(--text); font-size: 13px;
}
.cell-notes input:focus { outline: 1px solid var(--accent); background: var(--bg); text-align: left; }
.cell-notes input::placeholder { color: transparent; }
.cell-menu { justify-content: center; }
.cell-menu button { width: 28px; height: 28px; border-radius: 4px; color: var(--muted); font-size: 18px; line-height: 1; }
.cell-menu button:hover { background: var(--line); color: #fff; }
.cell-text input {
  width: 100%; height: 100%; background: transparent; border: 0; padding: 0 10px; text-align: center; color: var(--text); font-size: 13px;
}
.cell-text input:focus { outline: 1px solid var(--accent); background: var(--bg); }

.row.add { background: var(--row); }
.row.add > div { border-right: 0; }
.row.add input {
  background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 6px 6px; flex: 1; color: var(--text);
}
.row.add input::placeholder { color: var(--muted); }
.row.add input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.row.add .add-wrap { grid-column: 2 / -1; padding: 0 4px; }

.summary { display: grid; grid-template-columns: var(--task-cols); min-height: 34px; }
.summary > div { display: flex; align-items: center; padding: 0 6px; }
.sbar { display: flex; height: 20px; width: 100%; border-radius: 3px; overflow: hidden; background: var(--empty); }
.sbar i { display: block; height: 100%; }
.srange {
  font-size: 12px; background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 8px; white-space: nowrap; margin: 0 auto;
}

/* Subitems */
.subs { padding: 6px 0 14px 34px; background: var(--panel); border-bottom: 1px solid var(--bg); }
.subs .table { --gc: #579bfc; border-left-width: 3px; }
.subs .table-inner { min-width: 790px; }
.subs .row { grid-template-columns: var(--sub-cols); min-height: 36px; }
.subs .row.head { min-height: 32px; }

/* Empty state */
.empty-note { color: var(--muted); padding: 10px 12px; background: var(--row); font-size: 13px; }

/* ── Popover ────────────────────────────────────────── */
.pop {
  position: absolute; z-index: 50; min-width: 180px; max-width: 300px;
  background: #2b2e4a; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45); padding: 8px;
}
.pop h4 { margin: 4px 6px 8px; font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.pop .opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
}
.pop .opt:hover { background: var(--row-hover); }
.pop .opt.danger { color: #ff8094; }
.pop .opt.cur { background: var(--row-hover); }
.pop .chip { display: block; width: 100%; text-align: center; color: #fff; font-weight: 500; padding: 8px; border-radius: 4px; margin-bottom: 6px; }
.pop .chip:hover { filter: brightness(1.12); }
.pop .chip.cur { box-shadow: 0 0 0 2px #fff inset; }
.pop .sep { height: 1px; background: var(--line); margin: 6px 0; }
.pop .check { width: 18px; height: 18px; border-radius: 4px; border: 1.5px solid var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex: none; }
.pop .check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pop input[type="date"] {
  width: 100%; height: 38px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); padding: 0 8px; margin-bottom: 8px;
}
.pop .quick { display: flex; flex-wrap: wrap; gap: 6px; }
.pop .quick button { padding: 6px 10px; border-radius: 6px; background: var(--row); font-size: 13px; }
.pop .quick button:hover { background: var(--row-hover); }

/* ── Modal (people) ─────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; overflow-y: auto; }
.modal { background: #23264a; border: 1px solid var(--line); border-radius: 12px; width: 100%; max-width: 640px; padding: 20px; }
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.modal p.hint { color: var(--muted); margin: 0 0 16px; font-size: 13px; }
.person-row { display: grid; grid-template-columns: 34px 70px 1fr 1.4fr 40px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.person-row input[type="text"], .person-row input[type="email"] {
  height: 36px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); padding: 0 8px; width: 100%; min-width: 0;
}
.person-row input[type="color"] { width: 36px; height: 36px; border: 0; background: none; padding: 0; }
.person-row .del { color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 6px; }
.person-row .del:hover { background: var(--row-hover); color: #ff8094; }
.modal .actions { display: flex; justify-content: space-between; margin-top: 16px; }

/* ── Calendar ───────────────────────────────────────── */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-head h2 { margin: 0 8px 0 0; font-size: 22px; font-weight: 600; color: #fff; min-width: 190px; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--head); color: var(--muted); font-size: 12px; text-align: center; padding: 6px 0; }
.cal-day { background: var(--row); min-height: 112px; padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day.other { background: #232640; }
.cal-day.other .dnum { opacity: .4; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.dnum { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.cal-day.today .dnum { color: #fff; font-weight: 700; }
.ev {
  display: block; width: 100%; text-align: left; font-size: 12px; padding: 3px 6px; border-radius: 4px;
  background: var(--bg); border-left: 3px solid var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ev:hover { background: var(--row-hover); }
.ev.done { opacity: .5; text-decoration: line-through; }
.ev.late { color: #ff8094; }
.ev .k { color: var(--muted); }
.agenda { display: none; }
.agenda-day { margin: 14px 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: capitalize; }
.agenda .ev { font-size: 14px; padding: 10px 12px; margin-bottom: 4px; white-space: normal; }
.cal-toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-left: auto; }

/* ── Toast ──────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #33375a; border: 1px solid var(--line); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 80;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #5b2030; border-color: #a33; }

/* ── Phone ──────────────────────────────────────────── */
@media (max-width: 760px) {
  .top { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); gap: 6px; }
  .tabs { flex: 1; min-width: 0; }
  .tab { flex: 1; justify-content: center; padding: 8px 4px; gap: 4px; }
  .top-right { gap: 6px; }
  .people-stack .av:nth-child(n+3) { display: none; }
  main { padding: 14px 10px 90px; }
  .board-title { font-size: 21px; margin-bottom: 10px; }
  .toolbar { gap: 6px; }
  .search { flex: 1 1 100%; width: auto; height: 40px; }
  .btn { height: 38px; }

  .table { overflow: visible; border-left-width: 4px; }
  .table-inner, .subs .table-inner { min-width: 0; }
  .row.head { display: none; }
  .row, .subs .row {
    grid-template-columns: 30px 1fr 1fr 36px;
    grid-template-areas:
      "chev name name menu"
      ".    status due owners"
      ".    prio  notes notes";
    padding: 6px 4px 8px; gap: 6px 6px; border-bottom: 1px solid var(--bg);
  }
  .row > div { border-right: 0; }
  .cell-chev { grid-area: chev; }
  .cell-name { grid-area: name; padding: 0; }
  .cell-name input { font-size: 16px; font-weight: 500; padding: 6px 4px; }
  .cell-menu { grid-area: menu; }
  .cell-status { grid-area: status; }
  .cell-date { grid-area: due; }
  .cell-owners { grid-area: owners; justify-content: flex-end; }
  .cell-owners button { width: auto; }
  .cell-prio { grid-area: prio; }
  .cell-notes { grid-area: notes; }
  .pill { min-height: 32px; border-radius: 6px; }
  .cell-date button { background: var(--bg); border-radius: 6px; min-height: 32px; }
  .ph { display: inline; color: var(--muted); }
  .cell-notes input { background: var(--bg); border-radius: 6px; min-height: 32px; text-align: left; font-size: 16px; }
  .cell-notes input::placeholder { color: var(--muted); }
  .subs .row {
    grid-template-areas:
      "chev name name menu"
      ".    status due owners"
      ".    prio  prio .";
  }
  .subs { padding: 4px 0 10px 12px; }
  .row.add { grid-template-columns: 30px 1fr; grid-template-areas: none; padding: 4px; }
  .row.add .add-wrap { grid-column: 2; }
  .row.add input { font-size: 16px; }
  .summary { display: none; }

  .loan-row {
    grid-template-columns: 30px 1fr 1fr 36px;
    grid-template-areas:
      "chev name name menu"
      ".    status due owners"
      ".    borrowed contact contact";
  }
  .loan-row .cell-borrowed { grid-area: borrowed; }
  .loan-row .cell-contact { grid-area: contact; }
  .cell-text input { background: var(--bg); border-radius: 6px; min-height: 32px; text-align: left; font-size: 16px; }

  .pop { position: fixed; left: 8px !important; right: 8px; top: auto !important; bottom: max(8px, env(safe-area-inset-bottom)); max-width: none; padding: 12px; }
  .pop .opt { padding: 12px; font-size: 16px; }
  .pop .chip { padding: 12px; font-size: 16px; }

  .cal-grid { display: none; }
  .agenda { display: block; }
  .cal-head h2 { font-size: 19px; min-width: 0; flex: 1 1 100%; }

  .person-row { grid-template-columns: 30px 60px 1fr 36px 32px; }
  .person-row { margin-bottom: 14px; }
  .person-row .email { grid-column: 1 / -1; order: 10; }
  .modal-back { padding: 16px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
