/* SIMS Vendor Tracker — PWA Styles */

:root {
  --bg: #0f1117;
  --bg-card: #1a1d2e;
  --bg-card-hover: #222638;
  --primary: #2a2f45;
  --accent: #4ecdc4;
  --accent-dim: rgba(78, 205, 196, 0.15);
  --text: #e8eaf0;
  --text-muted: #8892a4;
  --success: #4ecdc4;
  --danger: #e05c5c;
  --warning: #f4a261;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────── */
#app-header {
  background: var(--bg-card);
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-brand h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

#status-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.syncing { background: var(--warning); animation: pulse 1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Install Banner ─────────────────────────────────── */
.install-banner {
  background: linear-gradient(135deg, #1a2a3a 0%, #1a1d2e 100%);
  border-bottom: 1px solid rgba(78, 205, 196, 0.2);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.install-banner.hidden { display: none; }

.install-banner-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.btn-install {
  background: var(--accent);
  color: #0f1117;
  border: none;
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

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

.btn-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  width: auto;
}

/* ── Main content ──────────────────────────────────── */
#main-content {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* ── Screens ───────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--primary);
}

/* ── Status Screens (verifying/welcome/error) ──────── */
.status-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  padding: 3rem 1rem;
  min-height: 60vh;
}

.status-screen h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.status-screen p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.status-icon {
  margin-bottom: 0.5rem;
}

.status-icon.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ─────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-group input {
  background: var(--bg);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-group input::placeholder { color: var(--text-muted); opacity: 0.6; }

button {
  background: var(--primary);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--accent);
  color: #0f1117;
}

.btn-danger {
  background: transparent;
  border: 1.5px solid var(--danger);
  color: var(--danger);
}

.error-msg {
  color: var(--danger);
  font-size: 0.82rem;
  text-align: center;
  min-height: 1.2em;
}

/* ── Login features ─────────────────────────────────── */
.login-features {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.25rem 0;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Spinner ────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ── Map Card ──────────────────────────────────────── */
.map-card {
  padding: 0;
  overflow: hidden;
  gap: 0;
}

#map-container {
  height: 200px;
  position: relative;
  background: var(--bg);
}

#map {
  width: 100%;
  height: 100%;
}

#map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.map-overlay-info {
  display: flex;
  border-top: 1px solid var(--primary);
}

.map-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem;
  border-right: 1px solid var(--primary);
}
.map-stat:last-child { border-right: none; }

.map-stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.map-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Status Card ───────────────────────────────────── */
.status-card {
  gap: 0.75rem;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.tracking-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--primary);
  border-radius: 14px;
  transition: 0.3s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: 0.3s;
}

input:checked + .slider { background: var(--accent); }
input:checked + .slider::before {
  transform: translateX(20px);
  background: #fff;
}

#tracking-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 24px;
}

.next-update-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.next-update-row strong { color: var(--text); }

.battery-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.battery-row strong { color: var(--text); }

/* ── Vendor Card ───────────────────────────────────── */
.vendor-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.vendor-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.vendor-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.vendor-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.vendor-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
}

.online-badge {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--success);
  background: rgba(78, 205, 196, 0.1);
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
}

.online-badge.offline { color: var(--text-muted); background: var(--primary); }

.vendor-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-top: 0.5rem;
  border-top: 1px solid var(--primary);
}

/* ── Sync Card ──────────────────────────────────────── */
.sync-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sync-title {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.sync-badge {
  font-size: 0.72rem;
  background: var(--warning);
  color: #0f1117;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-weight: 700;
}

.sync-badge.clear { background: var(--accent); }

/* ── Permission Card ───────────────────────────────── */
.permission-card {
  border-color: var(--warning);
  background: linear-gradient(135deg, rgba(244,162,97,0.08) 0%, var(--bg-card) 100%);
  text-align: center;
  gap: 0.75rem;
}

.permission-icon { display: flex; justify-content: center; }

.permission-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--warning);
}

.permission-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Leaflet overrides ──────────────────────────────── */
.leaflet-control-attribution { display: none; }
.leaflet-control-zoom { display: none; }
.leaflet-container {
  background: #1a1d2e !important;
  font-family: inherit !important;
}

/* Custom marker */
.vendor-marker {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
