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

:root {
  --bg: #0a1628;
  --surface: #122040;
  --surface2: #1a2d54;
  --accent: #00b4d8;
  --accent2: #0077b6;
  --text: #e0e6ed;
  --text-dim: #8899aa;
  --danger: #e63946;
  --success: #06d6a0;
  --warning: #ffd166;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(70px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--accent2), var(--surface));
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 1.25rem; font-weight: 700; }
.header .logo { font-size: 1.5rem; }

/* Bottom Nav */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 4px 8px;
  font-size: 0.65rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: color 0.2s;
}
.nav button .icon { font-size: 1.3rem; }
.nav button.active { color: var(--accent); }

/* Pages */
.page { display: none; padding: 16px; max-width: 600px; margin: 0 auto; }
.page.active { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 {
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.stat-card .label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-group select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238899aa'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* Section Headers inside forms */
.section-label {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--surface2);
}
.section-label:first-child { margin-top: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-small { padding: 6px 12px; font-size: 0.75rem; width: auto; }
.btn-group { display: flex; gap: 8px; margin-top: 16px; }
.btn-group .btn { flex: 1; }

/* FAB */
.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 180, 216, 0.4);
  cursor: pointer;
  z-index: 90;
  transition: transform 0.2s;
}
.fab:active { transform: scale(0.9); }

/* Dive List */
.dive-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s;
}
.dive-item:active { background: var(--surface2); }
.dive-item .dive-main { flex: 1; min-width: 0; }
.dive-item .dive-num {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.85rem;
}
.dive-item .dive-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dive-item .dive-site {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dive-item .dive-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}
.dive-item .dive-depth {
  text-align: right;
  flex-shrink: 0;
  margin-left: 12px;
}
.dive-item .dive-depth .value { font-size: 1.1rem; font-weight: 700; }
.dive-item .dive-depth .unit { font-size: 0.65rem; color: var(--text-dim); }

/* Detail View */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.detail-header .back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 0.9rem;
}
.detail-row .label { color: var(--text-dim); }
.detail-row .value { font-weight: 600; text-align: right; max-width: 60%; }

/* Species list in detail */
.species-tag {
  display: inline-block;
  background: var(--surface2);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.75rem;
  margin: 3px 3px 3px 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--success);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 600px;
  max-height: 80dvh;
  overflow-y: auto;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 16px; }

/* Search */
.search-bar {
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
  margin-bottom: 12px;
  font-family: inherit;
}
.search-bar:focus { outline: none; border-color: var(--accent); }

/* Sort bar */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.sort-btn {
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-dim);
  padding: 5px 10px;
  font-size: 0.72rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.sort-btn.active {
  background: var(--accent);
  color: var(--bg);
}

/* Export bar */
.export-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* Chart bars */
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.bar-label { width: 40px; text-align: right; color: var(--text-dim); flex-shrink: 0; }
.bar-track { flex: 1; height: 20px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 4px; transition: width 0.5s ease; }
.bar-value { width: 30px; font-size: 0.75rem; color: var(--text-dim); flex-shrink: 0; }

/* Checkbox */
.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkbox-wrap input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Dive Map */
#dive-map {
  height: 50dvh;
  min-height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 1;
}
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4) !important;
}
.leaflet-popup-tip { background: var(--surface) !important; }
.leaflet-popup-content { margin: 10px 14px !important; font-size: 0.85rem !important; }
.leaflet-popup-content .popup-title { font-weight: 700; font-size: 0.95rem; color: var(--accent); margin-bottom: 4px; }
.leaflet-popup-content .popup-meta { color: var(--text-dim); font-size: 0.75rem; }
.leaflet-popup-content .popup-stats { margin-top: 6px; display: flex; gap: 12px; }
.leaflet-popup-content .popup-stat { text-align: center; }
.leaflet-popup-content .popup-stat .val { font-weight: 700; font-size: 1rem; }
.leaflet-popup-content .popup-stat .lbl { font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; }
.map-site-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 0.85rem;
  cursor: pointer;
}
.map-site-item:last-child { border-bottom: none; }
.map-site-item:active { opacity: 0.7; }
.map-site-item .site-name { font-weight: 600; }
.map-site-item .site-count { color: var(--accent); font-weight: 700; font-size: 0.8rem; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }

/* Auth page */
#page-auth { align-items: flex-start; justify-content: center; min-height: 80dvh; }
#page-auth.active { display: flex; }
.auth-card { max-width: 380px; width: 100%; }
.auth-card h2 { color: var(--accent); }

/* Buddy badge */
.buddy-badge {
  font-size: 0.55rem;
  background: var(--warning);
  color: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 700;
  vertical-align: middle;
}

/* Species catalog */
.species-card { transition: background 0.2s; }
.species-card:active { background: var(--surface2); }

/* Responsive tweaks */
@media (min-width: 500px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
