/* ─── Design tokens ─── */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --border-subtle: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-subtle: #6e7681;
  --accent: #4a9e6b;
  --accent-hover: #3d8a5c;
  --link: #58a6ff;
  --danger: #c05a3e;
  --warn: #c8922a;
  --info: #5b7db8;

  --phase-1: #4a9e6b;
  --phase-2: #c8922a;
  --phase-3: #c05a3e;
  --phase-4: #5b7db8;

  --tag-upstate: #4a9e6b;
  --tag-city: #5b7db8;
  --tag-alt: #c05a3e;

  --status-done: #4a9e6b;
  --status-partial: #c8922a;
  --status-skipped: #c05a3e;
  --status-swapped: #5b7db8;

  --radius: 6px;
  --radius-sm: 3px;
  --font: "Inter", -apple-system, sans-serif;
  --mono: "JetBrains Mono", monospace;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --transition: 0.15s ease;
}

[data-theme="light"] {
  --bg: #f6f8fa;
  --bg2: #ffffff;
  --bg3: #eaeef2;
  --border: #d0d7de;
  --border-subtle: #e8ecf0;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-subtle: #9198a1;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* ─── Reset & base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 13px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}
button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--link); }
p { margin: 0; }
ul { padding-left: 1.2em; }
details > summary { cursor: pointer; }

/* ─── Utility ─── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.flex-1 { flex: 1; }

/* ─── App header ─── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  height: 44px;
  max-width: 1100px;
  margin: 0 auto;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 20px;
  flex-shrink: 0;
}
.logo-mark {
  width: 22px; height: 22px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}
.logo-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

/* Tab nav */
.tab-nav {
  display: flex;
  gap: 0;
  flex: 1;
  height: 100%;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 0 14px;
  height: 100%;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  border-radius: 8px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  margin-left: 12px;
  flex-shrink: 0;
  transition: color var(--transition), border-color var(--transition);
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }

/* ─── View container ─── */
.view-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 80px;
}
.view-content {
  padding-top: 20px;
}
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.view-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* ─── Week selector ─── */
.plan-view { padding-top: 20px; }
.week-selector-wrap {
  margin-bottom: 20px;
}
.week-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}
@media (max-width: 600px) { .week-grid { grid-template-columns: repeat(6, 1fr); } }
.week-btn {
  background: var(--bg2);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 6px 0;
  font-family: var(--mono);
  font-size: 11px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-align: center;
}
.week-btn:hover {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--border);
}
.week-btn.selected {
  border-color: var(--phase-color, var(--accent));
  color: var(--phase-color, var(--accent));
  background: var(--bg3);
}
.week-btn.current {
  font-weight: 600;
}

/* Phase legend */
.phase-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-subtle);
  letter-spacing: 0.08em;
}

/* ─── Week detail ─── */
.week-detail {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.week-detail-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.phase-tag {
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: 0.12em;
  font-weight: 500;
  margin-bottom: 4px;
}
.week-focus {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 480px;
}
.adjusted-tag {
  display: inline-block;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--warn);
  border: 1px solid var(--warn);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.week-stats {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.stat-chip {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: baseline;
  gap: 3px;
}
.stat-val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.stat-unit {
  font-size: 10px;
  color: var(--text-subtle);
  font-family: var(--mono);
}

/* Adherence bar */
.adherence-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.adherence-bar {
  flex: 1;
  height: 3px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.adherence-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.adherence-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-subtle);
  white-space: nowrap;
}

/* Week sub-tabs */
.week-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.week-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  padding: 8px 12px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
}
.week-tab:hover { color: var(--text); }
.week-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ─── Day cards ─── */
.day-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  overflow: hidden;
}
.day-card:hover {
  border-color: var(--text-muted);
  background: var(--bg3);
}
.day-card.day-flex { border-left: 3px solid var(--phase-2); }
.day-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.day-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  width: 32px;
  flex-shrink: 0;
}
.day-stim {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-subtle);
  letter-spacing: 0.06em;
  flex: 1;
}
.day-status {
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 500;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid;
}
.status-done    { color: var(--status-done);    border-color: var(--status-done); }
.status-partial { color: var(--status-partial); border-color: var(--status-partial); }
.status-skipped { color: var(--status-skipped); border-color: var(--status-skipped); }
.status-swapped { color: var(--status-swapped); border-color: var(--status-swapped); }
.status-none    { color: var(--text-subtle);    border-color: var(--border); }

