/* ============ Design tokens ============ */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #1c2030;
  --text-dim: #6b7186;
  --line: #e2e5ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --today: #4f46e5;
  --shadow: 0 8px 28px rgba(20, 24, 50, 0.12);

  /* category colors */
  --cat-school: #3b82f6;
  --cat-golfp: #16a34a;
  --cat-golfs: #0d9488;
  --cat-soccer: #ca8a04;
  --cat-trip: #f97316;   /* Vacation */
  --cat-work: #7c3aed;   /* Business Trip */
  --cat-appt: #dc2626;
  --cat-social: #ec4899;
  --cat-famact: #06b6d4;
  --cat-holiday: #c026d3;
  --cat-todo: #f43f5e;
  --cat-other: #64748b;

  /* person colors */
  --per-mom: #ec4899;
  --per-dad: #0ea5e9;
  --per-son: #22c55e;
  --per-family: #a855f7;

  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1c1f2b;
    --surface-2: #262a3a;
    --text: #eceef6;
    --text-dim: #9aa1b8;
    --line: #30354a;
    --accent: #818cf8;
    --accent-soft: #2a2d4a;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

.screen { min-height: 100dvh; }

/* ============ Sign-in ============ */
#signin {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.signin-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 26px calc(32px + var(--safe-bottom));
  text-align: center;
}
.signin-logo { font-size: 52px; }
.signin-card h1 { margin: 8px 0 4px; font-size: 26px; }
.signin-sub { margin: 0 0 24px; color: var(--text-dim); }
.signin-card .field { text-align: left; }
.person-picker { display: flex; gap: 8px; }
.person-picker button {
  flex: 1; padding: 12px 4px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: 15px;
}
.person-picker button.active {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent);
}
.btn-primary {
  width: 100%; margin-top: 18px; padding: 14px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 12px; font-size: 17px; font-weight: 700;
}
.btn-primary:disabled { opacity: 0.45; cursor: default; }
.signin-error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }

/* ============ Fields (shared) ============ */
.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-dim); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.field > span em { text-transform: none; font-weight: 400; font-style: normal; }
.field input[type="text"], .field input[type="date"], .field input[type="time"], .field textarea {
  width: 100%; padding: 11px 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); min-height: 44px;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field small { display: block; margin-top: 6px; color: var(--text-dim); font-size: 12px; }
.field-inline { display: flex; align-items: center; justify-content: space-between; }
.field-inline > span { margin: 0; }
.field-inline input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.month-nav { display: flex; align-items: center; gap: 4px; }
.topbar-right { display: flex; align-items: center; }
.topbar-right .btn-ghost { padding: 8px 6px; }
#btnRefresh.spinning { animation: refspin 0.9s linear infinite; }
@keyframes refspin { to { transform: rotate(360deg); } }
.month-nav h1 { margin: 0; font-size: 17px; min-width: 150px; text-align: center; }
.title-wrap { display: flex; flex-direction: column; align-items: center; }
#verTag { font-size: 9px; line-height: 1.1; color: var(--text-dim); letter-spacing: 0.04em; }
.btn-nav {
  border: none; background: transparent; color: var(--accent);
  font-size: 26px; line-height: 1; padding: 4px 12px; border-radius: 8px;
}
.btn-ghost {
  border: none; background: transparent; color: var(--accent);
  font-weight: 600; font-size: 15px; padding: 8px 10px; border-radius: 8px;
}
.btn-save { font-weight: 700; }
.btn-danger {
  width: 100%; padding: 12px; margin-top: 4px;
  background: transparent; color: var(--danger);
  border: 1.5px solid var(--danger); border-radius: 10px; font-weight: 600;
}

