:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --text: #1b1f1d;
  --muted: #5f6b66;
  --border: #dde2de;
  --brand: #1f6f5c;
  --brand-ink: #ffffff;
  --brand-soft: #e2f0eb;
  --ok: #1f8a4c;
  --ok-soft: #e1f4e7;
  --bad: #c0362c;
  --bad-soft: #fbe6e3;
  --closed: #8a8f8c;
  --closed-soft: #eceeec;
  --office: #2e8b57;
  --office-soft: #dcf1e3;
  --home: #2f6fcb;
  --home-soft: #dde8f8;
  --away: #c27a0e;
  --away-soft: #fbedd3;
  --off: #7b817e;
  --off-soft: #ebecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a1f1d;
    --surface-2: #232927;
    --text: #e8ece9;
    --muted: #9aa5a0;
    --border: #2f3633;
    --brand: #4cb397;
    --brand-ink: #0b1714;
    --brand-soft: #1d3530;
    --ok: #5cc98a;
    --ok-soft: #1a3324;
    --bad: #ff7b6e;
    --bad-soft: #3d1f1c;
    --closed: #8c9590;
    --closed-soft: #252a28;
    --office: #5cc98a;
    --office-soft: #1b3426;
    --home: #79a8ee;
    --home-soft: #1c2a40;
    --away: #f0b350;
    --away-soft: #3a2d15;
    --off: #9aa29e;
    --off-soft: #2a2f2d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
[hidden] { display: none !important; }

