/* AllMyEvents — flat design, no gradients, Helvetica. Light (eggshell) by default, dark as an option. */

:root {
  --bg: #F3EFE4;
  --surface: #FBF9F3;
  --surface-2: #ECE7DA;
  --text: #1E1D1A;
  --muted: #6B675E;
  --border: #D9D3C4;
  --primary: #1E1D1A;
  --primary-text: #FBF9F3;
  --ok: #2F6B3A;
  --warn: #8A6100;
  --warn-bg: #FFE9A8;
  --warn-border: #E3C25A;
  --warn-text: #3D2E00;
  --error: #A12A1F;
  --error-bg: #F9E1DD;
  --success-bg: #DDEFD9;
  --focus: #2C5DB8;
  --radius: 8px;
  --panel-w: 290px;
  --topbar-h: 56px;
  --font: Helvetica, "Helvetica Neue", Arial, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #161614;
  --surface: #20201D;
  --surface-2: #2A2A26;
  --text: #EDEAE2;
  --muted: #A09B90;
  --border: #3A3933;
  --primary: #EDEAE2;
  --primary-text: #161614;
  --ok: #7FC48B;
  --warn: #F2C94C;
  --warn-bg: #4A3C0F;
  --warn-border: #7A6420;
  --warn-text: #FFF3CC;
  --error: #F08A7E;
  --error-bg: #3D1F1B;
  --success-bg: #1F3321;
  --focus: #8DB0F0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h1, h2, h3 { letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* --- Top bar ------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { font-size: 19px; font-weight: 700; text-decoration: none; margin-right: auto; }
.view-switch { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.view-switch a { padding: 6px 12px; text-decoration: none; font-size: 14px; color: var(--muted); }
.view-switch a.on { background: var(--primary); color: var(--primary-text); }
.icon-btn { position: relative; font-size: 18px; width: 40px; padding: 0; }
.add-btn { width: 40px; padding: 0; font-size: 22px; line-height: 1; }
.dot-count {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--primary); color: var(--primary-text);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* --- Layout: collapsible side panel, drawer on phones --------------------- */

.layout { display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr); }
.layout.panel-collapsed { grid-template-columns: minmax(0, 1fr); }
.layout.panel-collapsed .panel { display: none; }
.panel {
  position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top));
  height: calc(100vh - var(--topbar-h) - env(safe-area-inset-top));
  overflow-y: auto; padding: 16px; border-right: 1px solid var(--border); background: var(--bg);
}
.content {
  min-width: 0; max-width: 900px; width: 100%; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

@media (max-width: 899px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .panel {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: auto;
    width: min(86vw, 320px);
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-100%); transition: transform 0.2s ease;
    visibility: hidden;
  }
  .panel.open { transform: none; visibility: visible; }
  .backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.35); }
}
@media (max-width: 520px) {
  .brand { font-size: 16px; }
  .view-switch a { padding: 6px 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}

.panel-section { display: flex; flex-direction: column; gap: 10px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: 0; }
.panel-section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; }
.nav-link { display: block; padding: 7px 10px; border-radius: var(--radius); text-decoration: none; }
.nav-link:hover { background: var(--surface-2); }
.nav-link-current { background: var(--primary); color: var(--primary-text); }
.nav-link-current:hover { background: var(--primary); }
.filter-group { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.two-col label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

/* --- Controls -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  font: inherit; font-size: 15px; color: var(--text); text-decoration: none; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.btn:hover { border-color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-on { background: var(--surface-2); border-color: var(--text); font-weight: 600; }
.btn-danger { color: var(--error); }
.btn-danger:hover { border-color: var(--error); }
.btn-small { min-height: 32px; padding: 0 10px; font-size: 14px; }
.link-button { background: none; border: 0; padding: 0; font: inherit; font-size: 14px; color: var(--muted); text-decoration: underline; cursor: pointer; }

.input {
  width: 100%; min-height: 40px; padding: 8px 10px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
textarea.input { resize: vertical; }
.input:focus { border-color: var(--text); outline: none; }
.input-small { width: auto; min-height: 32px; padding: 4px 8px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.color-input { width: 44px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.icon-input { width: 64px; text-align: center; }
.grow { flex: 1 1 180px; width: auto; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segmented button { font: inherit; font-size: 15px; padding: 8px 14px; border: 0; background: var(--surface); color: var(--text); cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.on { background: var(--primary); color: var(--primary-text); }

/* --- Chips & badges ------------------------------------------------------------ */

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 6px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.chip-small { font-size: 12.5px; padding: 1px 8px 1px 5px; gap: 5px; }
.chip-button { cursor: pointer; min-height: 32px; }
.chip-button[aria-pressed="true"] { border-color: var(--text); }
.chip-off { opacity: 0.45; }
.chip-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chip-icon { font-size: 0.95em; line-height: 1; }

.badge {
  display: inline-block; padding: 1px 8px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
}
.badge-cancelled { color: var(--error); border-color: var(--error); background: var(--error-bg); }
.badge-updated { color: var(--warn); border-color: var(--warn-border); }
.badge-alert { color: var(--warn-text); background: var(--warn-bg); border-color: var(--warn-border); }

/* --- Pages ----------------------------------------------------------------------- */

.page-header { margin-bottom: 16px; }
.back-link { display: inline-block; margin-bottom: 6px; color: var(--muted); text-decoration: none; font-size: 15px; }
.page-header-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-title { font-size: 26px; margin: 0; line-height: 1.2; overflow-wrap: anywhere; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--muted); }
.count { font-size: 14px; margin: 0 0 8px; }
.empty { color: var(--muted); padding: 24px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.error-box { color: var(--error); background: var(--error-bg); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; flex-basis: 100%; }
.success-box { background: var(--success-bg); border-radius: var(--radius); padding: 10px 12px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--muted); }
details[open] > summary::before { content: "▾"; }
details[open] > summary { margin-bottom: 12px; }
.inline { display: inline; margin: 0; }

