/* ═══════════════════════════════════════════════════════
   DESIGN SYSTEM (Light, Premium Aesthetic)
   ═══════════════════════════════════════════════════════ */
:root {
  --bg-deep: #f4f6f9;         /* Very light cool gray for main background */
  --bg-card: #ffffff;         /* Clean white for cards */
  --bg-card-hover: #f8f9fb;   
  --border: rgba(0, 0, 0, 0.08); 
  --border-active: rgba(0, 122, 255, 0.4);
  --accent: #007aff;          /* Premium iOS-style blue */
  --accent-dim: rgba(0, 122, 255, 0.1);
  --accent-glow: 0 4px 15px rgba(0, 122, 255, 0.2);
  --warn: #ff3b30;
  --success: #34c759;
  --orange: #ff9500;
  --purple: #af52de;
  
  --text-1: #1d1d1f;          /* Deep gray/black for primary text */
  --text-2: #86868b;          /* Medium gray for secondary text */
  --text-3: #aeaeb2;          /* Light gray for hints/disabled */
  
  --radius: 24px;
  --radius-sm: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-deep);
  color: var(--text-1);
  height: 100%; width: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ═══════════════════════════════════════════════════════
   LAYOUT SHELL
   ═══════════════════════════════════════════════════════ */
#app {
  display: flex; flex-direction: column;
  height: 100%;
  background: var(--bg-deep);
}

.page { display: none; flex-direction: column; flex: 1; overflow-y: auto; }
.page.active { display: flex; }
.page::-webkit-scrollbar { display: none; }

/* ── Top Bar ── */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}
.topbar-title { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.ble-chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 50px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  cursor: pointer; transition: all .25s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}
.ble-chip:active { transform: scale(.96); }
.ble-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); 
  transition: all .4s;
}
.ble-dot.on { background: var(--success); box-shadow: 0 0 8px rgba(52,199,89,0.4); }

/* ── Bottom Nav ── */
.navbar {
  display: flex; justify-content: space-around; align-items: flex-start;
  padding: 12px 0 calc(10px + var(--safe-bottom));
  background: rgba(255,255,255,0.9);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0; position: relative; z-index: 50;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; color: var(--text-3);
  cursor: pointer; padding: 4px 12px; transition: color .25s;
}
.nav-item.active { color: var(--accent); }
.nav-item svg { width: 24px; height: 24px; }

/* ═══════════════════════════════════════════════════════
   PAGE 1: KEY CONTROL
   ═══════════════════════════════════════════════════════ */
.car-hero {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 10px 20px; position: relative;
}
.car-vis {
  width: 280px; height: 200px; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.car-svg { width: 100%; height: 100%; }
.car-glow {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(0,122,255,0.05) 0%, transparent 60%);
  animation: pulse-glow 4s ease-in-out infinite;
}
@keyframes pulse-glow { 0%,100%{opacity:.6;transform:scale(1)} 50%{opacity:1;transform:scale(1.05)} }

.status-pill {
  margin-top: 12px; display: flex; align-items: center; gap: 8px;
  padding: 8px 20px; border-radius: 50px;
  background: var(--bg-card); border: 1px solid var(--border);
  font-size: 14px; font-weight: 600; color: var(--text-2);
  transition: all .3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}
.status-pill.unlocked { border-color: rgba(0,122,255,0.3); color: var(--accent); background: #f0f7ff; }
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3); transition: all .3s;
}
.status-pill.unlocked .dot { background: var(--accent); }

/* ── Control Grid ── */
.ctrl-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 16px; padding: 16px 20px 24px; flex-shrink: 0;
}
.ctrl-btn {
  position: relative; overflow: hidden;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; transition: all .2s cubic-bezier(.4,0,.2,1);
  -webkit-user-select: none; user-select: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.02);
}
.ctrl-btn:active { transform: scale(.96); background: var(--bg-card-hover); }
.ctrl-btn.highlight { 
  border-color: var(--accent); 
  background: #f0f7ff;
}
.ctrl-btn svg { width: 32px; height: 32px; color: var(--text-2); transition: color .3s; }
.ctrl-btn.highlight svg { color: var(--accent); }
.ctrl-label { font-size: 15px; font-weight: 700; color: var(--text-1); transition: color .3s; }
.ctrl-btn.highlight .ctrl-label { color: var(--accent); }
.ctrl-hint { font-size: 11px; font-weight: 500; color: var(--text-3); margin-top: -4px; }