/* Option grid inside day cards */
.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
}
@media (max-width: 640px) { .option-grid { grid-template-columns: 1fr; } }

.option-col {
  padding: 10px 14px;
  border-right: 1px solid var(--border-subtle);
}
.option-col:last-child { border-right: none; }

.option-unified {
  padding: 10px 14px;
}

.option-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
.tag-upstate { background: rgba(74,158,107,.12); color: var(--tag-upstate); }
.tag-city    { background: rgba(91,125,184,.12); color: var(--tag-city); }
.tag-alt     { background: rgba(192,90,62,.12);  color: var(--tag-alt); }
.tag-unified { background: var(--bg3); color: var(--text-muted); }

.option-am {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 5px;
}
.option-pm {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  padding-top: 5px;
  border-top: 1px dashed var(--border-subtle);
}
.option-loc {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-subtle);
  margin-top: 4px;
}
.day-note {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px solid var(--border-subtle);
}

/* Tab placeholder */
.tab-placeholder {
  padding: 32px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Modals ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-up 0.2s ease-out;
}
@media (min-width: 640px) {
  .modal-panel {
    border-radius: var(--radius);
    max-height: 85dvh;
  }
}
.modal-wide { max-width: 680px; }

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 14px; font-weight: 600; }
.modal-subtitle { font-size: 11px; color: var(--text-muted); font-family: var(--mono); margin-top: 2px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── Form elements ─── */
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--mono);
  letter-spacing: 0.06em;
}
.field-label-inline { display: flex; align-items: center; gap: 8px; }
.field-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.field-input:focus { border-color: var(--accent); }
.field-input::placeholder { color: var(--text-subtle); }
.field-textarea { resize: vertical; min-height: 72px; }
.field-textarea-lg { min-height: 140px; }
.field-small { max-width: 120px; }
.field-hint {
  font-size: 11px;
  color: var(--text-subtle);
}
.field-hint-inline {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-subtle);
}
.field-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.field-row .field-group { min-width: 140px; }

/* Pills */
.pill-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.pill-wrap { flex-wrap: wrap; }
.pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  transition: all var(--transition);
}
.pill:hover { border-color: var(--text-muted); color: var(--text); }
.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pill-sm { padding: 3px 9px; font-size: 11px; }

/* Toggle */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.toggle-label input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
}

/* GPX */
.gpx-row { display: flex; align-items: center; gap: 10px; }
.gpx-upload-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.gpx-upload-btn:hover { border-color: var(--text-muted); color: var(--text); }
.gpx-status { font-size: 11px; color: var(--text-subtle); }
.gpx-parsed {
  display: flex;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  margin-top: 6px;
  flex-wrap: wrap;
}
.manual-data { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.manual-data .field-input { max-width: 110px; }

/* ─── Buttons ─── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: all var(--transition);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--text-muted); }

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: color var(--transition), background var(--transition);
}
.btn-ghost:hover { color: var(--text); background: var(--bg3); }
.btn-danger { color: var(--danger) !important; }
.btn-danger:hover { background: rgba(192,90,62,.1) !important; }

/* ─── Proposals view ─── */
.proposal-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.proposal-history { opacity: 0.7; }
.proposal-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.proposal-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.trigger-badge {
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.proposal-date {
  font-size: 11px;
  color: var(--text-subtle);
  font-family: var(--mono);
}
.status-badge {
  font-size: 10px;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid;
}
.status-approved       { color: var(--status-done);    border-color: var(--status-done); }
.status-rejected       { color: var(--status-skipped); border-color: var(--status-skipped); }
.status-partially_approved { color: var(--status-partial); border-color: var(--status-partial); }
.status-pending        { color: var(--warn);  border-color: var(--warn); }
.trigger-summary { font-size: 12px; color: var(--text-muted); }

.med-context {
  padding: 8px 14px;
  background: rgba(91,125,184,.06);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  border-bottom: 1px solid var(--border-subtle);
}
.med-context-label { color: var(--text-subtle); font-family: var(--mono); }
.med-note-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--info);
}