/* --- Event list ------------------------------------------------------------------ */

.day-group { margin-bottom: 20px; }
.day-title { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin: 0 0 8px; }
.event-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.event-row { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 12px; padding: 12px 14px; text-decoration: none; }
.event-row + .event-row { border-top: 1px solid var(--border); }
.event-row:hover { background: var(--surface-2); }
.event-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.event-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.event-title { font-weight: 600; font-size: 16.5px; overflow-wrap: anywhere; }
.event-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 14px; }
.star { margin-right: 4px; }
.is-cancelled .event-title, .is-cancelled .cal-chip-text { text-decoration: line-through; color: var(--muted); }
@media (max-width: 520px) {
  .event-row { grid-template-columns: 1fr; gap: 2px; }
}

/* --- Calendar ---------------------------------------------------------------------- */

.calendar {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--border); gap: 1px;
  margin-bottom: 20px;
}
.cal-weekday { background: var(--surface-2); font-size: 12.5px; font-weight: 700; text-align: center; padding: 6px 0; color: var(--muted); }
.cal-day {
  display: flex; flex-direction: column; align-items: stretch; gap: 3px; min-height: 104px; padding: 4px;
  font: inherit; text-align: left; color: var(--text); background: var(--surface); border: 0; cursor: pointer;
}
.cal-day:hover { background: var(--surface-2); }
.cal-out { background: var(--bg); color: var(--muted); }
.cal-num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 12px; }
.cal-today .cal-num { background: var(--primary); color: var(--primary-text); }
.cal-selected { box-shadow: inset 0 0 0 2px var(--text); }
.cal-events { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-chip {
  display: flex; align-items: center; gap: 3px; min-width: 0;
  font-size: 12px; line-height: 1.3; padding: 1px 3px; border-left: 3px solid; background: var(--surface-2); border-radius: 3px;
}
.cal-chip-icon { flex: none; font-size: 11px; }
.cal-chip-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-more { font-size: 11.5px; color: var(--muted); padding-left: 3px; }
@media (max-width: 640px) {
  .cal-day { min-height: 58px; align-items: center; }
  .cal-events { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .cal-chip { padding: 0 2px; border-left-width: 3px; }
  .cal-chip-text { display: none; }
  .cal-more { padding: 0; }
}

/* --- Event page ---------------------------------------------------------------------- */

.detail-chips { margin: -4px 0 16px; }
.details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.detail-row { display: contents; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.description { white-space: pre-line; margin: 16px 0 0; }
.is-cancelled-card { border-color: var(--error); }
@media (max-width: 520px) {
  .details { grid-template-columns: 1fr; gap: 2px; }
  .details dd { margin-bottom: 8px; }
}

.warning-bubble {
  background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
}
.warning-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.warning-bubble .btn { background: transparent; color: var(--warn-text); border-color: var(--warn-border); }
.warning-bubble .muted { color: inherit; opacity: 0.75; font-size: 13px; }
.warning-item { margin-top: 8px; }
.change-list { margin: 4px 0 0; padding-left: 18px; }
.history-item { padding: 8px 0; border-top: 1px solid var(--border); }
.history-item .muted { font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.danger-zone { margin-top: 24px; }

/* --- Forms ------------------------------------------------------------------------------ */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field-label { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12.5px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.sticky-actions {
  position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
}
.route-edit {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 8px 12px; align-items: end;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.route-edit > .btn { grid-column: 1 / -1; justify-self: start; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.preview { display: inline-flex; min-width: 100px; }
.org-name { font-weight: 700; }
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .route-edit { grid-template-columns: 1fr 1fr; }
  .route-edit > .field:first-child { grid-column: 1 / -1; }
}

/* --- Organizers & sources -------------------------------------------------------------------- */

.source-row { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 1px solid var(--border); }
.source-row:first-of-type { margin-top: 12px; }
.source-id { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.source-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* --- Settings ------------------------------------------------------------------------------------ */

.setting-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.status { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.status dt { color: var(--muted); }
.status dd { margin: 0; font-weight: 600; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* --- Analysis, rejected log, screenshots ------------------------------------------ */

.small { font-size: 13.5px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; margin: 8px 0 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.progress-line { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 600; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--text); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.job-line { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 10px; align-items: center; }
@media (max-width: 520px) { .job-line { grid-template-columns: 1fr; gap: 2px; } }
.badge-job-done { color: var(--ok); }
.badge-job-failed { color: var(--error); border-color: var(--error); }
.rejected-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.success-box ul, .error-box ul { margin: 6px 0 0; padding-left: 18px; }
.error-box p, .success-box p { margin: 6px 0 0; }
.warn { color: var(--warn); }

/* --- Scanning ---------------------------------------------------------------------- */

.scan-now { display: flex; flex-direction: column; gap: 4px; }
.scan-now .btn { justify-content: flex-start; }
.scan-now p { margin: 0; }
.banner { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.error-list { margin: 0; padding-left: 18px; color: var(--error); font-size: 14px; }
.error-text { color: var(--error); }

/* --- Login & account ------------------------------------------------------------------ */

.login { max-width: 420px; margin: 0 auto; padding: calc(48px + env(safe-area-inset-top)) 16px 32px; }
.login .brand { display: block; text-align: center; font-size: 28px; margin-bottom: 24px; }
.code { background: var(--surface-2); border-radius: var(--radius); padding: 12px; font-size: 13px;
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.code-inline { font-family: ui-monospace, Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }

/* --- Notifications & calendars ------------------------------------------------------- */

.stack.tight { gap: 6px; }
.toggle-row { min-height: 32px; }
.feed-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.feed-name { flex: 1 1 160px; font-weight: 600; }

/* --- Monitoring chart ---------------------------------------------------------------------
   One series: blue checked at 4.2:1 on the light surface and 4.5:1 on the dark one. */

:root { --chart-bar: #2a78d6; }
:root[data-theme="dark"] { --chart-bar: #3987e5; }
.chart { margin: 0; }
.chart-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.chart-wrap { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; font-size: 11.5px; color: var(--muted);
  font-variant-numeric: tabular-nums; text-align: right; padding: 4px 0 0; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-bar { fill: var(--chart-bar); }
.chart-bar.is-hover { opacity: 0.75; }
.chart-limit { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-limit-label { position: absolute; right: 0; transform: translateY(-120%); font-size: 11.5px; color: var(--muted);
  background: var(--surface); padding: 0 4px; }
.chart-tip { position: absolute; top: 0; transform: translate(-50%, -105%); background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 12.5px; white-space: nowrap;
  display: flex; flex-direction: column; gap: 2px; pointer-events: none; z-index: 2; }
.chart-x { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin: 4px 0 8px 24px; }
.table-scroll { overflow-x: auto; }

/* --- Photo import -------------------------------------------------------------------------- */

.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-btn { min-height: 56px; font-size: 16px; }
.thumb { position: relative; }
.thumb img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.thumb-remove {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 14px; border: 0;
  background: var(--primary); color: var(--primary-text); font-size: 18px; line-height: 28px; cursor: pointer;
}
.review-actions { margin: 12px 0 20px; }
@media (max-width: 520px) { .photo-buttons { grid-template-columns: 1fr; } }

/* --- Navigation without side panel (2026-10) ------------------------------------------------ */

.layout, .panel { display: none; }  /* old side panel: removed */
.icon-btn.btn-on { background: var(--surface-2); }

.add-menu { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 250px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px; display: flex; flex-direction: column;
}
.menu-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; text-decoration: none; font-size: 15px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }
.menu-icon { width: 20px; text-align: center; }

.count-pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary);
  color: var(--primary-text); font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }

/* Filter sheet: slides up from the bottom on every screen size */
.sheet-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.35); opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 80; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px; max-height: 88vh;
  display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform 0.22s ease; visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
.sheet:focus { outline: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { margin: 0 auto 0 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.sheet-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.sheet-foot .btn { width: 100%; }
body.sheet-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { transition: none; } }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.switch { appearance: none; -webkit-appearance: none; flex: none; width: 46px; height: 28px; border-radius: 14px;
  background: var(--border); position: relative; cursor: pointer; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); transition: transform 0.15s; }
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(18px); }
.option-list { max-height: 200px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 10px; background: var(--surface); }
.option { padding: 6px 0; }

/* Settings hub */
.hub { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.hub-link { display: flex; align-items: center; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); text-decoration: none; font-weight: 600; }
.hub-link:hover { border-color: var(--text); }
.hub-card { display: flex; flex-direction: column; gap: 4px; text-decoration: none; }
.hub-card:hover { border-color: var(--text); }
.org-title { font-size: 17px; margin: 0; }

/* --- Image viewer ---------------------------------------------------------------------------- */

.gallery-item { padding: 0; border: 0; background: none; cursor: zoom-in; display: block; }
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 10, 9, 0.98);
  display: flex; align-items: center; justify-content: center;
  padding: calc(56px + env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom));
}
.lightbox-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.lightbox-bar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; color: #f3efe4; font-size: 15px;
}
.lightbox-close, .lightbox-nav {
  border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.16); color: #fff; cursor: pointer;
  width: 44px; height: 44px; font-size: 22px; line-height: 44px;
}
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 30px; }
.lightbox-nav.prev { left: 10px; }
.lightbox-nav.next { right: 10px; }

/* --- Settings side panel & drag handles -------------------------------------------------------- */

.side-panel {
  position: fixed; z-index: 80; top: 0; bottom: 0; left: 0; width: min(92vw, 460px);
  background: var(--bg); border-right: 1px solid var(--border); overflow-y: auto; overscroll-behavior: contain;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-105%); transition: transform 0.22s ease; visibility: hidden;
}
.side-panel.open { transform: none; visibility: visible; }
.side-panel:focus { outline: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.side-panel .hub { grid-template-columns: 1fr 1fr; }
@media (prefers-reduced-motion: reduce) { .side-panel { transition: none; } }

/* The sheet's top bar is the grab area: drag it down to close (touch). */
.sheet-grab { touch-action: none; cursor: grab; }
.sheet-handle { width: 44px; height: 5px; margin: 10px auto 2px; }

/* Filter sheet: vertical movement only (iOS lets fixed panels drift sideways otherwise). */
.sheet, .sheet-body { overflow-x: hidden; max-width: min(100vw, 640px); }
.sheet-body { touch-action: pan-y; overscroll-behavior: contain; }
.sheet-backdrop { touch-action: none; }
.sheet .two-col > label, .sheet .input { min-width: 0; max-width: 100%; }
.sheet input[type="date"] { -webkit-appearance: none; appearance: none; width: 100%; }
.sheet .chip-row { min-width: 0; }
