@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ─── Design Tokens ─────────────────────────────────────── */
:root {
  --primary:        #10b981;
  --primary-dark:   #059669;
  --primary-light:  #34d399;
  --accent:         #f59e0b;
  --accent-dark:    #d97706;
  --surface:        #000000;
  --surface-2:      #111111;
  --surface-3:      #1c1c1e;
  --card:           rgba(255,255,255,0.08);
  --card-border:    rgba(255,255,255,0.1);
  --text:           #ffffff;
  --text-muted:     #8e8e93;
  --text-sub:       #ebebf599;
  --danger:         #ff3b30;
  --info:           #0a84ff;
  --font-sans:      -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Helvetica Neue", sans-serif;
  --font-mono:      "SF Mono", "JetBrains Mono", monospace;
  --radius-sm:      0.75rem;
  --radius:         1.25rem;
  --radius-lg:      1.75rem;
  --radius-xl:      2.5rem;
  --shadow-sm:      0 2px 8px rgba(0,0,0,0.4);
  --shadow:         0 10px 40px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.05);
  --shadow-lg:      0 20px 80px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.1);
  --transition:     0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
  --spring:         0.5s cubic-bezier(0.32, 0.72, 0, 1);
  --top-bar-h:      60px;
  --bottom-bar-h:   84px;
  --drawer-w:       280px;
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mono { font-family: var(--font-mono); }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: var(--font-sans); }
input, textarea { font-family: var(--font-sans); }

/* ─── App Shell ──────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* Top Bar */
#top-bar {
  height: var(--top-bar-h);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 0.5px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}
#top-bar .wordmark {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
#top-bar .wordmark .pin-icon {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: 0.5rem;
  display: flex; align-items: center; justify-content: center;
}
#top-bar .wordmark .pin-icon svg { width: 14px; height: 14px; stroke: white; fill: none; stroke-width: 2.5; }
#top-bar .wordmark span em { font-style: normal; color: var(--primary); }

#hamburger-btn {
  width: 36px; height: 36px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
#hamburger-btn:active { background: var(--card); }
#hamburger-btn span {
  display: block; width: 18px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

#status-badge {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
#status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}
#status-dot.online { background: var(--primary); box-shadow: 0 0 8px var(--primary); }
#status-dot.offline { background: var(--danger); }

/* Content Area */
#content-area {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity var(--transition), transform var(--transition);
  padding-bottom: 0.5rem;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}
.screen::-webkit-scrollbar { width: 3px; }
.screen::-webkit-scrollbar-track { background: transparent; }
.screen::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

/* Bottom Ribbon */
#bottom-bar {
  height: var(--bottom-bar-h);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(30px) saturate(200%);
  -webkit-backdrop-filter: blur(30px) saturate(200%);
  border-top: 0.5px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  z-index: 100;
  padding: 0 0.5rem;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-btn {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  padding: 0.5rem 0;
  border-radius: var(--radius);
  transition: all var(--transition);
  color: var(--text-muted);
  position: relative;
}
.tab-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; transition: all var(--spring); }
.tab-btn span { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.tab-btn.active { color: var(--primary); }
.tab-btn.active svg { transform: scale(1.15); }
.tab-btn .tab-pill {
  position: absolute;
  top: 4px;
  width: 28px; height: 3px;
  background: var(--primary);
  border-radius: 999px;
  opacity: 0;
  transform: scaleX(0);
  transition: all var(--spring);
}
.tab-btn.active .tab-pill { opacity: 1; transform: scaleX(1); }
.tab-btn:active { transform: scale(0.92); }

/* ─── Side Drawer ────────────────────────────────────────── */
#drawer-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
#drawer-overlay.open { opacity: 1; pointer-events: all; }

#side-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--drawer-w);
  background: var(--surface-2);
  border-right: 1px solid var(--card-border);
  z-index: 950;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--spring);
  overflow-y: auto;
}
#side-drawer.open { transform: translateX(0); }