/* ============ Banner ============ */
.banner {
  padding: 8px 14px; font-size: 13px; text-align: center;
  background: #fef3c7; color: #92400e;
}
@media (prefers-color-scheme: dark) {
  .banner { background: #443714; color: #fbd58a; }
}

/* ============ Toolbar / segmented ============ */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px 4px;
}
.seg {
  display: inline-flex; background: var(--surface-2);
  border-radius: 10px; padding: 3px;
}
.seg button {
  border: none; background: transparent; color: var(--text-dim);
  padding: 7px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
  white-space: nowrap;
}
.seg-small button { padding: 7px 10px; font-size: 13px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
.seg-full { display: flex; width: 100%; }
.seg-full button { flex: 1; }

/* ============ Filters (dropdown pickers) ============ */
.filters { padding: 6px 12px 8px; display: flex; gap: 8px; }
.filter-btn {
  flex: 1; min-width: 0; min-height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 10px; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.filter-btn .caret { color: var(--text-dim); font-size: 11px; }
.filter-btn.filtering { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.filter-btn.filtering .caret { color: var(--accent); }

.filter-hint { margin: 0 0 10px; font-size: 12px; color: var(--text-dim); }
.filter-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding-bottom: 16px;
}
.filter-opt {
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 10px 12px; text-align: left;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600;
}
.filter-opt .fo-icon { font-size: 18px; flex: none; }
.filter-opt .fo-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-opt .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--dot, var(--text-dim)); }
.filter-opt.active { border-color: var(--accent); background: var(--accent-soft); }
.filter-opt.active::after { content: '✓'; color: var(--accent); font-weight: 800; flex: none; }

/* ============ Main view ============ */
main#view { padding: 4px 8px calc(90px + var(--safe-bottom)); max-width: 1150px; margin: 0 auto; width: 100%; }
@keyframes swipeInLeft  { from { transform: translateX(70px);  opacity: 0.15; } to { transform: none; opacity: 1; } }
@keyframes swipeInRight { from { transform: translateX(-70px); opacity: 0.15; } to { transform: none; opacity: 1; } }
main#view.swipe-left  { animation: swipeInLeft 0.28s ease-out; }
main#view.swipe-right { animation: swipeInRight 0.28s ease-out; }

/* big center flash naming the new period after a swipe/arrow */
#navFlash {
  position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%);
  z-index: 70; pointer-events: none; opacity: 0;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 12px 26px; font-size: 19px; font-weight: 800;
  box-shadow: var(--shadow); white-space: nowrap; max-width: 90vw;
  overflow: hidden; text-overflow: ellipsis;
}
#navFlash.show { animation: navflash 0.85s ease; }
@keyframes navflash {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
  18%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}
