:root {
  --bg: #041330;
  --surface: #081d40;
  --surface2: #0d2a50;
  --surface3: #12345f;
  --border: #1b3f6b;
  --primary: #2da1db;
  --primary-dim: #2466ac;
  --primary-glow: rgba(45,161,219,0.15);
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --purple: #a855f7;
  --orange: #f97316;
  --text: #f0f0f0;
  --text-muted: #9fb1c6;
  --text-dim: #5d7391;
  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 64px;
  --banner-h: 0px;
  /* iPhone notch and home bar (pages use viewport-fit=cover) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 0px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── NAV ── */
nav {
  position: fixed; top: var(--banner-h); left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 8px;
}

.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; color: var(--text);
  margin-right: 16px; white-space: nowrap;
}
.nav-brand .piano-icon {
  font-size: 22px;
}
.nav-brand span.accent { color: var(--primary); }

.nav-links { display: flex; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: all .15s; cursor: pointer; border: none; background: none;
  text-decoration: none;
}
.nav-link:hover { color: var(--text); background: var(--surface3); text-decoration: none; }
.nav-link.active { color: var(--primary); background: var(--primary-glow); }
.nav-link svg { width: 15px; height: 15px; flex-shrink: 0; }
/* "More" menu for less-used pages (api.js navHtml) */
.nav-more { position: relative; display: flex; }
.nav-more .nav-more-chev { width: 11px; height: 11px; transition: transform .2s; }
.nav-more.open .nav-more-chev { transform: rotate(180deg); }
.nav-more-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 200;
  flex-direction: column; gap: 2px; min-width: 190px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.nav-more.open .nav-more-menu { display: flex; }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.nav-user { font-size: 13px; color: var(--text-muted); }
.nav-user strong { color: var(--text); }

/* ── LAYOUT ── */
.page {
  margin-top: calc(var(--nav-h) + var(--banner-h));
  min-height: calc(100vh - var(--nav-h));
  padding: 32px 24px;
  max-width: 1280px;
  margin-left: auto; margin-right: auto;
}
.page-wide { max-width: 1440px; }

/* ── AUTH ── */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(45,161,219,0.08) 0%, transparent 60%);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px;
  box-shadow: var(--shadow);
}
.auth-logo {
  text-align: center; margin-bottom: 28px;
}
.auth-logo .piano-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.auth-logo h1 span { color: var(--primary); }
.auth-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1; padding: 10px; text-align: center; cursor: pointer;
  color: var(--text-muted); font-weight: 600; font-size: 13px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .15s;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.form-row .form-group { margin-bottom: 0; }
.form-label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;
}
.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
  transition: border-color .15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; transition: all .15s; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:focus, .btn:focus-visible { outline: none; }