.drawer-profile {
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--card-border);
  background: linear-gradient(135deg, rgba(5,150,105,0.15), transparent);
}
.drawer-avatar {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 900;
  color: white;
  margin-bottom: 0.75rem;
  box-shadow: 0 0 0 3px rgba(5,150,105,0.3);
}
.drawer-name { font-size: 0.95rem; font-weight: 800; margin-bottom: 0.2rem; }
.drawer-meta { font-size: 0.72rem; color: var(--text-sub); font-weight: 500; }
.drawer-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  margin-top: 0.6rem;
  background: rgba(5,150,105,0.15);
  border: 1px solid rgba(5,150,105,0.3);
  color: var(--primary);
  font-size: 0.65rem; font-weight: 700;
  padding: 0.2rem 0.6rem; border-radius: 999px;
}

.drawer-section { padding: 0.75rem 0.75rem 0; }
.drawer-section-label {
  font-size: 0.6rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted);
  padding: 0 0.5rem 0.5rem;
}
.drawer-item {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.8rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-sub);
  font-size: 0.85rem; font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.drawer-item svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }
.drawer-item:hover, .drawer-item:active { background: var(--card); color: var(--text); }
.drawer-item.active { background: rgba(5,150,105,0.12); color: var(--primary); }
.drawer-item.danger { color: var(--danger); }
.drawer-item.danger:hover { background: rgba(239,68,68,0.1); }
.drawer-divider { height: 1px; background: var(--card-border); margin: 0.5rem 0.75rem; }
.drawer-spacer { flex: 1; }

/* ─── Glass Card ─────────────────────────────────────────── */
.glass-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 4px 24px rgba(0,0,0,0.2), inset 0 1px 1px rgba(255,255,255,0.05);
}
.glass-card-light {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 700; font-size: 0.8rem;
  letter-spacing: 0.04em; text-transform: uppercase;
  transition: all var(--transition);
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 8px 24px rgba(16,185,129,0.3); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: var(--surface-3); color: var(--text-muted); box-shadow: none; }
.btn-ghost { background: var(--card); border: 1px solid var(--card-border); color: var(--text-sub); }
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.15); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }
.btn-full { width: 100%; }

/* ─── Inputs ─────────────────────────────────────────────── */
.inp {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.85rem 1rem;
  font-size: 16px; font-weight: 600; /* 16px prevents iOS zoom */
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.inp::placeholder { color: var(--text-muted); font-weight: 400; }
.inp:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}
.inp-mono { font-family: var(--font-mono); font-size: 0.8rem; }

/* ─── Step Indicator ─────────────────────────────────────── */
.step-dots { display: flex; align-items: center; gap: 0.4rem; }
.step-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--surface-3); transition: all var(--spring); }
.step-dot.active { width: 20px; border-radius: 3px; background: var(--primary); }
.step-dot.done { background: var(--primary); opacity: 0.5; }

/* ─── Chip / Tag ─────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  font-size: 0.65rem; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.chip-green { background: rgba(5,150,105,0.15); color: var(--primary); border: 1px solid rgba(5,150,105,0.25); }
.chip-amber { background: rgba(245,158,11,0.15); color: var(--accent); border: 1px solid rgba(245,158,11,0.25); }
.chip-blue  { background: rgba(59,130,246,0.15); color: var(--info); border: 1px solid rgba(59,130,246,0.25); }
.chip-red   { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }

/* ─── Section Header ─────────────────────────────────────── */
.section-label {
  font-size: 0.65rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* ─── Metric Card ────────────────────────────────────────── */
.metric-card {
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  display: flex; flex-direction: column; gap: 0.4rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15), inset 0 1px 1px rgba(255,255,255,0.05);
}
.metric-value { font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -0.04em; }
.metric-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