#periodTitle.pop { animation: titlepop 0.4s ease; }
@keyframes titlepop {
  0% { transform: scale(1.25); color: var(--accent); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  main#view.swipe-left, main#view.swipe-right, #periodTitle.pop { animation: none; }
  #navFlash.show { animation: navflash-static 0.9s; }
  @keyframes navflash-static { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
}

/* ---- Month grid ---- */
.month-head {
  display: grid; grid-template-columns: 20px repeat(7, 1fr);
  padding: 4px 2px; font-size: 11px; font-weight: 700;
  color: var(--text-dim); text-align: center; text-transform: uppercase;
}
.month-grid { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.week-row { position: relative; border-bottom: 1px solid var(--line); min-height: 96px; }
.week-row:last-child { border-bottom: none; }
.day-cells {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: 20px repeat(7, 1fr);
}
.wk-btn {
  border: none; border-right: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-dim);
  font-size: 14px; font-weight: 700; cursor: pointer; padding: 0;
}
.wk-btn:active { background: var(--accent-soft); color: var(--accent); }
.day-cell { border-right: 1px solid var(--line); padding: 3px; cursor: pointer; min-width: 0; }
.day-cell:last-child { border-right: none; }
.day-cell.other-month { background: var(--surface-2); }
.day-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 12px; font-weight: 600;
}
.other-month .day-num { color: var(--text-dim); opacity: 0.6; }
.day-cell.today .day-num { background: var(--today); color: #fff; }
.more-count {
  position: absolute; bottom: 2px; font-size: 10px; font-weight: 700;
  color: var(--text-dim); pointer-events: none; padding-left: 4px;
}
.events-layer {
  position: relative; pointer-events: none;
  display: grid; grid-template-columns: 20px repeat(7, 1fr);
  grid-auto-rows: 20px; gap: 2px 0;
  padding: 30px 1px 16px;
}
.evbar {
  pointer-events: auto; cursor: pointer;
  margin: 0 2px; padding: 1px 6px;
  border-radius: 6px; border: none; text-align: left;
  font-size: 11px; font-weight: 600; line-height: 16px;
  color: #fff; background: var(--ev, var(--cat-other));
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 4px; min-width: 0;
}
.evbar .ev-title { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.evbar.cont-left { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.evbar.cont-right { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.evbar.done .ev-title, .evcard.done .ev-name, .wg-chip.done { text-decoration: line-through; opacity: 0.7; }
.evbar.tentative {
  background:
    repeating-linear-gradient(45deg,
      transparent 0 6px, rgba(255,255,255,0.28) 6px 12px),
    var(--ev, var(--cat-other));
  border: 1.5px dashed rgba(255,255,255,0.9);
  opacity: 0.92;
}
.ev-when { display: none; opacity: 0.85; font-weight: 500; }
@media (max-width: 799px) {
  .evbar { padding: 1px 4px; gap: 3px; }
  .evbar.span1 .ev-badge { display: none; }
}
.ev-badge {
  flex: none; font-size: 11px; line-height: 1;
}

/* ---- Week & Agenda lists ---- */
.day-section { margin: 10px 2px; }
.day-section-head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 4px 6px; font-weight: 700; font-size: 14px;
}
.day-section-head .dow { color: var(--text-dim); font-size: 12px; text-transform: uppercase; }
.day-section-head.is-today .dnum { color: var(--today); }
.day-empty {
  padding: 10px 12px; color: var(--text-dim); font-size: 13px;
  background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; cursor: pointer;
}
.agenda-empty { text-align: center; color: var(--text-dim); padding: 60px 20px; }

/* ---- Day view (hourly timeline) ---- */
.day-hint { color: var(--text-dim); font-size: 14px; padding: 14px 8px 0; text-align: center; }
.day-allday { margin: 10px 2px 4px; }
.day-grid {
  position: relative; margin: 14px 2px 24px;
  border-top: 1px solid var(--line);
}
.day-hour {
  position: absolute; left: 0; right: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.day-hour:hover { background: var(--accent-soft); }
.day-hour-label {
  position: absolute; top: 2px; left: 2px;
  font-size: 10px; font-weight: 600; color: var(--text-dim); width: 46px;
}
.day-ev {
  position: absolute; z-index: 2; overflow: hidden; text-align: left;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--ev, var(--cat-other)); color: #fff;
  padding: 3px 8px; font-size: 12px; line-height: 1.25;
  box-shadow: 0 2px 6px rgba(10, 12, 24, 0.25);
}
.day-ev b { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-ev span { font-size: 10.5px; opacity: 0.9; }
.day-ev.tentative {
  background:
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(255,255,255,0.28) 6px 12px),
    var(--ev, var(--cat-other));
  border: 1.5px dashed rgba(255,255,255,0.9);
}
.day-ev.done b { text-decoration: line-through; opacity: 0.7; }
.day-now {
  position: absolute; left: 46px; right: 0; z-index: 3; height: 2px;
  background: #ef4444; pointer-events: none;
}
.day-now::before {
  content: ''; position: absolute; left: -5px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: #ef4444;
}
.day-section-head { cursor: pointer; }
.day-section-head .day-open { margin-left: auto; color: var(--text-dim); font-weight: 800; }

/* ---- Week time grid (landscape phones & laptops) ---- */
.wg { margin-top: 8px; }
.wg-row { display: grid; grid-template-columns: 46px repeat(7, 1fr); }
.wg-dayhead {
  border: none; background: none; color: var(--text);
  padding: 4px 2px 6px; text-align: center; cursor: pointer;
}
.wg-dayhead span { display: block; color: var(--text-dim); text-transform: uppercase; font-size: 9px; font-weight: 700; }
.wg-dayhead b { font-size: 15px; display: inline-block; width: 24px; height: 24px; line-height: 24px; border-radius: 50%; }
.wg-dayhead.today b { background: var(--today); color: #fff; }
.wg-allday { border-bottom: 2px solid var(--line); }
.wg-adcell {
  border-left: 1px solid var(--line); padding: 2px; min-height: 6px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.wg-chip {
  border: none; border-radius: 5px; cursor: pointer;
  background: var(--ev, var(--cat-other)); color: #fff;
  font-size: 10px; font-weight: 600; padding: 2px 5px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wg-chip.tentative {
  background:
    repeating-linear-gradient(45deg, transparent 0 5px, rgba(255,255,255,0.28) 5px 10px),
    var(--ev, var(--cat-other));
  border: 1px dashed rgba(255,255,255,0.9);
}
.wg-times { position: relative; }
.wg-times span {
  position: absolute; right: 6px; transform: translateY(-1px);
  font-size: 9px; font-weight: 600; color: var(--text-dim);
}
.wg-col {
  position: relative; border-left: 1px solid var(--line); cursor: pointer;
  background: repeating-linear-gradient(to bottom,
    transparent 0, transparent 47px, var(--line) 47px, var(--line) 48px);
}
.wg-ev { padding: 2px 4px; font-size: 10.5px; border-radius: 6px; }
.wg-ev b { font-size: 10.5px; }
.wg-ev span { font-size: 9px; }
.wg-now {
  position: absolute; left: 0; right: 0; height: 2px; z-index: 3;
  background: #ef4444; pointer-events: none;
}

/* ---- Event cards (lists & day sheet) ---- */
.evcard {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--ev, var(--cat-other));
  border-radius: 10px; padding: 9px 12px; margin-bottom: 6px;
  text-align: left; cursor: pointer; color: var(--text);
}
.evcard.tentative { border-style: dashed; border-left-style: solid; background: transparent; }
.evcard .ev-time { flex: none; width: 74px; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.evcard .ev-main { flex: 1; min-width: 0; }
.evcard .ev-name { display: block; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evcard .ev-sub { display: block; font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evcard .ev-tag {
  flex: none; font-size: 10px; font-weight: 800; color: #fff;
  background: var(--ev2, var(--text-dim));
  border-radius: 999px; padding: 3px 8px;
  max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.evcard .tent-mark { flex: none; font-weight: 800; color: var(--cat-trip); font-size: 15px; }

/* ============ FAB ============ */
#fab {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-bottom)); z-index: 40;
  width: 58px; height: 58px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.45);
}
#fab:active { transform: scale(0.94); }
#fabMic {
  position: fixed; right: 22px; bottom: calc(88px + var(--safe-bottom)); z-index: 40;
  width: 50px; height: 50px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--surface);
  font-size: 22px; line-height: 1;
  box-shadow: 0 4px 14px rgba(20, 24, 50, 0.25);
}
#fabMic:active { transform: scale(0.94); }

/* ============ Voice input ============ */
.voice-body { text-align: center; padding: 6px 0 14px; }
#voiceMic {
  width: 92px; height: 92px; border-radius: 50%;
  border: none; background: var(--accent-soft);
  font-size: 42px; line-height: 1;
}
dialog.listening #voiceMic { animation: micpulse 1.4s ease-in-out infinite; }
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.45); }
  50% { box-shadow: 0 0 0 18px rgba(79, 70, 229, 0); }
}
#voiceStatus { margin: 12px 0 4px; color: var(--text-dim); font-size: 13px; }
#voiceTranscript { margin: 0 0 10px; min-height: 24px; font-size: 17px; font-weight: 600; }
#btnVoiceRetry { max-width: 220px; margin: 4px auto 10px; display: block; }
.voice-hints { font-size: 12px; color: var(--text-dim); line-height: 1.7; margin: 8px 0 0; }
.voice-type-row { display: flex; gap: 8px; margin: 12px 0 2px; }
.voice-type-row input {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
}
.voice-type-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.voice-type-row .btn-primary { width: auto; margin: 0; padding: 10px 18px; }

.voice-note {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; padding: 9px 12px;
  font-size: 13px; font-weight: 600; margin: 0 0 14px;
}
.confirm-card { pointer-events: none; margin-bottom: 12px; }

/* ============ What's New ============ */
.whatsnew-body { padding-bottom: 14px; }
.whatsnew-body h3 {
  margin: 16px 0 2px; font-size: 15px;
  display: flex; align-items: baseline; gap: 8px;
}
.whatsnew-body h3 small { color: var(--text-dim); font-weight: 500; font-size: 12px; }
.whatsnew-body h4 {
  margin: 8px 0 2px; font-size: 11px; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
}
.whatsnew-body ul { margin: 2px 0 6px; padding-left: 20px; }
.whatsnew-body li { font-size: 14px; line-height: 1.5; margin-bottom: 3px; }

/* ============ While you were away ============ */
.away-body { padding-bottom: 14px; }
.away-body h4 {
  margin: 12px 0 4px; font-size: 11px; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
}
.away-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--line);
}
.away-row:last-child { border-bottom: none; }
.away-icon { flex: none; font-size: 16px; }
.away-main { flex: 1; min-width: 0; }
.away-title { font-weight: 700; font-size: 14px; }
.away-sub { font-size: 12px; color: var(--text-dim); }

