/* House Lights: warm, mobile first, light and dark. */

:root {
  --bg: #f6efe6;
  --bg-elev: #fffaf3;
  --card: #fffaf3;
  --card-off: #efe6da;
  --text: #2b2118;
  --muted: #7b6a5c;
  --line: rgba(60, 40, 20, 0.12);
  --accent: #e0862e;
  --accent-strong: #c96f16;
  --accent-text: #ffffff;
  --danger: #c2410c;
  --danger-bg: #fde8dc;
  --track: rgba(60, 40, 20, 0.14);
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
  --radius: 20px;
  --tap: 48px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171210;
    --bg-elev: #241b16;
    --card: #241b16;
    --card-off: #1d1613;
    --text: #f4ebe0;
    --muted: #a6968a;
    --line: rgba(255, 230, 200, 0.12);
    --accent: #ffb347;
    --accent-strong: #ff9d1a;
    --accent-text: #2b1d16;
    --danger: #ff8a5b;
    --danger-bg: #3a2018;
    --track: rgba(255, 230, 200, 0.18);
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: calc(8px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.topbar-row { display: flex; align-items: center; gap: 10px; }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; }

.brand { font-size: 22px; display: flex; align-items: center; gap: 8px; }
.brand-icon, .login-icon {
  display: inline-block;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #fff1d6 0 38%, var(--accent) 40% 60%, transparent 62%);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 70%, transparent);
}
.login-icon { width: 56px; height: 56px; margin: 0 auto 12px; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text);
  box-shadow: var(--shadow);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }

.badge {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 4px 8px; border-radius: 999px;
  background: var(--danger-bg); color: var(--danger);
}

/* ---------- buttons ---------- */

.big-btn {
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-elev);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow);
  flex: 1;
  text-align: center;
}
.big-btn svg { width: 22px; height: 22px; }
.big-btn:active { transform: scale(0.98); }
.big-btn:disabled { opacity: 0.55; cursor: default; }
.big-btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.big-btn.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.big-btn.secondary { background: var(--bg-elev); }
.big-btn.subtle { background: transparent; box-shadow: none; border-color: var(--line); }
.big-btn.small { min-height: 40px; padding: 6px 14px; font-size: 15px; border-radius: 12px; flex: 0 0 auto; }

.row-buttons { display: flex; gap: 10px; margin-top: 14px; }
.big-btn.full { width: 100%; margin-top: 22px; }

/* ---------- login ---------- */

.login-view { display: flex; justify-content: center; padding: 15vh 16px 40px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  text-align: center;
}
.login-card h2 { font-size: 26px; margin-bottom: 4px; }
.login-card form { display: grid; gap: 12px; margin-top: 20px; }
.login-card input {
  min-height: 54px; font-size: 20px; text-align: center;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); padding: 0 14px; width: 100%;
}
.login-card input:focus { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.form-error { color: var(--danger); margin: 0; font-weight: 600; }

.loading-view { display: flex; justify-content: center; padding: 30vh 0; }

/* ---------- home: room cards ---------- */

#dashboard-view { padding: 10px 16px 40px; max-width: 760px; margin: 0 auto; }

/* The first room spans the full width, the rest sit two side by side. */
.room-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }

.room-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.room-grid > .room-card:first-child { grid-column: 1 / -1; aspect-ratio: 16 / 10; }

.room-open {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  padding: 0; border: none; background: none;
  text-align: left;
}
.room-open:active { opacity: 0.9; }

.room-photo {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--accent) 38%, var(--card)) 0, var(--card-off) 72%);
  transition: filter 0.35s ease;
}
.room-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.room-photo svg { width: 30%; height: 30%; color: var(--accent); margin-bottom: 14%; }
/* A room with every light off shows its photo dimmed. */
.room-card.is-off .room-photo { filter: brightness(0.5) saturate(0.6); }

.room-text {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 44px 14px 14px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.66), rgba(0, 0, 0, 0));
}
.room-text h2 { font-size: 20px; line-height: 1.15; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); overflow-wrap: break-word; }
.room-grid > .room-card:first-child .room-text h2 { font-size: 26px; }
.room-status { margin: 3px 0 0; font-size: 14px; font-weight: 600; color: rgba(255, 255, 255, 0.88); }

