:root {
  --primary: #2d6cdf;
  --danger: #e04c3c;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1b2734;
  --muted: #6b7684;
  --border: #e3e8ee;
}

body.theme-dark {
  --primary: #5f9dff;
  --danger: #ff6b5b;
  --bg: #10161f;
  --card-bg: #1a2230;
  --text: #e8ecf1;
  --muted: #8b97a6;
  --border: #2a3542;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.loading-spinner {
  width: 36px; height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-card p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}
input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="number"], input:not([type]), select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  background: var(--card-bg);
  color: var(--text);
}
textarea { resize: vertical; font-family: inherit; }
input[type="color"] {
  width: 56px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
}

/* ---------- Color preset swatches, alongside the native color input ---------- */
.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.color-preset-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 -3px 5px rgba(0,0,0,0.12);
}
.color-preset-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 4px var(--text);
}

.checkbox-row {
  display: flex;
  align-items: center;
  font-weight: 500;
  color: var(--text);
}
.checkbox-row input { width: auto; margin-right: 8px; }

button { font-family: inherit; cursor: pointer; }
.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 16px;
}
.full-width { width: 100%; }
.danger-btn {
  background: #fdecea;
  color: var(--danger);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 10px;
}
.text-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  padding: 8px;
}
.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--muted);
  padding: 4px 8px;
}

.error { color: var(--danger); font-size: 14px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* ---------- App shell ---------- */
#app-screen { display: flex; flex-direction: column; min-height: 100vh; padding: 0; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 18px; margin: 0; }

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 90px;
}
.tab-panel { display: none; }
.tab-panel.active {
  display: block;
  animation: tabIn 0.2s ease both;
}
@keyframes tabIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header { margin: 18px 0 8px; }
.section-header:first-child { margin-top: 4px; }
.section-header h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin: 0;
}

/* Groups a settings section's fields into one visually distinct card,
   rather than the whole tab reading as one long unbroken form. */
#tab-settings .settings-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 16px 16px;
  margin-bottom: 4px;
}
#tab-settings .section-header { padding-top: 14px; }
#tab-settings .section-header:first-child { padding-top: 0; }

.tab-bar {
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 4px 10px;
  font-size: 12px;
  color: var(--muted);
}
.tab-btn.active { color: var(--primary); font-weight: 700; }

.fab {
  position: fixed;
  right: 18px;
  bottom: 76px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(45,108,223,0.4);
  z-index: 25;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
}
.fab:active {
  transform: scale(0.88);
  box-shadow: 0 2px 8px rgba(45,108,223,0.5);
}

/* ---------- Theme toggle ---------- */
.theme-toggle-btn {
  background: none;
  border: none;
  font-size: 20px;
  padding: 4px 8px;
  color: var(--muted);
  margin-right: 4px;
}

/* ---------- Toast notifications ---------- */
#toast-stack {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--card-bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translateY(10px);
  animation: toastIn 0.25s ease forwards, toastOut 0.25s ease forwards 2.3s;
}
.toast.toast-error { background: var(--danger); color: #fff; }
@keyframes toastIn { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- Skeleton loading placeholders ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.4s ease-in-out infinite;
  border-radius: 10px;
}
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-card { height: 64px; margin-bottom: 8px; }
.skeleton-chip { width: 46px; height: 46px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- Pull-to-refresh ---------- */
#pull-refresh-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  transition: height 0.15s ease;
}
#pull-refresh-indicator .loading-spinner {
  width: 18px; height: 18px; border-width: 3px; margin-right: 8px;
}

