:root {
  color-scheme: light dark;
  --bg: #f5f4f1;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6c6c72;
  --line: #e3e1dc;
  --accent: #2f5bea;
  --accent-soft: #e9eefe;
  --on-accent: #ffffff;
  --red: #c4362c;
  --red-soft: #fdecea;
  --amber: #9a6200;
  --amber-soft: #fff3d6;
  --ev: #7146d1;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --panel: #1c1c1f;
    --ink: #ececef;
    --muted: #9a9aa3;
    --line: #2d2d32;
    --accent: #7c9cff;
    --accent-soft: #1f2743;
    --on-accent: #10131c;
    --red: #ff6f64;
    --red-soft: #3a1d1b;
    --amber: #f0b54a;
    --amber-soft: #382a10;
    --ev: #b39aff;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
input, select {
  font: inherit;
  color: var(--ink);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- layout: two equal columns, stacked on narrow screens ---------- */
.app {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 8px;
  align-items: start;
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; padding: 12px 10px 8px; gap: 12px; }
}
.col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  min-width: 0;
}
@media (max-width: 820px) { .col { padding: 14px; } }
.col-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 17px; margin-bottom: 12px; }
.sub { color: var(--muted); font-size: 13px; }

/* ---------- controls ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span, .seg button {
  display: block; padding: 6px 10px; font-size: 13px; cursor: pointer;
  background: none; border: 0; color: var(--muted); white-space: nowrap;
}
.seg input:checked + span, .seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
button.primary {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 8px;
  padding: 7px 14px; font-weight: 600; cursor: pointer;
}
button.ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button.danger { background: none; border: 1px solid var(--red); color: var(--red); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.link { background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; color: inherit; }

.plus {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font-size: 22px; line-height: 1; padding: 0;
  transition: transform 0.15s;
}
.plus.on { transform: rotate(45deg); background: var(--muted); }
.quick-add {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.quick-add[hidden] { display: none; }
.quick-add input { background: var(--panel); }
.quick-add .seg { align-self: flex-start; background: var(--panel); flex-wrap: wrap; }
.qa-row { display: flex; flex-wrap: wrap; gap: 10px; }
.mini { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1 1 150px; }
.mini[hidden] { display: none; }
.quick-add .hint { margin: 0; }

/* ---------- blocks on the today side ---------- */
.block { margin-bottom: 16px; }
.block-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 0 0 6px;
}
.count { font-variant-numeric: tabular-nums; background: var(--bg); border-radius: 20px; padding: 0 8px; font-size: 12px; font-weight: 600; }
.must { border-left: 3px solid var(--accent); padding-left: 12px; }
.must > .block-head { color: var(--accent); }
.missed-block { border-left: 3px solid var(--red); padding-left: 12px; }
.missed-block > .block-head { color: var(--red); }
.appts { border-left: 3px solid var(--ev); padding-left: 12px; }
.appts > .block-head { color: var(--ev); }

.items, .events, .dues, .history-list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 2px; border-bottom: 1px solid var(--line); min-height: 40px;
}
.item:last-child { border-bottom: 0; }
.item[draggable="true"] { cursor: grab; }
.item.dragging { opacity: 0.35; }
.check {
  flex: none; width: 20px; height: 20px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--muted); border-radius: 6px; background: none;
}
.check:hover { border-color: var(--accent); background: var(--accent-soft); }
.text {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0;
  cursor: pointer; overflow-wrap: anywhere;
}
.text:hover { text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 3px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; flex: none; max-width: 50%; }
.chip { font-size: 11.5px; padding: 1px 7px; border-radius: 20px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.chip.exp { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--amber-soft); color: var(--amber); }
.chip.late { background: var(--red-soft); color: var(--red); font-weight: 600; }
.chip.dl { background: none; border: 1px solid var(--line); color: var(--ink); font-weight: 600; }
.chip.dl.warn { border-color: var(--amber); background: var(--amber-soft); color: var(--amber); }
.chip.dl.late { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.sched {
  flex: none; width: 30px; height: 30px; cursor: pointer; color: var(--muted);
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px;
}
.sched:hover { color: var(--accent); border-color: var(--accent); }
.minus:hover { color: var(--red); border-color: var(--red); }
.grip { flex: none; width: 20px; text-align: center; color: var(--muted); font-size: 12px; letter-spacing: -2px; cursor: grab; opacity: 0.6; }
.item:hover .grip { opacity: 1; }
@media (hover: hover) and (pointer: fine) {
  .item .sched { opacity: 0; }
  .item:hover .sched, .item .sched:focus-visible, .item .sched.always { opacity: 1; }
}
/* touch screens: bigger tap areas without changing the look (the box stays 20px,
   an invisible pad around it takes the tap; ~44px tall, kept clear of the text) */
@media (pointer: coarse) {
  .item { min-height: 48px; }
  .check, .ack { position: relative; }
  .check::before, .ack::before { content: ""; position: absolute; inset: -12px -6px -12px -14px; }
  .sched { width: 40px; height: 40px; }
  .seg span, .seg button { padding: 9px 12px; }
}
.ack {
  flex: none; width: 20px; height: 20px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--red); border-radius: 6px; background: none;
  color: transparent; font-size: 13px; line-height: 1; font-weight: 700;
}
.ack::after { content: "✓"; }
.ack:hover, .ack:focus-visible { background: var(--red-soft); color: var(--red); }

.event { display: flex; gap: 10px; padding: 3px 0; font-size: 14px; }
.event .time { color: var(--ev); font-variant-numeric: tabular-nums; font-weight: 600; min-width: 52px; flex: none; }

.empty { color: var(--muted); font-size: 13.5px; margin: 4px 0; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }

details.history { margin-top: 4px; }
.block-head .plain { text-transform: none; letter-spacing: 0; font-weight: 400; }
details.history > summary { font-size: 13px; color: var(--muted); cursor: pointer; padding: 4px 0; }
.history-list li { display: flex; gap: 8px; justify-content: space-between; font-size: 13px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.history-list li:last-child { border-bottom: 0; }
.history-list .h-text { color: var(--muted); }
.history-list .h-text.done { text-decoration: line-through; }
.history-list .h-meta { color: var(--muted); white-space: nowrap; font-size: 12px; }
.history-list .h-meta.missed { color: var(--red); }

/* ---------- queues ---------- */
.queues { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
details.queue { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
details.queue > summary {
  list-style: none; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; cursor: pointer; font-weight: 600; font-size: 14.5px;
}
details.queue > summary .count { margin-left: auto; }
details > summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: var(--muted); display: inline-block; transition: transform 0.15s; margin-right: 4px; }
details[open] > summary::before { transform: rotate(90deg); }
details.queue > .items, .q-add { margin: 0 12px; }
.q-add { display: flex; gap: 6px; padding: 8px 0 12px; }
.q-add input { flex: 1; font-size: 14px; padding: 5px 9px; }
.q-add button { font-size: 13px; padding: 5px 10px; }
.briefing {
  display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px;
  border: 1px dashed var(--line); border-radius: var(--radius);
  color: inherit; text-decoration: none; font-size: 14.5px; font-weight: 600;
}
.briefing:hover { border-color: var(--accent); }
.briefing .muted { font-weight: 400; }

/* drop highlight */
.drop-over { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-soft) !important; }

/* ---------- week ---------- */
.week { display: flex; flex-direction: column; gap: 6px; }
.day { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-height: 44px; }
.day.is-today { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.day.weekend { background: color-mix(in srgb, var(--bg) 55%, transparent); }
.day-head { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }
.day-head + * { margin-top: 3px; }
.tag { font-size: 11px; background: var(--accent); color: var(--on-accent); border-radius: 20px; padding: 0 7px; font-weight: 600; }
.tag.soft { background: var(--accent-soft); color: var(--accent); }
.items.compact .item { min-height: 32px; padding: 3px 0; }
.items.weekly .text { color: var(--muted); }
.cal-tools { display: flex; justify-content: flex-end; margin: -6px 0 8px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { padding: 0; margin: 0; accent-color: var(--accent); }

/* ---------- month ---------- */
.month-nav { display: flex; gap: 6px; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.month-nav .arrows { display: flex; gap: 6px; align-items: center; }
.month-nav .toggle { margin-right: 6px; }
.month-nav .ghost { padding: 3px 11px; }
.mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-bottom: 8px; }
.wd { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cell {
  aspect-ratio: 1 / 0.85; min-width: 0; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.cell:hover { border-color: var(--muted); }
.cell.out { opacity: 0.4; }
.cell.past .num { color: var(--muted); }
.cell.is-today { border-color: var(--accent); }
.cell.is-today .num { color: var(--accent); font-weight: 700; }
.cell.sel { background: var(--accent-soft); }
.num { font-size: 14px; font-variant-numeric: tabular-nums; }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: block; }
.dot.ev { background: var(--ev); }
.dot.it { background: var(--accent); }
.dot.dl { background: var(--amber); }
.dot.wk { background: var(--muted); opacity: 0.6; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- dialog, toast, footer ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink);
  padding: 18px; width: min(420px, calc(100vw - 24px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.field[hidden] { display: none; }
.field .seg { align-self: flex-start; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; min-height: 1em; }
.hint.err { color: var(--red); font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 10px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10; font-size: 14px; max-width: calc(100vw - 24px);
}
#toast[hidden] { display: none; }
#toast .link { color: var(--bg); font-weight: 600; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 10px 0 28px; }
.q-note { font-size: 12px; color: var(--muted); margin: 6px 12px 10px; }

/* ======================================================================
   Real UI additions (on top of the mockup styles above)
   ====================================================================== */
[hidden] { display: none !important; }

/* item text is a span (role=button) so it can hold links */
.text { display: block; }
.text:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.text a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.text code, .h-text code {
  font: 12.5px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); padding: 0 4px; border-radius: 4px;
}
.item.busy { opacity: 0.45; pointer-events: none; }

/* appointments: clickable title, optional location */
.ev-title {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0;
  cursor: pointer; overflow-wrap: anywhere;
}
.ev-title:hover { text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 3px; }
.ev-loc { color: var(--muted); font-size: 12.5px; }
.event .chip { align-self: center; }
@media (pointer: coarse) { .event { padding: 7px 0; } }

/* first-run token screen */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 12px;
}
.login-card .field input { font-size: 15px; }

/* connection problems */
.status {
  max-width: 1200px; margin: 12px auto 0; padding: 8px 14px; border-radius: 10px;
  background: var(--amber-soft); color: var(--amber); font-size: 13.5px; text-align: center;
}
@media (max-width: 820px) { .status { margin: 8px 10px 0; } }

#toast.err { background: var(--red); color: #fff; }
#toast.err .link { color: #fff; }

/* dialogs */
.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field-row .field { flex: 1 1 140px; }
.field-row > .toggle { margin-bottom: 18px; }
#qa-appt-row { align-items: flex-end; }
#qa-appt-row > .toggle { padding-bottom: 9px; }
button:disabled { opacity: 0.6; cursor: default; }

.foot .sync-err { color: var(--red); font-weight: 600; }
.loading { color: var(--muted); font-size: 14px; padding: 8px 0; }