/* Power sits top right; in edit mode the pencil takes the top left. */
.room-power { position: absolute; top: 12px; right: 12px; }
.room-card .card-edit { left: 12px; right: auto; top: 12px; }

.room-card.add-room {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--line); background: transparent; box-shadow: none;
  color: var(--muted); font-weight: 600;
}
.room-card.add-room svg { width: 32px; height: 32px; }

.round-btn {
  width: 48px; height: 48px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  transition: background-color 0.25s ease, color 0.25s ease;
}
.round-btn svg { width: 24px; height: 24px; }
.round-btn:active { transform: scale(0.94); }
.round-btn:disabled { opacity: 0.5; }
.round-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* ---------- room: light tiles ---------- */

.room-view-head { display: flex; align-items: center; gap: 12px; margin: 8px 0 14px; }
.room-view-head h2 { font-size: 26px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.room-actions { display: flex; gap: 10px; margin-bottom: 14px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }

.tile {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  --glow: #ffb347;
  transition: box-shadow 0.35s ease, background-color 0.35s ease, opacity 0.35s ease;
}
.tile.is-on {
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--glow) 70%, transparent),
    0 8px 26px color-mix(in srgb, var(--glow) 35%, transparent),
    var(--shadow);
}
.tile.is-off { background: var(--card-off); }
.tile.is-offline { opacity: 0.6; }

.tile-open {
  display: block; width: 100%;
  padding: 10px; border: none; background: none;
  text-align: left; border-radius: inherit;
}
.tile-photo {
  aspect-ratio: 1 / 1;
  border-radius: 14px; overflow: hidden;
  background: var(--bg); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.35s ease;
}
.tile-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-photo svg { width: 44%; height: 44%; color: var(--glow); }
.tile.is-off .tile-photo, .tile.is-offline .tile-photo { opacity: 0.6; }
.tile.is-off .tile-photo svg, .tile.is-offline .tile-photo svg { color: var(--muted); }
.tile-text { padding: 10px 52px 2px 2px; min-height: 58px; }
.tile-name { font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.tile-status { margin: 3px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.tile-status.offline { color: var(--danger); }
.tile-power { position: absolute; right: 10px; bottom: 12px; width: 44px; height: 44px; }
.tile.is-hidden-device { outline: 2px dashed var(--muted); outline-offset: 2px; }

/* ---------- light controls card (shown in the light sheet) ---------- */

.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  --glow: #ffb347;
  --glow-alpha: 0;
  transition: box-shadow 0.35s ease, background-color 0.35s ease, opacity 0.35s ease;
}
.card.is-on {
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--glow) 70%, transparent),
    0 10px 32px color-mix(in srgb, var(--glow) calc(var(--glow-alpha) * 100%), transparent),
    var(--shadow);
}
.card.is-off { background: var(--card-off); }
.card.is-off .card-photo, .card.is-off .card-name { opacity: 0.6; }
.card.is-offline { opacity: 0.6; }
.card.is-offline .card-controls, .card.is-offline .card-toggles { pointer-events: none; filter: grayscale(1); opacity: 0.5; }
.card.is-busy::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius);
  pointer-events: none;
}

.card-top { display: grid; grid-template-columns: 84px 1fr auto; gap: 12px; align-items: center; }

.card-photo {
  width: 84px; height: 84px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line);
  transition: opacity 0.35s ease;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-photo svg { width: 46px; height: 46px; color: var(--glow); }
.card.is-off .card-photo svg, .card.is-offline .card-photo svg { color: var(--muted); }

