/* 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) {
  .view-switch { display: none; }
}
@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); }