.btn-primary { background: var(--primary); color: #000; border: 0; }
.btn-primary:hover, .btn-primary:focus { background: #e0b42f; color: #000; border: 0; outline: none; box-shadow: none; }
.btn-secondary { background: var(--surface3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface2); border-color: #444; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-ghost { background: none; color: var(--text-muted); padding: 6px 10px; }
.btn-ghost:hover { color: var(--text); background: var(--surface3); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-full { width: 100%; justify-content: center; }

/* ── CARDS ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-muted); margin-bottom: 16px;
}

/* ── KPI GRID ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 28px; font-weight: 800; line-height: 1; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-card.gold { border-color: rgba(45,161,219,0.4); background: linear-gradient(135deg, var(--surface) 0%, rgba(45,161,219,0.05) 100%); }
.kpi-card.gold .kpi-value { color: var(--primary); }
.kpi-card.blue .kpi-value { color: var(--blue); }
.kpi-card.green .kpi-value { color: var(--green); }
.kpi-card.purple .kpi-value { color: var(--purple); }
.kpi-card.orange .kpi-value { color: var(--orange); }

/* ── BADGE ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 700;
}
.badge-gold { background: rgba(45,161,219,0.2); color: var(--primary); border: 1px solid rgba(45,161,219,0.4); }
.badge-blue { background: rgba(59,130,246,0.15); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.badge-green { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.badge-purple { background: rgba(168,85,247,0.15); color: var(--purple); border: 1px solid rgba(168,85,247,0.3); }
.badge-orange { background: rgba(249,115,22,0.15); color: var(--orange); border: 1px solid rgba(249,115,22,0.3); }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 12px 14px; font-size: 13px; vertical-align: middle; }
.rank-1 td:first-child { color: var(--primary); font-weight: 800; }
.rank-2 td:first-child { color: #c0c0c0; font-weight: 700; }
.rank-3 td:first-child { color: #cd7f32; font-weight: 700; }

/* ── PROGRESS BAR ── */
.progress-bar {
  height: 6px; background: var(--surface3); border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary); border-radius: 99px;
  transition: width .4s ease;
}
.progress-fill.blue { background: var(--blue); }
.progress-fill.green { background: var(--green); }

/* ── DAILY LOG FORM ── */
.log-grid { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.day-picker-list { display: flex; flex-direction: column; gap: 4px; max-height: calc(100vh - 160px); overflow-y: auto; }
.day-btn {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent; background: none; color: var(--text-muted);
  font-size: 13px; transition: all .1s; text-align: left; width: 100%;
}
.day-btn:hover { background: var(--surface2); color: var(--text); }
.day-btn.active { background: var(--primary-glow); border-color: rgba(45,161,219,0.4); color: var(--primary); font-weight: 600; }
.day-btn.logged { color: var(--text); }
.day-btn .dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.day-btn.logged .dot { background: var(--green); }
.day-btn:not(.logged) .dot { background: var(--surface3); border: 1px solid var(--border); }
.day-btn.future { opacity: .45; }

.entry-form-card { position: sticky; top: calc(var(--nav-h) + 20px); }

/* Checkboxes in form */
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border);
  cursor: pointer; user-select: none; transition: all .1s;
}
.check-item:hover { border-color: #444; }
.check-item input[type=checkbox] { display: none; }
.check-item .check-box {
  width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0;
  border: 2px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center; transition: all .1s;
}
.check-item input:checked ~ .check-box {
  background: var(--primary); border-color: var(--primary);
}
.check-item input:checked ~ .check-box::after {
  content: '✓'; font-size: 11px; color: #000; font-weight: 800;
}
.check-item input:checked ~ .check-label { color: var(--text); }
.check-label { font-size: 13px; color: var(--text-muted); line-height: 1.3; }
.check-pts { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--primary); }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric-input { position: relative; }
.metric-input label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 5px; }
.metric-input input {
  width: 100%; padding: 9px 10px 9px 32px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
}
.metric-input input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.metric-icon { position: absolute; bottom: 9px; left: 10px; font-size: 13px; color: var(--text-dim); }
.pts-label { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* Score preview */
.score-preview {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.sp-item {
  text-align: center;
  padding: 12px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s;
}
.sp-item.total {
  border-color: rgba(34,197,94,.4);
  background: rgba(34,197,94,.06);
}
.sp-val { font-size: 20px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.sp-label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-top: 4px; }
.sp-item.total .sp-val { font-size: 26px; color: var(--green); }
@media (max-width: 540px) {
  .score-preview { grid-template-columns: repeat(2, 1fr); }
}

/* ── WEEKLY HEATMAP ── */
.heatmap-wrap { overflow-x: auto; }
.heatmap-table { min-width: 900px; }
.heatmap-table td.heat-cell {
  text-align: center; font-size: 12px; font-weight: 600;
  border-radius: 4px; min-width: 58px;
}
.heat-0 { background: var(--surface2); color: var(--text-dim); }
.heat-1 { background: rgba(45,161,219,0.12); color: #2466ac; }
.heat-2 { background: rgba(45,161,219,0.25); color: #c09020; }
.heat-3 { background: rgba(45,161,219,0.45); color: #d4a820; }
.heat-4 { background: rgba(45,161,219,0.7); color: #1a1200; }
.heat-5 { background: var(--primary); color: #000; }

/* ── CHART ── */
.chart-wrap { position: relative; height: 200px; }

/* ── PAGE HEADER ── */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 24px; font-weight: 800; }
.page-header p { color: var(--text-muted); margin-top: 4px; }

/* ── SECTION ── */
.section { margin-top: 24px; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-muted); margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── ALERT / TOAST ── */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px;
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}
.alert-error { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.3); color: #86efac; }
.alert-info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.25); color: #93c5fd; }

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 20px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: none; } }

/* ── SPINNER ── */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; padding: 48px; }

/* ── MISC ── */
.text-gold { color: var(--primary); }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 960px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-body { overflow-y: auto; flex: 1; }

/* ── ADMIN TABS ── */
.admin-tabs {
  display: flex; flex-wrap: wrap; gap: 0 2px; margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.admin-tab {
  padding: 10px 22px; border: none; background: none;
  color: var(--text-muted); font-size: 13px; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: all .15s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── NAV PROFILE DROPDOWN ── */
.nav-profile { position: relative; }
.nav-profile-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: all .15s;
}
.nav-profile-btn:hover { background: var(--surface3); color: var(--text); }
.nav-profile-btn svg { width: 12px; height: 12px; transition: transform .2s; flex-shrink: 0; }
.nav-profile.open .nav-profile-btn svg { transform: rotate(180deg); }
.nav-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); min-width: 170px;
  box-shadow: var(--shadow); z-index: 200; overflow: hidden;
}
.nav-profile.open .nav-dropdown { display: block; }
.nav-dropdown-item {
  display: flex; align-items: center; width: 100%;
  padding: 10px 16px; font-size: 13px; color: var(--text-muted);
  background: none; border: none; cursor: pointer;
  text-align: left; text-decoration: none; transition: all .1s;
}
.nav-dropdown-item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-dropdown-danger:hover { color: var(--red); }

/* ── WELCOME MODAL ── */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.welcome-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 580px;
  box-shadow: var(--shadow); overflow: hidden;
}
.welcome-box-header { padding: 32px 32px 0; text-align: center; }
.welcome-box-body { padding: 20px 32px 32px; }
.welcome-box-body video { width: 100%; border-radius: var(--radius-sm); margin-bottom: 16px; display: block; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ── MERCH ── */
.merch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.merch-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; transition: border-color .2s, transform .2s;
}
.merch-card:hover { border-color: rgba(45,161,219,0.4); transform: translateY(-3px); }
.merch-img-wrap { width: 100%; aspect-ratio: 1; overflow: hidden; background: var(--surface2); }
.merch-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.merch-img-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 48px; color: var(--text-muted); }
.merch-body { padding: 16px; }
.merch-name { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.merch-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.merch-footer { display: flex; align-items: center; justify-content: space-between; }
.merch-price { font-size: 20px; font-weight: 900; color: var(--primary); }

/* ── CHAT BUBBLE ── */
#chat-unread-badge { display: flex; }

@media (max-width: 768px) {
  .log-grid { grid-template-columns: 1fr; }
  .entry-form-card { position: static; }
  .day-picker-list { max-height: 200px; flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; gap: 16px; }
  .check-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  nav { padding: 0 12px; }
  .nav-brand span:not(.accent):not(.piano-icon) { display: none; }
  /* Challenge Progress: stack to single column on mobile */
  .challenge-progress-grid { grid-template-columns: 1fr !important; }
  /* Dashboard header: stack greeting and days badge on mobile */
  .page-header.flex { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header.flex > div:last-child { margin-left: 0 !important; align-self: flex-start; }
  /* Chat bubble positioned via JS in api.js (positionChatPanel) */
}

/* ── ADMIN TAB MOBILE HAMBURGER ── */
.admin-tabs-wrapper { position: relative; }
.admin-tab-mobile { display: none; }
.admin-tab-mobile-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface2);
  color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; width: 100%; justify-content: space-between;
}
.admin-tab-mobile-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  z-index: 100; overflow-y: auto; overscroll-behavior: contain;
  max-height: calc(100vh - var(--banner-h) - 140px); max-height: calc(100dvh - var(--banner-h) - 140px);
}
.admin-tab-mobile-item {
  display: block; width: 100%; padding: 12px 16px;
  border: none; background: none; color: var(--text);
  font-size: 14px; text-align: left; cursor: pointer;
}
.admin-tab-mobile-item:hover { background: var(--surface2); }
.admin-tab-mobile-item.active { color: var(--primary); font-weight: 700; }
@media (max-width: 768px) {
  /* The section picker stays just under the nav while the page scrolls (top set from the nav's height in admin.html). */
  .admin-tabs-wrapper { position: sticky; top: calc(var(--banner-h) + 58px); z-index: 50; background: var(--bg); padding: 8px 0; margin: -8px 0 8px; }
  .admin-tab-mobile { display: block; }
  .admin-tabs { display: none; }
}

