:root {
  --bg: #f3f4f8;
  --card: #ffffff;
  --text: #1b1c22;
  --muted: #8a8d99;
  --line: #e8e9f0;
  --accent: #5b5bd6;
  --accent-2: #7a5af8;
  --harry: #5b5bd6;
  --note: #10b981;
  --today: #f59e0b;
  --am: #f59e0b;     /* morning crossover */
  --school: #64748b; /* school run (muted, shows most weekdays) */
  --pm: #0ea5e9;     /* evening crossover */
  --danger: #e5484d;
  --radius: 20px;
  --radius-sm: 13px;
  --shadow: 0 1px 2px rgba(16, 18, 30, .05), 0 10px 26px rgba(16, 18, 30, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101116; --card: #1a1b22; --text: #ecedf2; --muted: #888b98; --line: #2a2c36;
    --accent: #8b8bf0; --accent-2: #a78bfa; --harry: #6d6df0; --note: #34d399; --today: #fbbf24;
    --am: #fbbf24; --school: #94a3b8; --pm: #38bdf8;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 26px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased;
}
.app {
  max-width: 540px; margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 14px calc(var(--safe-bottom) + 30px);
}

/* Header */
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px 4px; }
.app-header h1 { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.icon-btn { border: none; background: var(--card); color: var(--text); width: 40px; height: 40px; border-radius: 50%; font-size: 1.4rem; line-height: 1; box-shadow: var(--shadow); cursor: pointer; }
.icon-btn:active { transform: scale(.94); }

.page[hidden] { display: none; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 14px; }
.card-title { margin: 0 0 12px; font-size: 1rem; font-weight: 700; }

/* Handover */
.handover { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.handover .tonight { margin: 0; font-size: 1.18rem; font-weight: 700; letter-spacing: -.01em; }
.handover .next { margin: 6px 0 0; font-size: .95rem; opacity: .92; }

/* Calendar toolbar */
.cal-toolbar { margin-top: 14px; }
.nav-row { display: flex; align-items: center; justify-content: space-between; }
.nav-btn { border: none; background: transparent; color: var(--text); width: 42px; height: 42px; border-radius: 12px; font-size: 1.6rem; line-height: 1; cursor: pointer; }
.nav-btn:active { background: var(--line); }
.month-label { border: none; background: transparent; color: var(--text); font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; cursor: pointer; padding: 6px 12px; border-radius: 10px; }
.month-label:active { background: var(--line); }
.view-toggle { display: flex; gap: 4px; background: var(--card); border-radius: 12px; padding: 3px; margin: 10px auto 0; width: fit-content; box-shadow: var(--shadow); }
.vt { border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem; padding: 7px 22px; border-radius: 9px; cursor: pointer; }
.vt.active { background: var(--accent); color: #fff; }

/* Month grid */
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.grid { column-gap: 0; row-gap: 6px; }
.weekdays { column-gap: 0; }
.weekdays { margin-bottom: 6px; }
.weekdays[hidden] { display: none; }
.grid[hidden] { display: none; }
.weekdays span { text-align: center; font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cell {
  position: relative; aspect-ratio: 1 / 1; min-width: 0; border: none; background: transparent; color: var(--text);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.cell:active { opacity: .65; }
.cell .dnum { font-size: .98rem; font-weight: 600; line-height: 1; width: 25px; height: 25px; display: flex; align-items: center; justify-content: center; border-radius: 999px; }
.cell.muted { color: var(--muted); opacity: .45; }
/* connected "with Harry" block (hotel-range style): seamless vertical-gradient fill,
   rounded only at the run's start/end, thin divider between consecutive days */
.cell.harry { background-color: var(--accent); background-image: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,0)); color: #fff; }
.cell.harry.rl { border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }
.cell.harry.rr { border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
.cell.harry.contL::after { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 1px; background: rgba(255,255,255,.28); }
.cell.today .dnum { background: var(--today); color: #fff; }
.cell.harry.today .dnum { background: #fff; color: var(--accent); }
.mkrow { display: flex; gap: 4px; min-height: 9px; line-height: 1; align-items: center; }
.mk { font-size: 8.5px; font-weight: 800; letter-spacing: .02em; }
.mk.am { color: var(--am); } .mk.s { color: var(--school); } .mk.pm { color: var(--pm); }
.cell.harry .mk { color: rgba(255, 255, 255, .95); }
.ndot { position: absolute; top: 5px; right: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--note); }
.cell.harry .ndot { background: #fff; }

/* Week list — consecutive nights join into a vertical block */
.week-list { display: flex; flex-direction: column; gap: 6px; }
.week-list[hidden] { display: none; }
.wrow { position: relative; display: flex; gap: 12px; text-align: left; border: none; background: var(--bg); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; align-items: stretch; }
.wrow:active { opacity: .7; }
.wrow.harry { background: var(--accent); color: #fff; border-radius: 0; }
.wrow.harry.rt { border-top-left-radius: var(--radius-sm); border-top-right-radius: var(--radius-sm); }
.wrow.harry.rb { border-bottom-left-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
.wrow.harry.contT { margin-top: -6px; }
.wrow.harry.contT::before { content: ""; position: absolute; left: 14px; right: 14px; top: 0; height: 1px; background: rgba(255,255,255,.22); }
.wrow.today { outline: 2px solid var(--today); outline-offset: -2px; z-index: 1; }
.wdate { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 42px; }
.wdate .wdow { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.wdate .wdn { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.wrow.harry .wdate .wdow { color: rgba(255,255,255,.8); }
.wbody { flex: 1; display: flex; flex-direction: column; gap: 5px; justify-content: center; }
.wstatus { font-weight: 700; font-size: .95rem; }
.wrow.harry .wstatus, .wrow.harry .wnote { color: #fff; }
.wtags { display: flex; flex-wrap: wrap; gap: 6px; }
.wtag { font-size: .74rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--card); color: var(--text); display: inline-flex; gap: 5px; align-items: center; }
.wtag b { font-weight: 800; }
.wtag.am b { color: var(--am); } .wtag.s b { color: var(--school); } .wtag.pm b { color: var(--pm); }
.wrow.harry .wtag { background: rgba(255,255,255,.18); color: #fff; }
.wrow.harry .wtag b { color: #fff; }
.wnote { font-size: .82rem; color: var(--muted); }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; font-size: .76rem; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 16px; height: 16px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.swatch.harry { background: linear-gradient(150deg, var(--accent), var(--accent-2)); }
.lk { font-size: 11px; font-weight: 800; letter-spacing: .02em; min-width: 18px; text-align: center; }
.lk.am { color: var(--am); } .lk.s { color: var(--school); } .lk.pm { color: var(--pm); }

/* Stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat .num { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.stat .num small { font-size: .85rem; font-weight: 600; color: var(--muted); margin-left: 4px; }
.stat .lbl { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; max-width: 540px; margin: 0 auto;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab { flex: 1; border: none; background: transparent; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 7px; font: inherit; font-size: .68rem; font-weight: 600; }
.tab .ti { font-size: 1.3rem; filter: grayscale(1); opacity: .6; }
.tab.active { color: var(--accent); }
.tab.active .ti { filter: none; opacity: 1; }

/* Sheets */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10,11,16,.42); display: flex; align-items: flex-end; justify-content: center; z-index: 50; animation: fade .15s ease; }
.sheet-backdrop[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--card); width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; -webkit-overflow-scrolling: touch; border-radius: 22px 22px 0 0; padding: 10px 18px calc(var(--safe-bottom) + 22px); box-shadow: 0 -10px 40px rgba(0,0,0,.25); animation: slideup .22s cubic-bezier(.2,.8,.2,1); }
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 1.2rem; font-weight: 800; letter-spacing: -.01em; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-size: 1.05rem; font-weight: 600; gap: 12px; }
.switch-row.compact { font-size: .95rem; }
.switch-row span small { display: block; font-size: .76rem; font-weight: 500; color: var(--muted); }
.switch { position: relative; width: 52px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .2s; }
.slider::before { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(21px); }

/* Day options (segmented) */
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.opt-label { font-weight: 600; font-size: .98rem; }
.opt-label small { display: block; font-size: .74rem; font-weight: 500; color: var(--muted); margin-left: 26px; }
.ol-tag { display: inline-block; font-size: .72rem; font-weight: 800; width: 22px; text-align: center; margin-right: 4px; }
.ol-tag.am { color: var(--am); } .ol-tag.s { color: var(--school); } .ol-tag.pm { color: var(--pm); }
.seg { display: flex; background: var(--bg); border-radius: 11px; padding: 3px; flex: none; }
.seg button { border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: .82rem; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }

.note-label { display: block; margin: 14px 0 6px; font-size: .82rem; font-weight: 600; color: var(--muted); }
textarea, input[type="text"], input[type="date"], input[type="email"] { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 12px; padding: 11px 12px; font: inherit; resize: vertical; }
textarea:focus, input[type="text"]:focus, input[type="date"]:focus, input[type="email"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn { flex: 1; border: none; border-radius: 13px; padding: 13px; font: inherit; font-weight: 700; cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--bg); color: var(--text); }
.btn.ghost.danger { color: var(--danger); }
.btn.block { width: 100%; margin-top: 12px; }

/* Menu */
.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-item { display: flex; align-items: center; gap: 14px; text-align: left; border: none; background: transparent; color: var(--text); padding: 12px 8px; border-radius: 12px; cursor: pointer; width: 100%; }
.menu-item:active { background: var(--bg); }
.mi-icon { font-size: 1.4rem; width: 30px; text-align: center; flex: none; }
.mi-text { display: flex; flex-direction: column; }
.mi-text small { color: var(--muted); font-size: .8rem; }

/* Importer */
.import-summary { font-size: 1rem; margin: 0 0 10px; }
.import-summary small { color: var(--muted); font-weight: 600; }
.import-hint { font-size: .8rem; color: var(--muted); margin: 6px 0 0; }
.ir-head { font-size: .82rem; font-weight: 700; color: var(--muted); margin: 14px 0 8px; }
.ir-head small { font-weight: 500; }
.rules-list { display: flex; flex-direction: column; gap: 6px; }
.rule-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 11px; padding: 7px 8px 7px 12px; }
.rule-text { flex: 1; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-badge { border: none; cursor: pointer; font: inherit; font-size: .72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; color: #fff; }
.rule-badge.night { background: var(--accent); } .rule-badge.note { background: var(--note); } .rule-badge.skip { background: var(--muted); }
.rule-del { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 2px 6px; border-radius: 8px; flex: none; }
.rule-del:active { background: var(--line); }
.rule-add { display: flex; gap: 8px; margin-top: 10px; }
.rule-add input { flex: 1; }
.rule-add select { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 12px; padding: 0 8px; font: inherit; font-weight: 600; }
.rule-add-btn { flex: none; padding: 10px 16px; }
.skipped-toggle { width: 100%; text-align: left; border: none; background: transparent; color: var(--text); font: inherit; font-weight: 600; font-size: .9rem; padding: 14px 2px 6px; cursor: pointer; }
.skipped-toggle .chev { display: inline-block; transition: transform .15s; color: var(--muted); }
.skipped-toggle.open .chev { transform: rotate(90deg); }
.skipped-list { max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.skipped-list[hidden] { display: none; }
.skip-row { display: flex; align-items: center; gap: 8px; padding: 6px 2px; border-bottom: 1px solid var(--line); }
.skip-text { flex: 1; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skip-text em { color: var(--muted); font-style: normal; font-size: .78rem; }
.skip-acts { display: flex; gap: 6px; flex: none; }
.skip-acts button { border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: .74rem; font-weight: 700; padding: 5px 9px; border-radius: 8px; cursor: pointer; }
.skip-acts button:active { background: var(--line); }
.muted-note { color: var(--muted); font-size: .85rem; text-align: center; padding: 10px; margin: 0; }

/* Sync */
.sync-code { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg); border-radius: 13px; padding: 14px 14px 14px 18px; margin: 4px 0 8px; }
.sync-code span { font-size: 1.02rem; font-weight: 800; letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.copy-btn { border: none; background: var(--accent); color: #fff; font: inherit; font-weight: 700; font-size: .82rem; padding: 8px 14px; border-radius: 9px; cursor: pointer; flex: none; }
.copy-btn:active { transform: scale(.96); }
.sync-status { font-size: .82rem; color: var(--muted); margin: 0 0 8px; }
#syncOn .ir-head, #syncOff .ir-head { margin-top: 16px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translateX(-50%); background: #1b1c22; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: .9rem; font-weight: 600; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.3); animation: fade .15s ease; }

/* Admin — holidays */
.holiday-list { display: flex; flex-direction: column; gap: 6px; }
.hol-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 11px; padding: 8px 8px 8px 12px; }
.hol-text { flex: 1; font-size: .9rem; font-weight: 600; }
.hol-text small { display: block; font-size: .76rem; font-weight: 500; color: var(--muted); }
.holiday-add { margin-top: 8px; }
.holiday-add > input { margin-bottom: 8px; }
.holiday-dates { display: flex; align-items: center; gap: 8px; }
.holiday-dates input[type="date"] { flex: 1; min-width: 0; }
.holiday-dates span { color: var(--muted); }
@media (prefers-color-scheme: dark) { .toast { background: #2a2c36; } }
