/* ═══════════════════════════════════════════════════════════════════════════
   PoolPilot App Styles — matches landing page design tokens
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --blue-deep: #0a1628;
  --blue-mid: #0f2847;
  --blue-light: #132d4f;
  --cyan: #00d4ff;
  --cyan-soft: #7aecff;
  --cyan-dim: rgba(0, 212, 255, 0.15);
  --white: #f0f6ff;
  --gray: #8ba3c7;
  --gray-dim: #4a6282;
  --surface: rgba(15, 40, 71, 0.6);
  --surface-solid: #0f2847;
  --border: rgba(0, 212, 255, 0.08);
  --border-hover: rgba(0, 212, 255, 0.25);
  --danger: #ff4757;
  --success: #2ed573;
  --warning: #ffa502;
  --topbar-h: 56px;
  --bottomnav-h: 64px;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--blue-deep);
  color: var(--white);
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; }

/* ─── Top Bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(10, 22, 40, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
}

.topbar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--cyan);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.topbar-logo span { color: var(--white); }

.topbar-title {
  flex: 1;
  text-align: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray);
}

.topbar-spacer { width: 80px; }

/* ─── Bottom Nav ──────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: rgba(10, 22, 40, 0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--gray-dim);
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.2s;
  padding: 6px 12px;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active, .nav-item:hover { color: var(--cyan); }
.nav-item svg { transition: transform 0.2s; }
.nav-item.active svg { transform: scale(1.1); }

/* ─── Main Content ────────────────────────────────────────────────────────── */
#app-content {
  padding-top: var(--topbar-h);
  padding-bottom: calc(var(--bottomnav-h) + 16px);
  min-height: 100vh;
}

.page { padding: 20px; max-width: 800px; margin: 0 auto; }

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-hover); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── Stat Grid ───────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--cyan);
  line-height: 1;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--gray);
  margin-top: 4px;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--cyan);
  color: var(--blue-deep);
}
.btn-primary:hover { background: var(--cyan-soft); }
.btn-secondary {
  background: var(--cyan-dim);
  color: var(--cyan);
}
.btn-secondary:hover { background: rgba(0, 212, 255, 0.25); }
.btn-danger {
  background: rgba(255, 71, 87, 0.15);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(255, 71, 87, 0.25); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  background: rgba(15, 40, 71, 0.8);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--white);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--cyan);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--gray-dim); }
.form-select { cursor: pointer; }
.form-select option { background: var(--blue-mid); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-hint { font-size: 0.75rem; color: var(--gray-dim); margin-top: 4px; }

/* ─── Customer List ───────────────────────────────────────────────────────── */
.customer-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.customer-item:hover { border-color: var(--border-hover); }
.customer-item:active { transform: scale(0.99); }
.customer-avatar {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--cyan-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--cyan);
  flex-shrink: 0;
}
.customer-info { flex: 1; min-width: 0; }
.customer-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.customer-meta {
  font-size: 0.8rem;
  color: var(--gray);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.customer-badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
  flex-shrink: 0;
}
.badge-active { background: rgba(46, 213, 115, 0.15); color: var(--success); }
.badge-inactive { background: rgba(255, 71, 87, 0.15); color: var(--danger); }
.badge-chlorine { background: rgba(0, 212, 255, 0.12); color: var(--cyan); }
.badge-saltwater { background: rgba(46, 213, 115, 0.12); color: var(--success); }

/* ─── Route ───────────────────────────────────────────────────────────────── */
.day-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}
.day-tab {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--gray);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.day-tab.active {
  background: var(--cyan);
  color: var(--blue-deep);
  border-color: var(--cyan);
}
.day-tab .count {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.7;
}

.route-stop {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.route-stop:last-child { border-bottom: none; }
.stop-number {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--cyan-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--cyan);
  flex-shrink: 0;
}
.stop-info { flex: 1; }
.stop-name { font-weight: 600; font-size: 0.9rem; }
.stop-address { font-size: 0.8rem; color: var(--gray); margin-top: 2px; }
.stop-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ─── Map ─────────────────────────────────────────────────────────────────── */
.map-container {
  width: 100%;
  height: 280px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.map-container .leaflet-container {
  height: 100%;
  background: var(--blue-mid);
}

/* ─── Service Log ─────────────────────────────────────────────────────────── */
.reading-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.reading-card {
  background: rgba(15, 40, 71, 0.5);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.reading-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--cyan);
}
.reading-label { font-size: 0.75rem; color: var(--gray); margin-top: 2px; }
.reading-status { font-size: 0.7rem; font-weight: 600; margin-top: 2px; }
.reading-ok { color: var(--success); }
.reading-warn { color: var(--warning); }
.reading-bad { color: var(--danger); }

/* ─── Log List ────────────────────────────────────────────────────────────── */
.log-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.log-customer { font-weight: 600; font-size: 0.9rem; }
.log-date { font-size: 0.78rem; color: var(--gray); }
.log-readings {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.log-reading {
  font-size: 0.78rem;
  color: var(--gray);
}
.log-reading strong { color: var(--white); }

/* ─── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface-solid);
  border: 1px solid var(--border-hover);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--white);
  backdrop-filter: blur(12px);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  pointer-events: auto;
  text-align: center;
  max-width: 90vw;
}
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ─── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 6px;
}
.empty-desc { font-size: 0.85rem; margin-bottom: 20px; }

/* ─── Loading ─────────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Back button ─────────────────────────────────────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--cyan);
  cursor: pointer;
  margin-bottom: 16px;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}
.back-btn:hover { color: var(--cyan-soft); }

/* ─── Modal / Overlay ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-content {
  background: var(--blue-mid);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px 20px;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--gray);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
}

/* ─── Section header ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.section-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .reading-group { grid-template-columns: repeat(3, 1fr); }
  .map-container { height: 350px; }
}