.card-head { min-width: 0; }
.card-name { font-size: 19px; line-height: 1.2; overflow-wrap: anywhere; }
.card-status { margin: 4px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.card-status.offline { color: var(--danger); }

.card-toggles { display: grid; gap: 8px; justify-items: end; }
.toggle-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.toggle-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* Big switch */
.switch {
  position: relative;
  width: 76px; height: 44px;
  border-radius: 999px;
  border: none;
  background: var(--track);
  padding: 0;
  transition: background-color 0.25s ease;
}
.switch::after {
  content: "";
  position: absolute; top: 4px; left: 4px;
  width: 36px; height: 36px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s ease;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(32px); }
.switch:disabled { opacity: 0.6; }

.card-controls { display: grid; gap: 12px; margin-top: 12px; }
.card-controls:empty { display: none; }

.slider-row { display: grid; grid-template-columns: 28px 1fr 44px; align-items: center; gap: 10px; }
.slider-row svg { width: 22px; height: 22px; color: var(--muted); }
.slider-value { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); text-align: right; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 44px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 12px; border-radius: 999px;
  background: var(--range-bg, var(--track));
}
input[type="range"]::-moz-range-track {
  height: 12px; border-radius: 999px;
  background: var(--range-bg, var(--track));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line);
  margin-top: -9px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