/* ── HAMBURGER MENU ── */
.nav-hamburger {
  display: none;
  flex-direction: column; justify-content: space-between;
  width: 28px; height: 20px;
  background: none; border: none; cursor: pointer;
  padding: 0; margin-left: auto;
}
.nav-hamburger span {
  display: block; width: 100%; height: 2px;
  background: var(--text-muted); border-radius: 2px;
  transition: all .25s;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }
.day-btn.locked { opacity: .35; }
/* Hidden on desktop — only visible inside mobile hamburger menu */
.nav-mobile-only { display: none; }
.nav-mobile-divider { display: none; }

@media (max-width: 768px) {
  nav { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 0; }
  .nav-brand { flex: 1; }
  .nav-hamburger { display: flex; order: 2; }
  .nav-right { order: 3; display: none; }
  /* Open menu: scrolls on its own, fits the screen, and holds the page still behind it. */
  nav:has(.nav-mobile-open) { max-height: calc(100vh - var(--banner-h)); max-height: calc(100dvh - var(--banner-h)); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  body.nav-open { overflow: hidden; }
  .nav-links {
    display: none; flex-direction: column; width: 100%; flex: 0 0 100%;
    order: 4; gap: 4px; padding: 8px 0 4px;
    border-top: 1px solid var(--border); margin-top: 8px;
  }
  .nav-links.nav-mobile-open { display: flex; }
  .nav-links.nav-mobile-open ~ .nav-right { display: flex; order: 5; width: 100%; padding: 4px 0 8px; border-top: 1px solid var(--border); }
  .nav-link { padding: 10px 8px; font-size: 14px; }
  /* The "More" pages are listed inline in the mobile menu. */
  .nav-more { flex-direction: column; }
  .nav-more-btn { display: none; }
  .nav-more-menu { display: flex; position: static; min-width: 0; padding: 0; border: none; box-shadow: none; background: none; gap: 4px; }
  /* Mobile-only profile / sign-out nav items */
  .nav-mobile-only { display: flex; }
  .nav-mobile-divider { display: block; height: 1px; background: var(--border); margin: 4px 0; width: 100%; }
  .nav-mobile-signout { color: var(--red) !important; background: none; border: none; cursor: pointer; width: 100%; text-align: left; font-size: 14px; font-family: inherit; }
  /* below the install banner and the notch too (the top of pages was hidden under the banner) */
  .page { margin-top: calc(var(--nav-h) + var(--banner-h) + var(--safe-top) + 8px); padding: 16px 16px 32px; }
  nav { padding-top: calc(12px + var(--safe-top)); }
  #log-today-cta .btn { display: block; text-align: center; width: 100%; box-sizing: border-box; }
  /* Pending approvals table — hide Phone + Applied on mobile, keep Name + Email + Actions */
  .pending-table thead tr th:nth-child(3),
  .pending-table thead tr th:nth-child(4),
  .pending-table tbody tr td:nth-child(3),
  .pending-table tbody tr td:nth-child(4) {
    display: none;
  }
}

/* ── PHONE TAB BAR (2026-11-13) ── */
.tabbar { display: none; }
.draft-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 99px;
  background: var(--primary); color: #000; font-size: 10.5px; font-weight: 800; line-height: 1;
}
.tabbar .draft-badge { position: absolute; top: 5px; left: calc(50% + 6px); margin: 0; border: 2px solid var(--bg); height: 20px; }
.tabbar > a { position: relative; }
@media (max-width: 768px) {
  body.has-tabbar { --tabbar-h: calc(62px + var(--safe-bottom)); padding-bottom: var(--tabbar-h); }
  .has-tabbar .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 400;
    height: var(--tabbar-h); padding: 0 4px var(--safe-bottom);
    background: rgba(14,14,14,0.97); border-top: 1px solid var(--border);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  }
  .tabbar > a, .tabbar > button {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--text-muted); font-family: inherit; font-size: 11px; font-weight: 600; line-height: 1; text-decoration: none;
    background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .tabbar > [hidden] { display: none; }
  .tabbar svg { width: 23px; height: 23px; }
  .tabbar .on { color: var(--primary); }
  .tabbar .tab-plus {
    width: 48px; height: 48px; margin-top: -20px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary); color: #000; box-shadow: 0 4px 16px rgba(45,161,219,0.45); border: 3px solid var(--bg);
  }
  .tabbar .tab-plus svg { width: 24px; height: 24px; }
  /* The Menu tab opens the menu, so the top bar needs no hamburger. */
  .has-tabbar .nav-hamburger { display: none; }
  .has-tabbar nav:has(.nav-mobile-open) { padding-bottom: calc(var(--tabbar-h) + 12px); }
  .has-tabbar .toast { bottom: calc(var(--tabbar-h) + 14px); left: 16px; right: 16px; }
  .has-tabbar #chat-bubble-btn { bottom: calc(var(--tabbar-h) + 12px) !important; right: 12px !important; width: 48px !important; height: 48px !important; }
  /* Thumb-sized buttons, and no zooming in on iPhones when typing (needs 16px). */
  .btn { min-height: 42px; }
  .btn-sm { min-height: 40px; }
  input.form-input, select.form-input, textarea.form-input, .form-input { font-size: 16px; }
  /* 2026-11-15: every typing box, including the chat's (it zoomed the whole app in and left it zoomed). */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]), textarea, select { font-size: 16px !important; }
  /* The chat fills the screen on a phone; the bubble and tab bar step aside. */
  body.chat-open #chat-bubble-btn, body.chat-open .tabbar { display: none !important; }
  body.chat-open #chat-bubble-container { z-index: 1001; }
  /* thumb-sized close and DM buttons in the chat header */
  #chat-panel-header button[onclick="toggleChat()"] { min-width: 44px; min-height: 44px; font-size: 26px !important; }
  #chat-panel-header #new-dm-btn { min-height: 36px; padding: 6px 12px !important; font-size: 13px !important; }   /* the chat sits in this box; above the top bar and the install banner */
  #chat-panel #chat-messages-list, #chat-panel [id$="-list"] { overscroll-behavior: contain; }
}

/* WCAG 2.2.2 / 2.3.3 (2026-11-13): people who ask for less motion get none. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