.rationale {
  padding: 14px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  border-bottom: 1px solid var(--border-subtle);
}
.rationale h2, .rationale h3, .rationale h4 { font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.rationale ul { margin: 4px 0 4px 16px; }
.rationale li { margin: 2px 0; }
.rationale p { margin: 4px 0; }
.rationale strong { font-weight: 600; }

.changes-list { padding: 8px 14px; }
.change-item {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
  font-size: 12px;
}
.change-approved { border-color: var(--status-done); }
.change-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg3);
}
.change-where { font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--text); }
.change-field { font-family: var(--mono); font-size: 10px; color: var(--text-subtle); }
.change-diff { display: grid; grid-template-columns: 1fr 1fr; }
.change-before {
  padding: 6px 10px;
  background: rgba(192,90,62,.05);
  color: var(--text-muted);
  text-decoration: line-through;
  font-size: 11px;
  border-right: 1px solid var(--border-subtle);
  word-break: break-word;
}
.change-after {
  padding: 6px 10px;
  background: rgba(74,158,107,.05);
  color: var(--accent);
  font-size: 11px;
  word-break: break-word;
}
.change-reason {
  padding: 5px 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px solid var(--border-subtle);
}
.change-check { accent-color: var(--accent); margin-right: 4px; }

.proposal-actions {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.proposal-resolution {
  padding: 10px 14px;
  font-size: 11px;
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
}

/* ─── Medical view ─── */
.med-section { margin-bottom: 20px; }
.section-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-subtle);
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.empty-hint { font-size: 12px; color: var(--text-subtle); padding: 8px 0; }
.note-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.note-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
  flex-wrap: wrap;
}
.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.type-badge {
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid;
}
.note-date { font-size: 11px; color: var(--text-subtle); font-family: var(--mono); }
.expired-tag {
  font-size: 10px;
  color: var(--text-subtle);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
}
.note-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.note-title { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.note-preview { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-bottom: 6px; }
.note-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 4px; }
.note-tag {
  font-size: 10px;
  font-family: var(--mono);
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.note-expiry { font-size: 11px; color: var(--text-subtle); }

/* ─── Settings view ─── */
.settings-form { max-width: 520px; }
.settings-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.settings-section-title {
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.settings-actions { margin-top: 4px; }

.sensitivity-options {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
@media (max-width: 480px) { .sensitivity-options { grid-template-columns: 1fr; } }
.sensitivity-option {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: all var(--transition);
  display: block;
}
.sensitivity-option:hover { border-color: var(--text-muted); }
.sensitivity-option.active {
  border-color: var(--accent);
  background: rgba(74,158,107,.08);
}
.sens-label { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.sens-desc  { font-size: 11px; color: var(--text-muted); }

/* ─── History / collapsible ─── */
.history-section { margin-top: 16px; }
.history-toggle {
  font-size: 12px;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  user-select: none;
}
.history-toggle::marker,
.history-toggle::-webkit-details-marker { display: none; }
.history-toggle::before {
  content: "▶";
  font-size: 9px;
  transition: transform 0.15s;
}
details[open] .history-toggle::before { transform: rotate(90deg); }
.history-list { margin-top: 8px; }

/* ─── Empty state ─── */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-state p { margin-bottom: 6px; }
.empty-state .empty-hint { font-size: 12px; color: var(--text-subtle); }

/* ─── Toasts ─── */
#toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 12px;
  color: var(--text);
  max-width: 300px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { border-left: 3px solid var(--status-done); }
.toast-error   { border-left: 3px solid var(--status-skipped); }
.toast-warning { border-left: 3px solid var(--warn); }
.toast-info    { border-left: 3px solid var(--info); }

/* ─── Plan setup / generate ─── */
.setup-shell {
  padding: 40px 16px 80px;
  display: flex;
  justify-content: center;
}

.setup-card {
  width: 100%;
  max-width: 580px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.setup-header { margin-bottom: 24px; }
.setup-title  { font-size: 16px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.setup-subtitle { font-size: 12px; color: var(--text-muted); margin: 0; }

.setup-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.setup-tab {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.setup-tab:hover { color: var(--text); }
.setup-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.setup-form { display: flex; flex-direction: column; gap: 16px; }
.setup-row  { display: flex; flex-direction: column; gap: 16px; }
.setup-row-2 { flex-direction: row; gap: 12px; }
.setup-row-2 .setup-field { flex: 1; min-width: 0; }

.setup-field { display: flex; flex-direction: column; gap: 6px; }

.setup-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.setup-label-hint {
  text-transform: none;
  font-weight: 400;
  opacity: 0.7;
  letter-spacing: 0;
}

.setup-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}

.setup-input:focus { border-color: var(--accent); }
.setup-input::placeholder { color: var(--text-faint); }
.setup-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.setup-error {
  font-size: 12px;
  color: var(--status-skipped);
  background: color-mix(in srgb, var(--status-skipped) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--status-skipped) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.setup-generate-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.setup-hint { font-size: 11px; color: var(--text-faint); margin: 0; }

.setup-spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 4px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

.setup-upload-area { padding: 8px 0; }

.upload-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s;
}

.upload-drop-zone.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.upload-label { font-size: 13px; color: var(--text); margin: 0; }
.upload-hint  { font-size: 12px; color: var(--text-faint); margin: 0; }

/* ─── Admin view ─── */
.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  gap: 0;
}

.admin-tab {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s, border-color 0.15s;
}

.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-tab-count {
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 6px;
  color: var(--text-muted);
}

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.admin-table th {
  padding: 9px 14px;
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg2); }

.admin-cell-email { font-family: var(--font-mono); font-size: 12px; }
.admin-cell-date  { color: var(--text-muted); white-space: nowrap; }
.admin-cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

.admin-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.admin-badge-ok   { background: color-mix(in srgb, var(--status-done) 15%, transparent); color: var(--status-done); }
.admin-badge-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

.admin-btn-secondary {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s;
}

.admin-btn-secondary:hover { color: var(--text); border-color: var(--text-muted); }

.admin-btn-danger {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  border-radius: var(--radius-sm);
  color: var(--danger);
  transition: background 0.15s;
}

.admin-btn-danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

.admin-btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: none;
  border: none;
  color: var(--text-faint);
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.admin-btn-icon:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

.admin-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.admin-section-header { margin-bottom: 16px; }
.admin-section-title { font-size: 13px; font-weight: 600; color: var(--text); margin: 0 0 4px; }
.admin-section-desc  { font-size: 12px; color: var(--text-muted); margin: 0; }

.admin-mode-toggle { display: flex; flex-direction: column; gap: 8px; }

.admin-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.admin-mode-option:hover { border-color: var(--text-muted); }
.admin-mode-option.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.admin-mode-option input[type="radio"] { margin-top: 2px; flex-shrink: 0; accent-color: var(--accent); }
.admin-mode-label { font-size: 12px; font-weight: 500; color: var(--text); }
.admin-mode-desc  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.admin-add-email-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.admin-input:focus { border-color: var(--accent); }

.admin-allowlist { display: flex; flex-direction: column; gap: 4px; }

.admin-allowlist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text);
}

.admin-empty-list { font-size: 12px; color: var(--text-faint); margin: 0; }

/* ─── Auth extra states ─── */
.auth-verify-sent {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 8px 0;
}

.auth-verify-icon { color: var(--accent); }
.auth-verify-title { font-size: 15px; font-weight: 600; color: var(--text); margin: 0; }
.auth-verify-body  { font-size: 13px; color: var(--text-muted); margin: 0; line-height: 1.5; }

.auth-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: underline;
  padding: 4px 0;
  cursor: pointer;
  transition: color 0.15s;
}

.auth-link:hover { color: var(--text); }

.auth-hint-text {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 4px;
  line-height: 1.5;
}

/* ─── Auth page ─── */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}

