:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --card: #1c1c21;
    --text: #f2f2f5;
    --muted: #9ca3af;
    --line: #2d2d34;
    --accent: #818cf8;
    --accent-soft: #25264a;
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2 { margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); font-weight: 400; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text);
  font-size: 26px; line-height: 1; text-decoration: none;
}
.icon-btn:active { background: var(--line); }

.banner {
  margin: 10px 12px 0; padding: 10px 12px; border-radius: var(--radius);
  background: #fef3c7; color: #78350f; font-size: 14px;
}
.banner a { color: inherit; font-weight: 700; }
@media (prefers-color-scheme: dark) { .banner { background: #3b2f0b; color: #fde68a; } }

/* ---------- Main ---------- */
.app { max-width: 900px; margin: 0 auto; padding: 8px 12px 24px; }

.datebar { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.date-label {
  flex: 1; border: 0; background: none; font-size: 17px; font-weight: 600;
  padding: 8px 4px; border-radius: 10px; text-align: center;
}
.date-label:active { background: var(--line); }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  background: var(--line); padding: 2px; border-radius: 10px; margin: 4px 0 10px;
}
.segmented button { border: 0; background: transparent; padding: 7px; border-radius: 8px; font-weight: 500; }
.segmented button.active { background: var(--card); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 10px; }
.weekstrip .day {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 0; background: var(--card); border-radius: 12px; padding: 6px 0 7px; min-width: 0;
}
.weekstrip small { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.weekstrip b { font-size: 17px; }
.weekstrip .today b { color: var(--accent); }
.weekstrip .sel { background: var(--accent); color: #fff; }
.weekstrip .sel small, .weekstrip .sel b { color: #fff; }
.dots { display: flex; gap: 2px; height: 6px; flex-wrap: wrap; justify-content: center; max-width: 90%; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
.sel .dots i { box-shadow: 0 0 0 1px #fff; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 4px 10px 4px 6px; font-size: 13px;
}
.chip i { width: 12px; height: 12px; border-radius: 50%; }
.chip.muted { opacity: .45; }
.chip.muted i { background: transparent !important; box-shadow: inset 0 0 0 2px var(--muted); }
.chip.off { opacity: .6; border-style: dashed; cursor: default; }

.free-card { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.free-card p { margin: 0; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; }
.slot {
  background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok);
  border-radius: 8px; padding: 4px 9px; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums;
}

/* ---------- Day timeline ---------- */
.timeline { background: var(--card); border-radius: var(--radius); overflow: clip; }
.tl-head {
  display: flex; position: sticky; top: calc(57px + env(safe-area-inset-top)); z-index: 5;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.tl-gutter { width: 46px; flex: none; }
.tl-name {
  flex: 1; min-width: 0; text-align: center; padding: 8px 2px 6px; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 3px solid var(--c);
}
.tl-body { position: relative; display: flex; margin: 10px 0; }
.tl-hours { width: 46px; flex: none; position: relative; }
.tl-hours span {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.tl-cols {
  flex: 1; display: flex; position: relative;
  background-image: linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% var(--hour);
  border-bottom: 1px solid var(--line);
}
.tl-col { flex: 1; position: relative; border-left: 1px solid var(--line); min-width: 0; }
.blk {
  position: absolute; left: 3px; right: 3px; border: 0; border-radius: 6px; padding: 3px 4px;
  color: #fff; text-align: left; overflow: hidden; opacity: .9;
}
.blk span { font-size: 11px; font-weight: 600; line-height: 1.15; display: block; font-variant-numeric: tabular-nums; }
.blk:active { opacity: 1; filter: brightness(1.1); }
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; margin: 0; }

/* ---------- Week view ---------- */
.weeklist { background: var(--card); border-radius: var(--radius); padding: 6px 10px 10px; }
.wscale, .wrow { display: grid; grid-template-columns: 44px 1fr; gap: 8px; }
.ticks { position: relative; height: 18px; }
.ticks span { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--muted); }
.ticks span:first-child { transform: none; }
.ticks span:last-child { transform: translateX(-100%); }
.wrow {
  width: 100%; border: 0; background: none; text-align: left;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.wlabel { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.wlabel small { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.wlabel b { font-size: 18px; }
.wrow.today .wlabel b { color: var(--accent); }
.wtracks { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.track { position: relative; height: 9px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.track span { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.wfree { color: var(--muted); font-size: 12px; margin-top: 2px; }

.status { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0 0; min-height: 1em; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .25); z-index: 50; max-width: calc(100% - 32px); text-align: center;
}

/* ---------- Cards, buttons, forms ---------- */
.center-card { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; }
.center-card .card { max-width: 380px; width: 100%; text-align: center; padding: 28px 22px; }
.center-card h1 { font-size: 22px; margin: 8px 0; }
.center-card p { margin: 0 0 20px; }
.logo { width: 64px; height: 64px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--accent); color: #fff; font-weight: 600; text-decoration: none;
}
.btn:active { filter: brightness(.92); }
.btn-google { background: var(--card); color: var(--text); border: 1px solid var(--line); width: 100%; padding: 12px; }
.btn-light { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-small { padding: 6px 10px; font-size: 13px; }

.admin { max-width: 640px; margin: 0 auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.admin p { margin: 0 0 10px; }
input[type=text], input[type=email] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
  font-size: 16px; /* prevents iOS zoom */
}
input[type=color] { width: 40px; height: 40px; border: 0; padding: 0; background: none; border-radius: 50%; flex: none; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 50%; }
input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }

.add-form { display: grid; grid-template-columns: 1fr; gap: 10px; }
.add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.add-form .color-label { flex-direction: row; align-items: center; gap: 10px; }
@media (min-width: 560px) {
  .add-form { grid-template-columns: 2fr 1fr auto auto; align-items: end; }
  .add-form .color-label { flex-direction: column; align-items: flex-start; gap: 4px; }
}

.share { display: flex; gap: 8px; }

.members { list-style: none; margin: 0; padding: 0; }
.members li + li { border-top: 1px solid var(--line); }
.member-row { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; padding: 10px 0; align-items: start; }
.member-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.member-info input { padding: 6px 8px; font-weight: 600; }
.member-info small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.member-info .st-ok { color: var(--ok); }
.member-info .st-warn { color: var(--warn); }
.member-actions { grid-column: 2; display: flex; gap: 6px; flex-wrap: wrap; }

.flash { padding: 10px 12px; border-radius: var(--radius); font-size: 14px; }
.flash.ok { background: color-mix(in srgb, var(--ok) 15%, var(--card)); }
.flash.err { background: color-mix(in srgb, var(--danger) 15%, var(--card)); }