/* ---------- Lists ---------- */
.item-list { list-style: none; margin: 0 0 8px; padding: 0; }
.item-list li {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.item-list li.empty {
  color: var(--muted);
  font-style: italic;
  background: transparent;
  border: none;
  padding: 6px 2px;
  display: block;
}
.item-list .swipe-content {
  background: var(--card-bg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  position: relative;
  z-index: 1;
}
.swipe-delete-bg {
  position: absolute;
  inset: 0;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 22px;
  font-weight: 700;
  font-size: 13px;
}
.item-color-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 10px;
  flex: none;
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; }
.item-sub { font-size: 13px; color: var(--muted); }
.item-actions { display: flex; gap: 6px; flex: none; }
.item-actions button {
  background: var(--bg);
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
}

.inline-form { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.inline-form input[type="text"], .inline-form input:not([type]) { flex: 1; }
.row-2 { display: flex; gap: 10px; }
.row-2 > div { flex: 1; }

/* ---------- Family avatar strip (tap a person to filter) ---------- */
.member-strip {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 2px 2px 14px;
  -webkit-overflow-scrolling: touch;
}
.member-chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  opacity: 0.5;
}
.member-chip.selected { opacity: 1; }
.member-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12), inset 0 -4px 8px rgba(0,0,0,0.12), inset 0 2px 4px rgba(255,255,255,0.25);
}
.member-chip .member-name { font-size: 11px; color: var(--text); font-weight: 600; max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-chip .member-count { font-size: 10px; color: var(--muted); }

/* ---------- Day strip (pick a day to see its events) ---------- */
.day-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 16px;
  -webkit-overflow-scrolling: touch;
}
.day-strip-btn {
  flex: 0 0 auto;
  width: 46px;
  text-align: center;
  border-radius: 14px;
  padding: 8px 2px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
}
.day-strip-btn.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-strip-btn.is-today:not(.selected) { border-color: var(--primary); }
.day-strip-btn .dow { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.day-strip-btn.selected .dow { color: rgba(255,255,255,0.85); }
.day-strip-btn .dnum { display: block; font-size: 16px; font-weight: 700; margin-top: 2px; }

/* ---------- Colorful event cards ---------- */
.event-card-list { list-style: none; margin: 0 0 8px; padding: 0; }
.event-card-list li.empty { color: var(--muted); font-style: italic; padding: 6px 2px; }
.event-card-list li:not(.empty) {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  margin-bottom: 10px;
}
.event-card {
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  border: none;
  position: relative;
  z-index: 1;
}
.event-card .ec-main { flex: 1; min-width: 0; }
.event-card .ec-title { font-weight: 700; font-size: 15px; color: var(--text); }
.event-card .ec-time { font-size: 13px; color: var(--muted); margin-top: 2px; }
.event-card .ec-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex: none;
  margin-left: 10px;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.14), inset 0 2px 3px rgba(255,255,255,0.3);
}
.event-card .ec-edit {
  flex: none;
  margin-left: 8px;
  background: rgba(0,0,0,0.06);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
}

.weather-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
}
.weather-preview .wp-icon { font-size: 32px; line-height: 1; }
.weather-preview .wp-temp { font-size: 22px; font-weight: 700; }
.weather-preview .wp-sub { font-size: 13px; color: var(--muted); }

.camera-frame {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-top: 12px;
  text-align: center;
}
.camera-frame img, .camera-frame video {
  width: 100%;
  max-width: 420px;
  border-radius: 8px;
  background: #10161f;
  display: block;
  margin: 0 auto;
}

.camera-status-row {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}
.camera-status-block {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.status-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin-bottom: 4px;
}
.status-value { font-size: 17px; font-weight: 700; }
.status-value::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  background: currentColor;
}
.status-value.status-live::before { animation: statusPulse 1.4s ease-in-out infinite; }
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50% { box-shadow: 0 0 0 4px transparent; opacity: 0.7; }
}
.status-value.status-good, .status-value.status-live { color: #27ae60; }
.status-value.status-bad, .status-value.status-error { color: var(--danger); }
.status-value.status-starting { color: #e0a800; }
.status-value.status-stopped, .status-value.status-offline { color: var(--muted); }

.camera-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.camera-controls button {
  margin: 0;
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.camera-controls button:disabled { opacity: 0.45; }
.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.token-qr-box {
  margin-top: 10px;
  text-align: center;
}
#token-qr {
  display: inline-block;
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  line-height: 0;
}
#token-qr svg { width: 220px; height: 220px; }

.token-display {
  font-family: "SFMono-Regular", Consolas, monospace;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  word-break: break-all;
  margin-top: 6px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(20,26,35,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  animation: modalOverlayIn 0.2s ease forwards;
}
@keyframes modalOverlayIn { to { opacity: 1; } }
.modal-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  animation: modalCardIn 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes modalCardIn { to { transform: translateY(0); } }
@media (min-width: 560px) {
  .modal-card { transform: translateY(24px) scale(0.97); }
  @keyframes modalCardIn { to { transform: translateY(0) scale(1); } }
}
@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 16px; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; }
.modal-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