.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-faint); }

.auth-error {
  font-size: 12px;
  color: var(--status-skipped);
  background: color-mix(in srgb, var(--status-skipped) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--status-skipped) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.auth-submit {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 0;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.auth-submit:hover { opacity: 0.88; }
.auth-submit:disabled,
.auth-submit.loading { opacity: 0.55; cursor: not-allowed; }

/* Logout button in header */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.header-logout:hover {
  color: var(--text);
  background: var(--bg3);
}

/* ─── Mobile tweaks ─── */
@media (max-width: 480px) {
  .header-inner { padding: 0 12px; }
  .view-container { padding: 0 12px 80px; }
  .tab-btn { padding: 0 10px; font-size: 11px; }
  .logo-text { display: none; }
  .week-detail-header { flex-direction: column; }
  .week-stats { gap: 6px; }
  .stat-chip { padding: 4px 8px; }
  .change-diff { grid-template-columns: 1fr; }
  .change-before { border-right: none; border-bottom: 1px solid var(--border-subtle); }
  .modal-panel { border-radius: var(--radius) var(--radius) 0 0; }
  #toast-root { right: 12px; bottom: 12px; left: 12px; }
  .toast { max-width: none; }
  .setup-card { padding: 24px 16px; }
  .setup-row-2 { flex-direction: column; }
  .setup-generate-footer { flex-direction: column; align-items: flex-start; }
}
