:root {
  --c-bg: #f1f5f9;
  --c-surface: #ffffff;
  --c-border: #cbd5e1;
  --c-text: #0f172a;
  --c-muted: #64748b;
  --c-primary: #1e40af;
  --c-primary-hover: #1d4ed8;
  --c-empty: #ffffff;
  --c-empty-border: #94a3b8;
  --c-occupied: #1e40af;
  --c-disabled: #cbd5e1;
  --c-reserved: #facc15;
  --c-danger: #dc2626;
  --c-success: #16a34a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; font-size: 14px; }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.app-home {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background-color 0.15s;
}
.app-home:hover { background: var(--c-bg); }
.app-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex-shrink: 0;
}
.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--c-primary);
  letter-spacing: -0.5px;
  margin: 0;
}
.app-header h1 .muted { color: var(--c-muted); font-weight: 500; }

.day-tabs { display: flex; gap: 4px; }
.day-tab {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--c-muted);
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.day-tab:hover { background: var(--c-bg); }
.day-tab.active {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}

.session-tabs {
  display: flex;
  gap: 3px;
  padding: 2px;
  background: var(--c-bg);
  border-radius: var(--radius);
}
.session-tab {
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--c-muted);
  background: transparent;
  border: none;
  transition: all 0.15s;
}
.session-tab:hover { color: var(--c-text); }
.session-tab.active {
  background: #f59e0b;
  color: white;
  box-shadow: 0 1px 2px rgba(245, 158, 11, 0.3);
}
.session-tab[data-session="afternoon"].active {
  background: #6366f1;
  box-shadow: 0 1px 2px rgba(99, 102, 241, 0.3);
}