.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
}
.topbar-row { display: flex; align-items: center; gap: 8px; max-width: 760px; margin: 0 auto; }
.topbar h1 { font-size: 19px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 13px; color: var(--muted); font-weight: 400; display: block; margin-top: 2px; }
main.view { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { display: flex; width: 100%; max-width: 760px; }
.tabbar button {
  flex: 1; height: var(--tabbar-h); border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; color: var(--muted);
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--brand); font-weight: 600; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; font-weight: 500;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 22px; height: 22px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { padding: 16px; margin-bottom: 12px; }
.section h2 { font-size: 17px; margin-bottom: 4px; }
.section p.hint { margin: 2px 0 12px; color: var(--muted); font-size: 14px; }

/* Day cards */
.day { margin-bottom: 12px; overflow: hidden; }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.day-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.day-date { flex: 1; min-width: 0; }
.day-date strong { font-size: 16px; }
.day-date .muted { font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.under { background: var(--bad-soft); color: var(--bad); }
.pill.closed, .pill.free { background: var(--closed-soft); color: var(--closed); }
.gaps { margin: 0 14px 10px; padding: 8px 10px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); font-size: 14px; }
.closed-label { margin: 0 14px 12px; color: var(--muted); font-size: 14px; }

.timeline { position: relative; height: 10px; margin: 0 14px 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.timeline span { position: absolute; top: 0; bottom: 0; }
.timeline .tl-0 { background: var(--bad); opacity: .55; }
.timeline .tl-1 { background: var(--away); opacity: .6; }
.timeline .tl-ok { background: var(--ok); opacity: .6; }
.tl-scale { display: flex; justify-content: space-between; margin: -6px 14px 8px; font-size: 11px; color: var(--muted); }

.people { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.person { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); min-height: 52px; }
.person:last-child { border-bottom: 0; }
.person.mine { background: var(--brand-soft); cursor: pointer; }
.person.editable { cursor: pointer; }
.person .name { flex: 1; min-width: 0; }
.person .name strong { font-weight: 600; }
.person .detail { display: block; font-size: 13px; color: var(--muted); }
.person .detail .warn { color: var(--away); }
.halves { display: flex; gap: 3px; flex: none; }
.half {
  min-width: 34px; height: 30px; padding: 0 6px; border-radius: 8px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.half.office { background: var(--office-soft); color: var(--office); }
.half.home { background: var(--home-soft); color: var(--home); }
.half.away { background: var(--away-soft); color: var(--away); }
.half.off { background: var(--off-soft); color: var(--off); }
.half.none { border: 1.5px dashed var(--border); color: var(--muted); }
.half.full { min-width: 71px; }
.chev { color: var(--muted); flex: none; }

/* Week nav */
.weeknav { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.weeknav .label { flex: 1; text-align: center; font-weight: 600; }
.summary-strip { display: flex; gap: 6px; margin-bottom: 12px; }
.summary-strip button { flex: 1; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 6px 0; cursor: pointer; font-size: 12px; color: var(--muted); }
.summary-strip button b { display: block; font-size: 15px; color: var(--text); }
.summary-strip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; }
.dot.ok { background: var(--ok); } .dot.under { background: var(--bad); } .dot.closed, .dot.free { background: var(--closed); }

/* Month */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month-grid .wd { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.mday {
  aspect-ratio: 1 / 1; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; font-size: 15px; padding: 0;
}
.mday.out { visibility: hidden; }
.mday.free { background: transparent; color: var(--muted); border-style: dashed; }
.mday.closed { background: var(--closed-soft); color: var(--closed); }
.mday.under { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.mday.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.mday.today { outline: 2px solid var(--brand); outline-offset: 1px; }
.mday .mine { width: 18px; height: 5px; border-radius: 3px; }
.mday .mine.office { background: var(--office); } .mday .mine.home { background: var(--home); }
.mday .mine.away { background: var(--away); } .mday .mine.off { background: var(--off); }
.mday .mine.none { background: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 5px; }

/* Forms */
.form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=password], input[type=time], input[type=date], input[type=number], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 16px;
}
input[type=time] { min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.row { display: flex; gap: 8px; align-items: end; }
.row > * { flex: 1; min-width: 0; }
.row > .icon-btn { flex: none; }
.row input[type=number], .row input[type=time] { padding-left: 8px; padding-right: 6px; }
.row input[type=time]::-webkit-calendar-picker-indicator { display: none; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--text); font-size: 15px; padding: 6px 0; }
.switch input { width: 48px; height: 28px; appearance: none; -webkit-appearance: none; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(20px); }
.switch small { display: block; color: var(--muted); font-size: 13px; }

.notice { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.error-text { color: var(--bad); font-size: 14px; min-height: 1em; }
.muted { color: var(--muted); }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* Schedule editor */
.sched { display: grid; gap: 10px; }
.sched-day { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sched-day:last-child { border-bottom: 0; }
.sched-day .wdn { font-weight: 700; grid-row: span 2; }
.sched-day select, .sched-day input { min-height: 40px; font-size: 15px; padding: 6px 8px; }

/* List rows (admin) */
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 700; margin-left: 4px; }
.badge.gray { background: var(--off-soft); color: var(--off); }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 10px; }
.sheet h2 { font-size: 18px; }
.sheet .sheet-sub { color: var(--muted); font-size: 14px; margin: 2px 0 14px; }
.sheet h3 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin: 18px 0 8px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice {
  min-height: 56px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; text-align: left; font-weight: 600; font-size: 15px;
}
.choice .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.choice.wide { grid-column: span 2; }
.choice[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.sw.office { background: var(--office); } .sw.home { background: var(--home); } .sw.away { background: var(--away); } .sw.off { background: var(--off); }
.sw.split { background: linear-gradient(90deg, var(--office) 50%, var(--home) 50%); }
.custom-halves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.appt-list { list-style: none; padding: 0; margin: 0 0 8px; }
.appt-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--away-soft); margin-bottom: 6px; }
.appt-list li span { flex: 1; }
.sheet-actions { display: grid; gap: 8px; margin-top: 18px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.bad { background: var(--bad); color: #fff; }

/* Login / install */
body.plain { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login, .install { width: 100%; max-width: 400px; padding: 24px; }
.login h1, .install h1 { font-size: 22px; margin-bottom: 4px; }
.install h2 { font-size: 16px; margin: 18px 0 8px; }
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.logo { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 14px; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 4px 0; }
.checks .ok { color: var(--ok); } .checks .bad { color: var(--bad); }

@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (min-width: 700px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 18px; animation: fade .15s; }
  .sheet .grab { display: none; }
}
