:root {
  --bg: #f1f5f9; --surface: #ffffff; --fg: #16222a; --muted: #5a6a74; --line: #d9e1e5;
  --accent: #0b5c9e; --on-accent: #ffffff; --ok: #1d6b3a; --ok-bg: #e1f4e7;
  --bad: #a12626; --bad-bg: #fde7e5; --warn: #9a5200; --warn-bg: #fff1dc; --hatch: #e6ecef;
  --chip-s: 70%; --chip-l: 88%; --chip-fg: #16222a; --pip-l: 42%;
  --font-display: 'Outfit', system-ui, sans-serif;
  --font-body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070f22; --surface: #0e1a33; --fg: #e6edf7; --muted: #9fb0c8; --line: #22314d;
    --accent: #5cc0f0; --on-accent: #01102b; --ok: #7fd29b; --ok-bg: #16301f;
    --bad: #f19a95; --bad-bg: #3a1b1a; --warn: #f0b667; --warn-bg: #36280f; --hatch: #14213b;
    --chip-s: 38%; --chip-l: 24%; --chip-fg: #e5ecef; --pip-l: 58%;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font-body);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; font-weight: 600; letter-spacing: 0; }
h2 { font-size: 22px; } h3 { font-size: 17px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.hide { display: none !important; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.top img { width: 34px; height: 34px; border-radius: 8px; }
.brand { font-family: var(--font-display); font-weight: 600; font-size: 18px; }
.who { text-align: right; line-height: 1.2; }
.who b { display: block; font-size: 14px; } .who span { font-size: 12px; color: var(--muted); }
.tabs { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; min-height: 44px; }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 14px; font-weight: 600; min-height: 42px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 14px; }
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=button]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 8px; padding: 10px 12px; min-height: 44px;
  color-scheme: light dark; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input::placeholder { color: var(--muted); opacity: .8; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--hatch); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); }
.msg { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 14px; }
.msg.bad { background: var(--bad-bg); color: var(--bad); } .msg.ok { background: var(--ok-bg); color: var(--ok); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login .card { width: 100%; max-width: 400px; padding: 24px; }
.login .logo { display: block; width: 150px; max-width: 60%; margin: 0 auto 8px; }
.login h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.linkbtn { background: none; border: 0; color: var(--accent); padding: 8px 0; text-decoration: underline; font-weight: 500; }

/* month / calendar */
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.bar h2 { min-width: 170px; text-align: center; }
.locs { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 6px; margin-bottom: 10px; }
.loc { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; white-space: nowrap; font-size: 14px; font-weight: 500; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; }
.loc[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: hsl(var(--h) 70% var(--pip-l)); display: inline-block; flex: none; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 96px; padding: 4px; text-align: left; display: block; width: 100%; overflow: hidden; }
button.day:hover { border-color: var(--accent); }
.day.out { background: transparent; border-style: dashed; opacity: .5; }
.day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day .n { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 2px; }
.chip { display: block; background: hsl(var(--h) var(--chip-s) var(--chip-l)); color: var(--chip-fg); border-radius: 5px; padding: 1px 5px; margin-top: 2px; font-size: 12px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .cs { display: none; }
.more { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
@media (max-width: 640px) {
  .day { min-height: 64px; padding: 3px; }
  .chip { font-size: 9.5px; padding: 1px 3px; white-space: normal; overflow-wrap: anywhere; line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
  .chip .cf { display: none; }
  .chip .cs { display: inline; }
  .bar .spacer { display: none; }
  .bar h2 { min-width: 0; flex: 1 1 auto; font-size: 18px; white-space: nowrap; text-align: center; }
  .brand { font-size: 15px; line-height: 1.1; }
  .top-in { gap: 8px; padding: 8px 12px; }
  .who b { font-size: 13px; }
  .btn.small, .tab { white-space: nowrap; }
  .bar { gap: 8px; }
}

button.day.av-can, .day.av-can { background: var(--ok-bg); border-color: var(--ok); }
button.day.av-cant, .day.av-cant { background: var(--bad-bg); border-color: var(--bad); }
.day.blackout { background: repeating-linear-gradient(45deg, var(--hatch), var(--hatch) 6px, transparent 6px, transparent 12px); }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 15px; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }

/* modal */
#modal-root:empty { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(5, 10, 25, .55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; overflow-y: auto; overscroll-behavior: contain; }
.sheet { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; max-height: 92dvh; overflow-y: scroll; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-width: thin; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet::-webkit-scrollbar { width: 10px; } .sheet::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid var(--surface); }
.sheet .stickybar { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--surface); padding: 10px 0 4px; margin-top: 8px; border-top: 1px solid var(--line); z-index: 1; }
@media (min-width: 700px) { .scrim { align-items: center; padding: 16px; } .sheet { border-radius: 16px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); } }
body.noscroll { overflow: hidden; }
.sheet h3 { margin-bottom: 12px; }
.list { list-style: none; margin: 0 0 14px; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 12px; margin-bottom: 12px; }
.checks label { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.checks input { width: 20px; height: 20px; }
#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* messages */
.thread { display: flex; flex-direction: column; gap: 8px; height: min(52vh, 420px); overflow-y: auto; padding: 4px 2px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.bubble .meta { display: block; font-size: 11px; opacity: .75; margin-bottom: 2px; }
.composer { display: flex; gap: 8px; margin: 12px 0 0; }
.composer input { flex: 1; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

@media (max-width: 560px) { .hide-sm { display: none; } }

a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.calbtns { display: grid; gap: 10px; margin: 10px 0; }
.calbtns.two { grid-template-columns: 1fr 1fr; }
.calbtn { display: flex; align-items: center; justify-content: center; text-align: center; text-decoration: none; padding: 14px 16px; border-radius: 10px; font-weight: 600; font-size: 1rem; min-height: 48px; border: 1px solid transparent; cursor: pointer; line-height: 1.2; }
.calbtn.apple { background: #0b5c9e; color: #fff; }
.calbtn.google { background: #1a73e8; color: #fff; }
.calbtn.alt { background: var(--surface); color: var(--fg); border-color: var(--line); }