/* ─── Splash Screen ──────────────────────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--surface);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.25rem;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
#splash.hidden { opacity: 0; transform: scale(1.05); pointer-events: none; }
.splash-logo {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 60px rgba(5,150,105,0.4);
  animation: pulse-glow 2s infinite;
}
.splash-logo svg { width: 36px; height: 36px; stroke: white; fill: none; stroke-width: 2; }
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 40px rgba(5,150,105,0.4); }
  50% { box-shadow: 0 0 80px rgba(5,150,105,0.7); }
}
.splash-title { font-size: 1.5rem; font-weight: 900; letter-spacing: -0.03em; }
.splash-title em { font-style: normal; color: var(--primary); }
.splash-loader {
  width: 48px; height: 3px;
  background: var(--surface-3);
  border-radius: 2px; overflow: hidden;
  margin-top: 1rem;
}
.splash-loader-bar {
  height: 100%; width: 0;
  background: var(--primary);
  border-radius: 2px;
  animation: load-bar 1.5s ease forwards;
}
@keyframes load-bar { to { width: 100%; } }

/* ─── Map ────────────────────────────────────────────────── */
.leaflet-container { background: var(--surface-3) !important; }
.map-wrap { border-radius: var(--radius-lg); overflow: hidden; position: relative; }
.map-label {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  padding: 2px 6px; font-size: 8px; font-weight: 800;
  font-family: var(--font-mono); text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}

/* ─── Toast ──────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: calc(var(--bottom-bar-h) + 1rem);
  left: 50%; transform: translateX(-50%);
  z-index: 8000; display: flex; flex-direction: column; gap: 0.5rem;
  align-items: center; pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.6rem 1.25rem;
  font-size: 0.78rem; font-weight: 600;
  display: flex; align-items: center; gap: 0.5rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s var(--spring) forwards;
  white-space: nowrap;
}
.toast.success { border-color: rgba(5,150,105,0.4); }
.toast.error { border-color: rgba(239,68,68,0.4); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Animations ─────────────────────────────────────────── */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fade-up 0.4s var(--spring) both; }
.fade-up-1 { animation-delay: 0.05s; }
.fade-up-2 { animation-delay: 0.1s; }
.fade-up-3 { animation-delay: 0.15s; }
.fade-up-4 { animation-delay: 0.2s; }

/* ─── Screen-specific shared ─────────────────────────────── */
.screen-header {
  padding: 1.25rem 1.25rem 0.75rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.screen-title { font-size: 1.4rem; font-weight: 900; letter-spacing: -0.03em; }
.screen-sub { font-size: 0.78rem; color: var(--text-sub); font-weight: 500; }
.screen-body { padding: 0 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 1rem; }

/* ─── PIN Input ──────────────────────────────────────────── */
.pin-display {
  display: flex; gap: 0.5rem; justify-content: center;
  margin: 1rem 0;
}
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--card-border);
  transition: all var(--spring);
}
.pin-dot.filled { background: var(--primary); border-color: var(--primary); box-shadow: 0 0 10px rgba(5,150,105,0.5); }
.pin-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem 1.5rem;
  max-width: 280px; margin: 1rem auto; justify-items: center;
}
.pin-key {
  width: 72px; height: 72px; border-radius: 50%;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  font-size: 1.75rem; font-weight: 400; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s cubic-bezier(0.32, 0.72, 0, 1);
  backdrop-filter: blur(12px);
}
.pin-key:active { transform: scale(0.9); background: rgba(255,255,255,0.2); }
.pin-key.action { background: rgba(255,255,255,0.04); color: var(--text); }
.pin-key.empty { background: transparent; border: none; }
.pin-key.delete { background: transparent; border: none; color: var(--text); }

/* ─── Scrollbar global ───────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }

/* ─── Material Symbols ───────────────────────────────────── */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip .material-symbols-outlined,
.btn .material-symbols-outlined,
.drawer-badge .material-symbols-outlined { font-size: inherit; }
.toast-icon { display: inline-flex; align-items: center; }
.toast-icon .material-symbols-outlined { font-size: 18px; }