.header-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius);
  background: var(--c-bg);
  min-width: 60px;
}
.stat-label { font-size: 10px; color: var(--c-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 16px; font-weight: 600; }
.stat-sub {
  font-size: 10px;
  color: #d97706;
  font-weight: 600;
  line-height: 1;
  margin-top: 1px;
}
.stat-sub[hidden] { display: none; }
.stat.occupied .stat-value { color: var(--c-occupied); }
.stat.empty .stat-value { color: var(--c-success); }
.stat.percent .stat-value { color: var(--c-primary); }

.header-right { display: flex; align-items: center; gap: 8px; }
.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--c-bg);
  font-size: 12px;
  font-weight: 500;
  transition: background-color 0.3s;
  white-space: nowrap;
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-muted);
  flex-shrink: 0;
}
.sync-text { color: var(--c-text); }
.sync-status.idle .sync-dot { background: var(--c-muted); }
.sync-status.idle .sync-text { color: var(--c-muted); }
.sync-status.syncing { background: #fef3c7; }
.sync-status.syncing .sync-dot { background: var(--c-reserved); animation: pulse 1s infinite; }
.sync-status.syncing .sync-text { color: #92400e; }
.sync-status.ok { background: #dcfce7; }
.sync-status.ok .sync-dot { background: var(--c-success); }
.sync-status.ok .sync-text { color: #166534; }
.sync-status.error { background: #fee2e2; }
.sync-status.error .sync-dot { background: var(--c-danger); }
.sync-status.error .sync-text { color: #991b1b; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  font-size: 18px;
  background: var(--c-bg);
  color: var(--c-muted);
}
.icon-btn:hover { background: var(--c-border); color: var(--c-text); }

/* ===== Views ===== */
.view {
  padding: 16px;
  max-width: 100%;
}

/* ===== Setup ===== */
.setup-card {
  max-width: 480px;
  margin: 60px auto;
  padding: 32px;
  background: var(--c-surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.setup-card h2 { margin-bottom: 8px; }
.setup-card p { color: var(--c-muted); margin: 8px 0; }
.setup-card code {
  font-size: 12px;
  padding: 2px 6px;
  background: var(--c-bg);
  border-radius: 4px;
}
.setup-card input {
  width: 100%;
  padding: 12px;
  margin: 16px 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 14px;
}

/* ===== Buttons ===== */
.btn-primary, .btn-secondary, .btn-danger {
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn-primary { background: var(--c-primary); color: white; }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-secondary { background: var(--c-bg); color: var(--c-text); border: 1px solid var(--c-border); }
.btn-secondary:hover { background: var(--c-border); }
.btn-danger { background: var(--c-danger); color: white; }
.btn-danger:hover { background: #b91c1c; }

/* ===== Extras card ===== */
.extras-card {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.extras-info { flex: 1; min-width: 200px; }
.extras-label {
  font-size: 14px;
  font-weight: 600;
  color: #78350f;
  margin-bottom: 4px;
}
.extras-hint { font-weight: 400; color: #92400e; font-size: 12px; }
.extras-summary { font-size: 13px; color: #78350f; }
.extras-summary strong { font-size: 16px; }
.extras-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.extras-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: white;
  color: #92400e;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid #fcd34d;
  transition: all 0.15s;
}
.extras-btn:hover { background: #fcd34d; }
.extras-btn:active { transform: scale(0.94); }
#extras-input {
  width: 70px;
  height: 36px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: white;
  color: #78350f;
  -moz-appearance: textfield;
}
#extras-input::-webkit-outer-spin-button,
#extras-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ===== Overview ===== */
.overview-canvas {
  background: var(--c-surface);
  border-radius: 12px;
  padding: 24px 16px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.overview-layout {
  display: flex;
  align-items: stretch;
  gap: 16px;
}
.overview-zones {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.overview-row {
  display: flex;
  gap: 6px;
  justify-content: flex-start;
}
.stage {
  flex-shrink: 0;
  width: clamp(28px, 5vw, 80px);
  background: linear-gradient(180deg, var(--c-primary), var(--c-primary-hover));
  color: white;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.6vw, 8px);
  align-self: stretch;
  box-shadow: var(--shadow-sm);
  padding: clamp(6px, 1.5vw, 16px) 0;
}
.stage-char {
  font-size: clamp(11px, 2vw, 32px);
  font-weight: 700;
  line-height: 1;
  text-align: center;
}
.zone-overview {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  background: var(--c-bg);
  border: 1px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
  min-width: 0;
}
.zone-overview:hover { border-color: var(--c-primary); transform: scale(1.05); z-index: 2; }
.zone-overview .zone-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: 2px;
  line-height: 1;
}
.zone-overview .zone-info {
  font-size: 9px;
  color: var(--c-muted);
  margin-top: 2px;
  display: flex;
  gap: 4px;
  line-height: 1;
}
.zone-overview .zone-info strong { color: var(--c-text); font-weight: 600; }
.zone-overview-grid {
  --overview-seat: clamp(1.8px, 0.4vw, 5px);
  display: grid;
  gap: 0;
  background: var(--c-bg);
  grid-template-columns: repeat(var(--cols), var(--overview-seat));
  grid-template-rows: repeat(var(--rows), var(--overview-seat));
}
.zone-overview-grid .seat {
  width: var(--overview-seat);
  height: var(--overview-seat);
  background: var(--c-empty);
  border: 0.5px solid var(--c-empty-border);
}
.zone-overview-grid .seat.occupied { background: var(--c-occupied); border-color: var(--c-occupied); }
.zone-overview-grid .seat.disabled { background: var(--c-disabled); border-color: var(--c-disabled); }
.zone-overview-grid .seat.reserved { background: var(--c-reserved); border-color: var(--c-reserved); }
.zone-overview-grid .seat.removed { background: transparent; border: none; }

.fill-bar {
  width: 100%;
  height: 3px;
  background: var(--c-border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.fill-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--c-success), var(--c-reserved), var(--c-danger));
  transition: width 0.3s;
}

.overview-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--c-muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.seat-sample { width: 14px; height: 14px; border: 1px solid var(--c-empty-border); border-radius: 2px; }
.seat-sample.empty { background: var(--c-empty); }
.seat-sample.occupied { background: var(--c-occupied); border-color: var(--c-occupied); }
.seat-sample.disabled { background: var(--c-disabled); border-color: var(--c-disabled); }
.seat-sample.reserved { background: var(--c-reserved); border-color: var(--c-reserved); }

/* ===== Zone detail ===== */
.zone-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.btn-back {
  font-size: 14px;
  font-weight: 500;
  color: var(--c-primary);
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
}
.btn-back:hover { background: var(--c-border); }
.zone-title { font-size: 18px; }
.zone-title #zone-name { color: var(--c-primary); font-weight: 700; }
.zone-stats { display: flex; gap: 10px; font-size: 14px; margin-left: auto; }
.zone-percent { font-weight: 600; color: var(--c-primary); }
.zone-actions { display: flex; gap: 6px; }
.btn-mode, .btn-undo, .btn-reset-zone, .btn-fill-zone {
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--c-bg);
  font-size: 13px;
  border: 1px solid var(--c-border);
}
.btn-mode { font-weight: 500; }
.btn-mode[data-mode="edit"] { background: var(--c-primary); color: white; border-color: var(--c-primary); }
.btn-undo:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-fill-zone { color: var(--c-primary); font-weight: 500; }
.btn-fill-zone:hover { background: var(--c-primary); color: white; border-color: var(--c-primary); }
.btn-reset-zone { color: var(--c-danger); }
.btn-reset-zone:hover { background: var(--c-danger); color: white; border-color: var(--c-danger); }

.zone-canvas-wrap {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  overflow: auto;
  max-height: calc(100vh - 180px);
  display: flex;
  justify-content: safe center;
  align-items: flex-start;
}
.zone-grid {
  display: inline-grid;
  gap: 2px;
  user-select: none;
  --seat-size: clamp(20px, 5vw, 36px);
}
.zone-grid.edit-mode { touch-action: none; }
.zone-grid .corner-cell { background: transparent; }
.zone-grid .col-header,
.zone-grid .row-header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-muted);
  background: var(--c-bg);
  border-radius: 3px;
  position: sticky;
  z-index: 5;
}
.zone-grid .col-header { top: 0; height: 22px; min-width: var(--seat-size); }
.zone-grid .row-header { left: 0; width: 28px; height: var(--seat-size); }
.zone-grid .seat {
  width: var(--seat-size);
  height: var(--seat-size);
  background: var(--c-empty);
  border: 1px solid var(--c-empty-border);
  border-radius: 3px;
  transition: background-color 0.1s, transform 0.1s;
  padding: 0;
  position: relative;
}
.zone-grid .seat.occupied { background: var(--c-occupied); border-color: var(--c-occupied); }
.zone-grid .seat.disabled { background: var(--c-disabled); border-color: var(--c-disabled); }
.zone-grid .seat.disabled::after {
  content: '×';
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--c-muted);
  font-size: 14px;
}
.zone-grid .seat.reserved { background: var(--c-reserved); border-color: var(--c-reserved); }
.zone-grid .seat.removed { background: transparent; border: none; pointer-events: none; }
.zone-grid .seat.in-special { box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.3); }
.zone-grid .seat:active { transform: scale(0.92); }

/* ===== Admin ===== */
.admin-panel {
  max-width: 720px;
  margin: 0 auto;
  background: var(--c-surface);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.admin-section {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--c-border);
}
.admin-section:last-child { border-bottom: none; }
.admin-section h3 { font-size: 15px; margin-bottom: 8px; }
.admin-section .hint { color: var(--c-muted); font-size: 12px; margin-bottom: 12px; }
.admin-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.admin-row input[type="url"], .admin-row input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}
.admin-section.danger h3 { color: var(--c-danger); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { padding: 8px; text-align: center; border-bottom: 1px solid var(--c-border); }
.admin-table th { background: var(--c-bg); font-weight: 600; }
.admin-table input[type="number"] {
  width: 70px;
  padding: 4px 6px;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  text-align: center;
}
.btn-delete-zone {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}
.btn-delete-zone:hover { background: #fca5a5; }
.checkbox { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  background: var(--c-text);
  color: white;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slide-up 0.2s ease-out;
  pointer-events: auto;
}
.toast.success { background: var(--c-success); }
.toast.error { background: var(--c-danger); }
.toast.warn { background: #d97706; }
@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== Modal ===== */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-card {
  background: var(--c-surface);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.modal-card h3 { margin-bottom: 12px; }
.modal-card p { color: var(--c-muted); margin-bottom: 16px; }
.modal-card input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== Overseer button & view ===== */
.overseer-btn { position: relative; }
.overseer-btn.active {
  background: #fef3c7;
  color: #92400e;
  box-shadow: 0 0 0 2px #f59e0b;
}
.overseer-btn.active::after {
  content: '';
  position: absolute;
  top: 2px; right: 2px;
  width: 8px; height: 8px;
  background: #f59e0b;
  border-radius: 50%;
}

.overseer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.overseer-header h2 { font-size: 18px; }
.overseer-header .btn-secondary { margin-left: auto; }
.overseer-panel {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.overseer-panel .hint {
  color: var(--c-muted);
  font-size: 13px;
  margin-bottom: 16px;
  padding: 12px;
  background: #fef3c7;
  border-radius: var(--radius);
  border-left: 4px solid #f59e0b;
}
.locks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.lock-day {
  background: var(--c-bg);
  border-radius: var(--radius);
  padding: 16px;
}
.lock-day h3 {
  font-size: 15px;
  color: var(--c-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
}
.lock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.lock-row > span { font-size: 14px; }
.lock-toggle {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid;
  transition: all 0.15s;
}
.lock-row.unlocked .lock-toggle {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}
.lock-row.unlocked .lock-toggle:hover { background: #86efac; }
.lock-row.locked .lock-toggle {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}
.lock-row.locked .lock-toggle:hover { background: #fca5a5; }

/* Lock indicators on tabs */
.session-tab.locked::before { content: '🔒 '; }
.day-tab.has-lock::after {
  content: '🔒';
  font-size: 9px;
  margin-left: 4px;
  vertical-align: middle;
}

/* Lock banner in zone view */
.lock-banner {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  border-left: 4px solid #ef4444;
  font-size: 14px;
  font-weight: 500;
  align-items: center;
  gap: 8px;
}
.lock-banner[hidden] { display: none; }
.lock-banner:not([hidden]) { display: flex; }
.lock-banner.overseer-override {
  background: #fef3c7;
  color: #92400e;
  border-left-color: #f59e0b;
}

/* Password modal */
#password-modal .modal-card { max-width: 360px; }
#pwd-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 16px;
  letter-spacing: 4px;
  text-align: center;
}

/* ===== History view ===== */
.history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.history-header h2 { font-size: 18px; }
.history-actions { display: flex; gap: 8px; margin-left: auto; }
.history-list {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.history-day-group { margin-bottom: 24px; }
.history-day-group:last-child { margin-bottom: 0; }
.history-day-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--c-primary);
  padding: 8px 0;
  border-bottom: 2px solid var(--c-bg);
  margin-bottom: 8px;
}
.history-empty {
  color: var(--c-muted);
  font-size: 13px;
  font-style: italic;
  padding: 8px 0;
}
.history-item {
  display: grid;
  grid-template-columns: 70px 95px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-bg);
}
.history-item:last-child { border-bottom: none; }
.history-time { font-family: ui-monospace, monospace; font-size: 13px; color: var(--c-muted); }
.history-session {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 12px;
  text-align: center;
}
.history-session.morning { background: #fef3c7; color: #92400e; }
.history-session.afternoon { background: #dbeafe; color: #1e40af; }
.history-stats { display: flex; flex-direction: column; gap: 2px; }
.history-count { font-size: 14px; font-weight: 600; }
.history-count .muted { color: var(--c-muted); font-weight: 400; }
.history-note { font-size: 12px; color: var(--c-muted); }
.history-actions-row { display: flex; gap: 4px; }
.history-actions-row button {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
}
.history-actions-row button:hover { background: var(--c-border); }
.history-actions-row .delete-btn { color: var(--c-danger); }
.history-actions-row .delete-btn:hover { background: var(--c-danger); color: white; border-color: var(--c-danger); }

/* ===== Snapshot modal ===== */
#snapshot-modal .modal-card { max-width: 420px; }
.snap-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.snap-label { color: var(--c-muted); font-size: 13px; min-width: 40px; }
.snap-sessions { display: flex; gap: 8px; flex-wrap: wrap; }
.session-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
  user-select: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.session-pill:hover { background: var(--c-border); }
.session-pill:has(input:checked) {
  background: #dbeafe;
  border-color: var(--c-primary);
  color: var(--c-primary);
}
.session-pill input[type="radio"] {
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--c-primary);
  width: 14px;
  height: 14px;
}
.session-pill span {
  white-space: nowrap;
  flex-shrink: 0;
}
.snap-count-box {
  background: var(--c-bg);
  border-radius: var(--radius);
  padding: 12px;
  margin: 12px 0;
}
.snap-count-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}
.snap-count-row strong { font-size: 16px; color: var(--c-primary); }
.snap-count-row.total {
  border-top: 1px dashed var(--c-border);
  border-bottom: 1px dashed var(--c-border);
  margin: 4px 0;
  padding: 6px 0;
}
.snap-count-row.total strong { font-size: 18px; color: #d97706; }
#snap-note {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* ===== Tablet (iPad portrait ~768-1024px) ===== */
@media (max-width: 1024px) {
  .app-header { padding: 8px 12px; gap: 10px; }
  .app-header h1 { font-size: 17px; }
  .header-stats { gap: 4px; }
  .stat { padding: 3px 10px; min-width: 52px; }
  .stat-value { font-size: 15px; }
  .day-tab { padding: 5px 10px; font-size: 12px; }
  .view { padding: 10px; }
  .overview-canvas { padding: 14px 8px; }
  .overview-row { gap: 4px; }
  .zone-overview { padding: 3px; }
  .zone-overview .zone-label { font-size: 11px; }
  .zone-toolbar { padding: 6px 10px; gap: 8px; }
  .zone-title { font-size: 16px; }
}

/* ===== Phone (iPhone portrait <= 640px) ===== */
@media (max-width: 640px) {
  .app-header {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .header-left { gap: 8px; flex: 1 1 auto; min-width: 0; }
  .app-home { gap: 6px; padding: 2px; }
  .app-logo { width: 30px; height: 30px; }
  .app-header h1 { font-size: 14px; letter-spacing: -0.3px; }
  .app-header h1 .muted { display: none; }
  .day-tabs { gap: 2px; }
  .day-tab { padding: 4px 8px; font-size: 11px; }
  .header-stats {
    width: 100%;
    order: 3;
    justify-content: space-between;
    gap: 2px;
  }
  .stat { padding: 2px 6px; min-width: 0; flex: 1; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 13px; }
  .header-right { gap: 4px; }
  .sync-status { padding: 4px 8px; font-size: 11px; }
  .icon-btn { width: 32px; height: 32px; font-size: 16px; }

  .view { padding: 6px; }
  .overview-canvas { padding: 10px 4px; border-radius: 8px; }
  .overview-layout { gap: 6px; }
  .overview-zones { gap: 3px; }
  .overview-row { gap: 3px; }
  .zone-overview { padding: 2px; min-width: 0; }
  .zone-overview .zone-label { font-size: 9px; line-height: 1; margin-bottom: 1px; }
  .zone-overview .zone-info { font-size: 8px; gap: 3px; margin-top: 1px; }

  .zone-toolbar { padding: 6px; gap: 6px; border-radius: 8px; }
  .zone-title { font-size: 14px; }
  .zone-stats { gap: 6px; font-size: 13px; }
  .zone-actions { gap: 4px; flex-wrap: wrap; }
  .btn-mode, .btn-undo, .btn-reset-zone, .btn-fill-zone {
    padding: 5px 10px;
    font-size: 12px;
  }
  .btn-back { padding: 6px 10px; font-size: 13px; }

  .zone-canvas-wrap {
    padding: 8px;
    border-radius: 8px;
    max-height: calc(100vh - 220px);
  }

  .toast { font-size: 12px; padding: 8px 14px; }
}

/* ===== Very small phone (<400px) ===== */
@media (max-width: 400px) {
  .app-header h1 { display: none; }
  .stat-label { display: none; }
  .sync-text { display: none; }
  .sync-status { padding: 6px; }
}