input[type="range"]:disabled { opacity: 0.5; }
.brightness-slider { --range-bg: linear-gradient(90deg, #4a3b2e, #ffcf7a); }
.warmth-slider { --range-bg: linear-gradient(90deg, #ffb46b, #fff4e0 55%, #cfe3ff); }

.presets {
  display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.presets::-webkit-scrollbar { display: none; }
.preset {
  flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 2px 6px rgba(0, 0, 0, 0.18);
  padding: 0;
  position: relative;
}
.preset:active { transform: scale(0.92); }
.preset.active { box-shadow: 0 0 0 3px var(--accent); }
.preset.picker {
  background: conic-gradient(#ff5f5f, #ffd25f, #7cff6b, #5fd8ff, #7a6bff, #ff6bd6, #ff5f5f);
  overflow: hidden;
}
.preset.picker input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.more-row { display: flex; justify-content: flex-end; }
.more-btn { background: none; border: none; color: var(--muted); font-weight: 600; min-height: 40px; padding: 0 8px; }
.card.expanded .more-btn svg { transform: rotate(180deg); }
.more-btn svg { width: 16px; height: 16px; vertical-align: -3px; transition: transform 0.2s; }
.extra { display: none; gap: 12px; }
.card.expanded .extra { display: grid; }

.scene-row { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 10px; }
.scene-row svg { width: 22px; height: 22px; color: var(--muted); }
select.scene-select, .field select, .field input {
  min-height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 12px;
  width: 100%;
}

.card-edit {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--accent); color: var(--accent-text);
  display: none; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.card-edit svg { width: 20px; height: 20px; }
body.edit-mode .card-edit { display: inline-flex; }
body:not(.is-admin) .admin-only { display: none !important; }
body:not(.edit-mode) .edit-only { display: none !important; }

/* Inside the sheet the card is the whole view, so it drops its own frame and shows every control. */
.card.in-sheet, .card.in-sheet.is-on, .card.in-sheet.is-off { background: transparent; border: none; box-shadow: none; padding: 0; }
.card.in-sheet .more-row, .card.in-sheet .card-edit { display: none !important; }
.card.in-sheet .card-name { font-size: 22px; margin: 0; color: var(--text); text-transform: none; letter-spacing: -0.01em; }
.card.is-hidden-device { outline: 2px dashed var(--muted); outline-offset: 2px; }
.card.is-hidden-device::before {
  content: "Hidden from sitters";
  position: absolute; left: 14px; bottom: 8px;
  font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.card.is-hidden-device { padding-bottom: 26px; }

.empty { text-align: center; padding: 40px 0; }
.status-line { text-align: center; font-size: 13px; margin: 26px 0 0; }

/* ---------- sheets ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 10, 5, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  animation: slide-up 0.25s ease;
}
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 24px; }
}
.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 22px; margin-bottom: 14px; }
.sheet h3 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 22px 0 8px; }
.field { display: grid; gap: 6px; margin-top: 14px; }
.field > span { font-weight: 600; font-size: 15px; }
.field.check { grid-template-columns: auto 1fr; align-items: center; gap: 12px; min-height: var(--tap); }
.field.check input { width: 26px; height: 26px; accent-color: var(--accent); }
.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; min-width: 0; }
.inline-form .big-btn { flex: 0 0 auto; }

.photo-edit { display: grid; gap: 10px; }
.photo-preview {
  width: 100%; aspect-ratio: 4 / 3; max-height: 240px;
  border-radius: 16px; overflow: hidden;
  background: var(--bg); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.photo-preview.wide { aspect-ratio: 16 / 10; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview svg { width: 64px; height: 64px; color: var(--muted); }
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-buttons .subtle { grid-column: 1 / -1; }

/* ---------- voice ---------- */

.voice-log { display: grid; gap: 8px; max-height: 38vh; overflow-y: auto; margin-bottom: 6px; }
.voice-log:empty { display: none; }
.voice-line { margin: 0; padding: 10px 14px; border-radius: 16px; max-width: 85%; overflow-wrap: break-word; }
.voice-line.you { justify-self: end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.voice-line.lights { justify-self: start; background: var(--card-off); border-bottom-left-radius: 6px; }
.voice-line.note { justify-self: start; color: var(--muted); font-size: 14px; padding: 0 4px; }
.voice-line.error { justify-self: start; color: var(--danger); font-size: 14px; font-weight: 600; padding: 0 4px; }

.mic-wrap { display: flex; justify-content: center; padding: 10px 0 4px; }
.mic-btn {
  width: 88px; height: 88px; border-radius: 50%;
  border: none; padding: 0;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.mic-btn svg { width: 40px; height: 40px; }
.mic-btn:active { transform: scale(0.95); }
.mic-btn:disabled { opacity: 0.55; }
.mic-btn.listening { animation: pulse 1.2s ease-in-out infinite; }
/* Hold to talk: no text selection, callout menu or scrolling from a long press. */
.mic-btn, #voice-btn, .talk-btn { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; }

/* The big hold-to-talk button at the top of a room page. */
.talk-btn {
  width: 100%; min-height: 76px;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 12px 20px;
  border: none; border-radius: 22px;
  background: var(--accent); color: var(--accent-text);
  font-size: 20px; font-weight: 700;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 40%, transparent);
}
.talk-btn:active { transform: scale(0.98); }
.talk-btn.listening { animation: pulse 1.2s ease-in-out infinite; }
.talk-btn.busy { opacity: 0.7; }
.talk-icon {
  width: 48px; height: 48px; border-radius: 50%; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent-text) 16%, transparent);
}
.talk-icon svg { width: 28px; height: 28px; }
.talk-status { margin: 8px 4px 14px; min-height: 22px; text-align: center; font-weight: 600; color: var(--muted); }
.talk-status:empty { margin-bottom: 6px; }
.talk-status.error { color: var(--danger); }
#voice-btn.listening { background: var(--accent); color: var(--accent-text); border-color: transparent; animation: pulse 1.2s ease-in-out infinite; }
.voice-hint { text-align: center; min-height: 20px; margin: 6px 0 12px; }

/* ---------- schedules ---------- */

.sheet.tall { min-height: 70vh; min-height: 70dvh; }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-title-row h2 { margin: 0; }
.step-label { margin: 14px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.pause-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.pause-row p { margin: 0; }
.pause-title { font-weight: 700; }
.paused-note { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--danger-bg); color: var(--danger); font-weight: 600; }

/* Chips: the editor is answered with these. */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 14px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
  font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; gap: 8px;
}
.chip small { font-weight: 500; font-size: 12px; opacity: 0.75; }
.chip.selected, .chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip.ghost { background: transparent; border-style: dashed; color: var(--muted); }
.chip:active { transform: scale(0.97); }
.swatch { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); }

/* Month calendar */
.cal { margin: 16px 0 6px; padding: 12px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); }
.cal.compact { margin-top: 12px; background: var(--bg); }
.cal .chip-row { margin-top: 10px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { margin: 0; font-weight: 700; font-size: 18px; }
.cal-nav { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-elev); font-size: 26px; line-height: 1; padding: 0 0 3px; }
.cal-nav:disabled { opacity: 0.35; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 2px 0 4px; }
.cal-day {
  position: relative; aspect-ratio: 1 / 1; min-height: 40px; padding: 0;
  border: none; border-radius: 12px; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.cal-day.past { color: var(--muted); opacity: 0.55; }
.cal-day.busy { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.cal-day.today .cal-num { width: 28px; height: 28px; line-height: 28px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day.selected, .cal-day.picked { background: var(--accent); color: var(--accent-text); opacity: 1; }
.cal-day.selected .cal-dots i { background: var(--accent-text); }
.cal-day.range-start { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day:disabled { cursor: default; }
.cal-dots { display: flex; gap: 3px; height: 5px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-strong); }

/* The chosen day's timeline */
.agenda { margin: 6px 0 4px; }
.agenda-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0 8px; }
.agenda-title { margin: 0; font-weight: 700; font-size: 17px; }
.agenda-list { display: grid; gap: 6px; }
.agenda-item, .agenda-sun { display: grid; grid-template-columns: 76px 1fr; gap: 10px; align-items: center; }
.agenda-item { padding: 10px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); }
.agenda-item.off { border-left-color: var(--muted); }
.agenda-item.editable { cursor: pointer; }
.agenda-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.agenda-text { display: grid; gap: 2px; min-width: 0; }
.agenda-text span { font-size: 14px; color: var(--muted); }
.agenda-sun { padding: 2px 12px 2px 16px; font-size: 13px; color: var(--muted); }
.agenda-sun .agenda-time { font-size: 13px; font-weight: 600; }
.agenda-empty { margin: 4px 0; }

/* Every schedule */
.schedule-list { display: grid; gap: 10px; margin: 6px 0 4px; }
.schedule-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  padding: 14px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line);
}
.schedule-item.editable { cursor: pointer; }
.schedule-item.editable:active { transform: scale(0.99); }
.schedule-item.is-off .schedule-main { opacity: 0.55; }
.schedule-main { min-width: 0; }
.schedule-name { margin: 0; font-weight: 700; font-size: 17px; overflow-wrap: break-word; }
.schedule-line { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.schedule-next { margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--accent-strong); }
.schedule-next.warn, .warn-text { color: var(--danger); }

/* Editor */
.sched-summary { margin: -6px 0 6px; font-weight: 600; color: var(--accent-strong); }
.sched-step { padding: 14px 0; border-bottom: 1px solid var(--line); }
.sched-step h4 { margin: 0 0 10px; font-size: 17px; }
.sched-step .chip-row + .chip-row { margin-top: 10px; }
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.preset-card {
  display: grid; gap: 2px; text-align: left; min-height: 64px;
  padding: 10px 14px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--bg);
}
.preset-card span { font-size: 13px; color: var(--muted); }
.preset-card.selected { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.preset-card.selected span { color: inherit; opacity: 0.8; }
.preset-card.off.selected { background: var(--text); color: var(--bg); }
.time-wrap { display: block; margin-top: 10px; }
.time-wrap input { width: 100%; min-height: 56px; font-size: 22px; font-weight: 700; text-align: center; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; }
.day-chips { display: flex; gap: 6px; margin-top: 10px; }
.day-chip {
  flex: 1; min-width: 0; min-height: 44px; padding: 0;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-weight: 700;
}
.day-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.sched-more { padding: 14px 0 4px; }
.sched-more summary { font-weight: 600; color: var(--muted); cursor: pointer; min-height: 32px; }
.sched-more input { width: 100%; margin-top: 8px; min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; }
.sticky-actions {
  position: sticky; bottom: calc(-22px - env(safe-area-inset-bottom));
  display: flex; gap: 10px; margin: 14px -18px 0; padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg-elev); border-top: 1px solid var(--line);
}

/* ---------- toast, spinner, pull indicator ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 14px;
  font-weight: 600; z-index: 60;
  max-width: calc(100vw - 32px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  animation: fade-in 0.2s ease;
}
.toast.error { background: var(--danger); color: #fff; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--track); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block;
}

.pull-indicator {
  position: fixed; top: 0; left: 50%; transform: translate(-50%, -60px);
  z-index: 30; transition: transform 0.2s ease;
  background: var(--bg-elev); border-radius: 50%; padding: 8px;
  box-shadow: var(--shadow);
}
.pull-indicator.visible { transform: translate(-50%, calc(14px + env(safe-area-inset-top))); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  50% { box-shadow: 0 0 0 18px color-mix(in srgb, var(--accent) 0%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