/* Long press indicator */
.lp-ring {
  position: absolute; inset: 0; border-radius: var(--radius);
  border: 3px solid transparent; pointer-events: none;
  transition: border-color .15s;
}
.ctrl-btn.pressing .lp-ring {
  border-color: var(--accent);
  animation: lp-fill 800ms linear forwards;
}
@keyframes lp-fill {
  0% { clip-path: inset(0 100% 0 0); }
  100% { clip-path: inset(0 0 0 0); }
}

/* Quick actions row */
.quick-row {
  display: flex; gap: 12px; padding: 0 20px 16px; flex-shrink: 0;
}
.quick-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px 10px;
  font-size: 13px; font-weight: 600; color: var(--text-1);
  cursor: pointer; transition: all .2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}
.quick-btn:active { transform: scale(.96); background: var(--bg-card-hover); }
.quick-btn svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-2); }

/* ═══════════════════════════════════════════════════════
   PAGE 2: PEPS (Comfortable Entry)
   ═══════════════════════════════════════════════════════ */
.section-header {
  padding: 24px 20px 12px;
  font-size: 13px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.card {
  margin: 0 20px 12px; padding: 20px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.02);
}
.card-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0;
}
.card-row + .card-row { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; }
.card-label { font-size: 16px; font-weight: 600; color: var(--text-1); }
.card-sublabel { font-size: 13px; color: var(--text-2); margin-top: 4px; line-height: 1.4; }

/* Toggle Switch */
.toggle {
  width: 52px; height: 32px; border-radius: 16px;
  background: #e9e9ea; position: relative;
  cursor: pointer; transition: background .3s;
  flex-shrink: 0; border: 1px solid rgba(0,0,0,0.05);
}
.toggle.on { background: var(--success); border-color: transparent; }
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 26px; height: 26px; border-radius: 50%;
  background: white; transition: transform .3s cubic-bezier(0.4, 0.0, 0.2, 1);
  box-shadow: 0 2px 5px rgba(0,0,0,.2);
}
.toggle.on::after { transform: translateX(20px); }

/* Range Slider */
.slider-group { margin-top: 20px; }
.slider-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; color: var(--text-1); font-weight: 500; margin-bottom: 12px;
}
.slider-val { font-weight: 700; color: var(--accent); font-size: 15px; }
input[type=range] {
  width: 100%; height: 6px; border-radius: 3px;
  background: #e9e9ea; outline: none;
  -webkit-appearance: none; appearance: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════
   PAGE 3: DEVICE INFO
   ═══════════════════════════════════════════════════════ */
.info-hero {
  display: flex; flex-direction: column; align-items: center;
  padding: 30px 20px 20px;
}
.info-avatar {
  width: 88px; height: 88px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #5ac8fa 100%);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px; box-shadow: 0 8px 24px rgba(0,122,255,0.2);
}
.info-avatar svg { width: 40px; height: 40px; color: white; }
.info-name { font-size: 24px; font-weight: 800; }
.info-mac { font-size: 13px; color: var(--text-2); margin-top: 6px; font-family: monospace; }

.info-stats {
  display: grid; grid-template-columns: repeat(3,1fr);
  gap: 12px; padding: 20px; width: 100%;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 18px 10px;
  text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}
.stat-val { font-size: 24px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-2); margin-top: 6px; }

