/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0e1a;
  --surface: #131929;
  --surface2: #1a2235;
  --border: #1e2d45;
  --primary: #f59e0b;
  --primary-dim: rgba(245,158,11,0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.15);
  --warning: #f97316;
  --warning-dim: rgba(249,115,22,0.15);
  --success: #10b981;
  --success-dim: rgba(16,185,129,0.15);
  --text: #f1f5f9;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 72px;
  --header-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, a, label, select, input {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ── Onboarding ── */
.onboarding {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px calc(40px + var(--safe-bottom));
}

.onboarding-inner {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.onboarding-logo {
  font-size: 64px;
  margin-bottom: 12px;
  animation: spin-slow 8s linear infinite;
}

@keyframes spin-slow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.onboarding-inner h1 {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--primary);
  margin-bottom: 8px;
}

.onboarding-sub {
  color: var(--text-soft);
  font-size: 15px;
  margin-bottom: 36px;
}

.ob-step { display: none; animation: fadeIn 0.3s ease; }
.ob-step.active { display: block; }

.ob-step h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}

.step-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.member-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.count-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s;
}

.count-btn:active { background: var(--primary-dim); border-color: var(--primary); }

.count-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.count-display span {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.count-display label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.checklist-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.check-item {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-size: 13px;
  color: var(--text-soft);
}

.check-item input { display: none; }
.check-item:has(input:checked) {
  border-color: var(--success);
  background: var(--success-dim);
  color: var(--text);
}

.check-icon { font-size: 24px; }

.ob-next-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: #000;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 24px;
  transition: opacity 0.2s;
}

.ob-next-btn:active { opacity: 0.85; }

.onboarding-done-icon { font-size: 64px; margin: 24px 0; }

/* ── App Shell ── */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top, 0px);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo { font-size: 22px; }

.app-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.alert-badge {
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  animation: pulse-badge 1.5s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

/* ── Views ── */
.view {
  display: none;
  padding: 20px;
  animation: fadeIn 0.2s ease;
  min-height: 100%;
}

.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.view-header h2 {
  font-size: 22px;
  font-weight: 800;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}

/* ── Weather Card ── */
.weather-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  transition: border-color 0.4s, background 0.4s;
}

.weather-card.level-watch {
  border-color: var(--warning);
  background: linear-gradient(135deg, var(--surface) 0%, var(--warning-dim) 100%);
}

.weather-card.level-warning {
  border-color: var(--danger);
  background: linear-gradient(135deg, var(--surface) 0%, var(--danger-dim) 100%);
}

.weather-card.level-clear {
  border-color: var(--success);
}

.weather-status-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.weather-icon { font-size: 48px; }

.weather-level {
  font-size: 18px;
  font-weight: 800;
}

.weather-desc {
  font-size: 14px;
  color: var(--text-soft);
  margin-top: 2px;
}

.weather-updated {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 12px;
}

/* ── Active Alerts ── */
.alert-item {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
}

.alert-item .alert-event {
  font-size: 14px;
  font-weight: 700;
  color: var(--danger);
  margin-bottom: 4px;
}

.alert-item .alert-headline {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.4;
}

/* ── Readiness Bar ── */
.readiness-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.readiness-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.readiness-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 6px;
}

.readiness-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--success);
  transition: width 0.6s ease;
  width: 0%;
}

.readiness-pct {
  font-size: 13px;
  font-weight: 700;
  color: var(--success);
  text-align: right;
}

/* ── Critical List ── */
.critical-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.critical-item.ok { border-color: var(--success); }
.critical-item.low { border-color: var(--warning); }
.critical-item.missing { border-color: var(--danger); }

.critical-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ok .critical-dot { background: var(--success); }
.low .critical-dot { background: var(--warning); }
.missing .critical-dot { background: var(--danger); }

.critical-name { flex: 1; font-size: 14px; }

.critical-status {
  font-size: 12px;
  font-weight: 600;
}

.ok .critical-status { color: var(--success); }
.low .critical-status { color: var(--warning); }
.missing .critical-status { color: var(--danger); }

/* ── Family Summary ── */
.family-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.fam-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.fam-stat .fam-num {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.fam-stat .fam-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Inventory ── */
.add-btn {
  background: var(--primary);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  border: none;
  border-radius: 99px;
  cursor: pointer;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 16px;
  padding-bottom: 2px;
}

.category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.cat-tab.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.inventory-list { display: flex; flex-direction: column; gap: 8px; }

.inv-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.inv-item.expiring-soon { border-color: var(--warning); }
.inv-item.expired { border-color: var(--danger); }

.inv-emoji { font-size: 22px; flex-shrink: 0; }

.inv-info { flex: 1; min-width: 0; }

.inv-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.inv-expiry-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 600;
  flex-shrink: 0;
}

.expiring-soon .inv-expiry-tag { background: var(--warning-dim); color: var(--warning); }
.expired .inv-expiry-tag { background: var(--danger-dim); color: var(--danger); }

.inv-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Recommendations ── */
.rec-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.rec-item.urgent { border-color: var(--danger); }
.rec-item.important { border-color: var(--warning); }
.rec-item.normal { border-color: var(--border); }

.rec-icon { font-size: 22px; flex-shrink: 0; }

.rec-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.rec-desc {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.4;
}

.rec-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.urgent .rec-badge { background: var(--danger-dim); color: var(--danger); }
.important .rec-badge { background: var(--warning-dim); color: var(--warning); }
.normal .rec-badge { background: var(--primary-dim); color: var(--primary); }

/* ── Profile ── */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.profile-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 8px;
  text-align: center;
}

.profile-stat .ps-icon { font-size: 28px; }
.profile-stat .ps-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin: 4px 0 2px;
}
.profile-stat .ps-label { font-size: 10px; color: var(--text-muted); }

.edit-profile-btn {
  width: 100%;
  padding: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.equipment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.equip-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.equip-item.has { border-color: var(--success); color: var(--text); }
.equip-item.missing { color: var(--text-muted); }

.equip-check {
  font-size: 16px;
  flex-shrink: 0;
}

.notif-settings { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}

.toggle-row:last-child { border-bottom: none; }

.toggle-row input[type="checkbox"] {
  width: 44px;
  height: 26px;
  appearance: none;
  background: var(--border);
  border-radius: 99px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-row input[type="checkbox"]:checked {
  background: var(--success);
}

.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s;
  padding: 8px 0;
}

.nav-btn.active { color: var(--primary); }

.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding-bottom: calc(20px + var(--safe-bottom));
  animation: slide-up 0.3s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: var(--surface2);
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body { padding: 20px; }

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group select option { background: var(--surface2); }

.save-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: #000;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 8px;
}

.save-btn:active { opacity: 0.85; }