/* ============ Update toast ============ */
.update-toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + var(--safe-bottom));
  z-index: 60; margin: 0 auto; max-width: 420px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
}
.update-toast span { flex: 1; }
#btnUpdateReload {
  border: none; background: var(--accent); color: #fff;
  border-radius: 9px; padding: 9px 16px; font-weight: 700; min-height: 40px;
}
#btnUpdateDismiss {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 15px; padding: 8px; min-width: 40px; min-height: 40px;
}

/* ============ Dialogs ============ */
dialog {
  border: none; border-radius: 18px 18px 0 0;
  width: 100%; max-width: 560px;
  margin: auto auto 0; padding: 0 18px calc(20px + var(--safe-bottom));
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  max-height: 92dvh; overflow-y: auto;
}
dialog::backdrop { background: rgba(10, 12, 24, 0.45); }
.dlg-head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 10px; margin-bottom: 6px;
  background: var(--surface);
}
.dlg-head h2 { margin: 0; font-size: 17px; }

.option-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.option-row button {
  display: flex; align-items: center; gap: 7px; min-width: 0; min-height: 44px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 11px; font-size: 14px; font-weight: 600;
  text-align: left; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.option-row button .opt-icon { flex: none; font-size: 16px; }
.option-row button .dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--dot, var(--text-dim)); }
.option-row button.active { border-color: var(--dot, var(--accent)); background: var(--accent-soft); }