.menu-item {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 0;
}
.menu-item + .menu-item { border-top: 1px solid var(--border); }
.menu-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.menu-icon svg { width: 20px; height: 20px; }
.menu-icon.blue { background: rgba(0,122,255,0.1); color: var(--accent); }
.menu-icon.orange { background: rgba(255,149,0,0.1); color: var(--orange); }
.menu-icon.purple { background: rgba(175,82,222,0.1); color: var(--purple); }
.menu-icon.red { background: rgba(255,59,48,0.1); color: var(--warn); }
.menu-text { flex: 1; }
.menu-text .mt { font-size: 16px; font-weight: 600; color: var(--text-1); }
.menu-text .ms { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.menu-arrow { color: var(--text-3); font-size: 20px; }

/* ═══════════════════════════════════════════════════════
   PAGE 4: SETTINGS
   ═══════════════════════════════════════════════════════ */
.settings-item {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 0; cursor: pointer;
  transition: opacity 0.2s;
}
.settings-item:active { opacity: 0.6; }
.settings-item + .settings-item { border-top: 1px solid var(--border); }

/* ═══════════════════════════════════════════════════════
   MODAL / OVERLAY
   ═══════════════════════════════════════════════════════ */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
.overlay.show { opacity: 1; pointer-events: all; }
.sheet {
  width: 100%; max-width: 420px;
  background: #ffffff; border-radius: 28px 28px 0 0;
  padding: 28px 24px calc(24px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .35s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}
.overlay.show .sheet { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 5px; border-radius: 3px;
  background: #e0e0e0; margin: 0 auto 24px;
}
.sheet-title { font-size: 20px; font-weight: 800; text-align: center; margin-bottom: 24px; color: var(--text-1); }
.sheet-input {
  width: 100%; padding: 16px; border-radius: var(--radius-sm);
  background: #f8f9fb; border: 1px solid var(--border);
  color: var(--text-1); font-size: 15px; outline: none;
  font-family: monospace; margin-bottom: 16px;
  transition: border-color 0.3s;
}
.sheet-input:focus { border-color: var(--accent); background: #fff; }
.sheet-btn {
  width: 100%; padding: 16px; border: none; border-radius: var(--radius-sm);
  background: var(--accent);
  color: white; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: transform .2s;
  box-shadow: 0 4px 12px rgba(0,122,255,0.3);
}
.sheet-btn:active { transform: scale(0.98); }
.sheet-btn.danger {
  background: var(--warn);
  box-shadow: 0 4px 12px rgba(255,59,48,0.3);
}

/* ═══════════════════════════════════════════════════════
   LOG CONSOLE
   ═══════════════════════════════════════════════════════ */
.log-strip {
  padding: 8px 20px; flex-shrink: 0;
  overflow: hidden; height: 32px;
  background: rgba(0,0,0,0.02);
  border-top: 1px solid var(--border);
}
.log-msg {
  font-size: 11px; font-family: monospace; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .3s; font-weight: 500;
}
.log-msg.tx { color: var(--accent); }
.log-msg.rx { color: var(--success); }
.log-msg.err { color: var(--warn); }

/* Utility */
.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }

/* ═══════════════════════════════════════════════════════
   SHARE FEATURE
   ═══════════════════════════════════════════════════════ */
.share-duration-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 10px; margin-bottom: 20px;
}
.share-dur-btn {
  padding: 14px 10px; border-radius: var(--radius-sm);
  background: #f8f9fb; border: 2px solid var(--border);
  font-size: 15px; font-weight: 600; color: var(--text-1);
  text-align: center; cursor: pointer;
  transition: all .2s;
}
.share-dur-btn:active { transform: scale(.97); }
.share-dur-btn.selected {
  border-color: var(--accent);
  background: rgba(0,122,255,0.06);
  color: var(--accent);
}
.share-link-box {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-sm);
  background: #f8f9fb; border: 1px solid var(--border);
  font-size: 12px; font-family: monospace; color: var(--text-2);
  word-break: break-all; margin-bottom: 16px;
  min-height: 48px; display: flex; align-items: center;
  line-height: 1.5;
}
.share-link-box.empty { color: var(--text-3); font-family: inherit; font-size: 14px; justify-content: center; }

/* ── Expired Overlay ── */
.expired-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-deep);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px; padding: 40px;
}
.expired-icon {
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,59,48,0.08);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.expired-icon svg { width: 48px; height: 48px; color: var(--warn); }
.expired-title { font-size: 24px; font-weight: 800; color: var(--text-1); }
.expired-desc { font-size: 15px; color: var(--text-2); text-align: center; line-height: 1.6; }

/* ── Guest Mode Badge ── */
.guest-badge {
  display: none;
  align-items: center; gap: 6px;
  background: rgba(255,149,0,0.1); border: 1px solid rgba(255,149,0,0.3);
  padding: 4px 12px; border-radius: 50px;
  font-size: 11px; font-weight: 700; color: var(--orange);
}
body.guest-mode .guest-badge { display: flex; }
body.guest-mode .owner-only { display: none !important; }