.day-list { padding-bottom: 10px; min-height: 120px; }
.settings-body { padding-bottom: 10px; }
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
  font-size: 15px; margin-bottom: 2px;
}
.settings-row span { color: var(--text-dim); }
.settings-hint { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.btn-feeds {
  width: 100%; padding: 12px; margin: 14px 0 10px;
  background: var(--accent-soft); color: var(--accent);
  border: 1.5px solid var(--accent); border-radius: 10px; font-weight: 700; font-size: 15px;
}

/* ============ Search ============ */
.search-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.search-bar input {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
}
.search-bar input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.search-bar .btn-primary { width: auto; margin: 0; padding: 10px 16px; white-space: nowrap; }
.search-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.search-opts select {
  min-height: 40px; padding: 6px 8px; font-size: 13px; font-weight: 600;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.search-results { padding-bottom: 16px; min-height: 80px; }
.search-answer {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; padding: 10px 12px; margin: 8px 0;
  font-weight: 600; font-size: 14px; line-height: 1.4;
}
.search-count { font-size: 12px; color: var(--text-dim); margin: 8px 2px 4px; }
.search-note { font-size: 12.5px; color: var(--text-dim); margin: 8px 2px; }
.sr-date { font-size: 11px; font-weight: 700; color: var(--text-dim); margin: 10px 2px 3px; }
.sr-item .evcard { margin-bottom: 2px; }

/* ============ Event alerts ============ */
.alert-body { padding: 4px 0 14px; display: flex; flex-direction: column; gap: 16px; }
.alert-item { display: flex; flex-direction: column; gap: 6px; }
.alert-when { font-size: 13px; font-weight: 800; color: var(--accent); }
.btn-snooze {
  align-self: flex-end; min-height: 44px; padding: 10px 16px;
  background: var(--accent-soft); color: var(--accent);
  border: 1.5px solid var(--accent); border-radius: 10px; font-weight: 700; font-size: 14px;
}
#btnPushToggle { font-weight: 700; color: var(--accent); }
#btnPushToggle:disabled { color: var(--text-dim); }

/* ============ Feeds refresh ============ */
.feeds-body { padding-bottom: 16px; min-height: 120px; }
.feeds-body h4 {
  margin: 12px 0 6px; font-size: 12px; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
}
.feed-line { padding: 6px 2px; font-size: 14px; border-bottom: 1px solid var(--line); }
.feed-line b { font-weight: 700; }
.feed-detail { border-bottom: none; padding: 1px 2px 1px 26px; }
.feed-item { font-size: 12px; color: var(--text-dim); }
.feed-change { font-size: 12.5px; font-weight: 600; }
.feed-err { color: var(--danger); }
.feed-done {
  margin-top: 10px; border-bottom: none;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 13px;
}

/* ============ Desktop ============ */
@media (min-width: 800px) {
  dialog { border-radius: 18px; margin: auto; }
  .week-row { min-height: 120px; }
  .evbar { font-size: 12px; line-height: 18px; }
  .ev-when { display: inline; }
  .events-layer { grid-auto-rows: 22px; }
  .month-nav h1 { font-size: 20px; min-width: 220px; }
  .filters { max-width: 560px; }
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
  .option-row { grid-template-columns: repeat(3, 1fr); }
  main#view { padding-left: 16px; padding-right: 16px; }
}
