/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap');

:root {
  /* GGYC Brand Colors */
  --ggyc-blue: #036acb;
  --ggyc-blue-light: #629ece;
  --ggyc-blue-pale: #b8d4e9;
  --ggyc-red: #d0262b;

  /* App Theme */
  --bg: #060d1a;
  --bg2: #0b1729;
  --surface: rgba(3, 106, 203, 0.07);
  --surface-border: rgba(3, 106, 203, 0.2);
  --text: #e8f0fb;
  --text-dim: rgba(232, 240, 251, 0.5);
  --cyan: var(--ggyc-blue);
  --cyan-dim: rgba(3, 106, 203, 0.35);
  --orange: var(--ggyc-red);
  --orange-dim: rgba(208, 38, 43, 0.15);
  --red: var(--ggyc-red);
  --green: #2ecc71;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 0; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ─── Loading Screen ────────────────────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 100;
}

.loading-wave {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 32px;
}

.loading-wave span {
  width: 5px;
  background: var(--cyan);
  border-radius: 3px;
  animation: wave-bar 1.2s ease-in-out infinite;
}

.loading-wave span:nth-child(1) { animation-delay: 0s; }
.loading-wave span:nth-child(2) { animation-delay: 0.15s; }
.loading-wave span:nth-child(3) { animation-delay: 0.3s; }
.loading-wave span:nth-child(4) { animation-delay: 0.45s; }
.loading-wave span:nth-child(5) { animation-delay: 0.6s; }

@keyframes wave-bar {
  0%, 100% { height: 8px; opacity: 0.4; }
  50% { height: 28px; opacity: 1; }
}

.loading-label {
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ─── Error Screen ──────────────────────────────────────────────────────── */
#error-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  z-index: 100;
  text-align: center;
}

#error-screen .error-icon { font-size: 48px; }
#error-screen .error-msg { font-size: 15px; color: var(--text-dim); line-height: 1.5; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 100px;
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--cyan); color: #000; }
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--surface-border);
  color: var(--text);
}
.btn-orange { background: var(--orange); color: #000; }

/* ─── Main Layout ───────────────────────────────────────────────────────── */
#main-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 24px;
}

/* ─── GGYC Brand Bar ────────────────────────────────────────────────────── */
.ggyc-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 8px;
  border-bottom: 1px solid rgba(3, 106, 203, 0.2);
}

.ggyc-pennant {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 6px;
}

.ggyc-wordmark {
  flex: 1;
}

.ggyc-wordmark-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ggyc-blue);
  line-height: 1;
}

.ggyc-wordmark-sub {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  gap: 12px;
}

.station-info { flex: 1; min-width: 0; }
.station-name {
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.station-id {
  font-size: 11px;
  color: var(--ggyc-blue-light);
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--surface-border);
  color: var(--cyan);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.icon-btn:active { background: rgba(255,255,255,0.1); }

/* ─── King Tide Alert ───────────────────────────────────────────────────── */
.king-tide-alert {
  margin: 0 16px 12px;
  background: var(--orange-dim);
  border: 1px solid rgba(255,140,0,0.3);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.king-tide-alert .alert-icon { font-size: 22px; flex-shrink: 0; }
.king-tide-alert .alert-content { flex: 1; }
.king-tide-alert .alert-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--orange);
  margin-bottom: 4px;
}
.king-tide-alert .alert-body { font-size: 13px; color: var(--text-dim); line-height: 1.4; }
.king-tide-alert .alert-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 0; line-height: 1;
}

/* ─── Slack Water Indicator ─────────────────────────────────────────────── */
.slack-water {
  margin: 0 16px 12px;
  background: rgba(0,212,255,0.06);
  border: 1px solid var(--cyan-dim);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.slack-pulse {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--cyan);
  flex-shrink: 0;
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--cyan-dim); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.slack-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cyan);
}
.slack-sub { font-size: 11px; color: var(--text-dim); }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  margin: 0 16px 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.metric { text-align: center; }
.metric-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.metric-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.metric-value.cyan { color: var(--cyan); }
.metric-value.rising { color: #2ecc71; }
.metric-value.falling { color: var(--ggyc-blue-light); }
.metric-unit {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
}

/* Sun/Moon card */
.sunmoon-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sunmoon-item { text-align: center; }
.sunmoon-icon { font-size: 20px; margin-bottom: 4px; }
.sunmoon-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.sunmoon-value { font-size: 15px; font-weight: 600; }

/* ─── Graph Section ─────────────────────────────────────────────────────── */
.graph-section { margin-bottom: 12px; }
.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 8px;
}
.graph-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.now-btn {
  background: rgba(255,140,0,0.15);
  border: 1px solid rgba(255,140,0,0.3);
  color: var(--orange);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 100px;
  cursor: pointer;
}

#graph-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  scroll-behavior: smooth;
}
#graph-scroll:active { cursor: grabbing; }
#graph-scroll::-webkit-scrollbar { height: 2px; }

#graph-canvas { display: block; }

/* ─── King Tides List ───────────────────────────────────────────────────── */
.king-tides-section {
  margin: 0 16px 12px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.expand-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

.king-tide-item {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.king-tide-item .kt-icon { font-size: 22px; }
.king-tide-item .kt-info { flex: 1; }
.king-tide-item .kt-date { font-size: 14px; font-weight: 600; }
.king-tide-item .kt-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.king-tide-item .kt-badge {
  background: var(--orange-dim);
  border: 1px solid rgba(255,140,0,0.3);
  color: var(--orange);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 100px;
}
.king-tide-item.past { opacity: 0.5; }

/* ─── Station Picker ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
}

.modal-sheet {
  background: #111827;
  border-radius: 20px 20px 0 0;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

.modal-handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 12px auto 8px;
}
.modal-header {
  display: flex;
  align-items: center;
  padding: 8px 20px 12px;
  gap: 12px;
}
.modal-title { font-size: 18px; font-weight: 700; flex: 1; }
.modal-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--text);
  font-size: 16px;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

.search-bar {
  margin: 0 16px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
}
.search-bar input::placeholder { color: var(--text-dim); }
.search-bar .search-icon { color: var(--text-dim); font-size: 16px; }

.station-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.station-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  gap: 12px;
  transition: background 0.15s;
}
.station-item:active { background: rgba(255,255,255,0.06); }
.station-item.selected { background: rgba(0,212,255,0.08); }

.station-item .si-icon { font-size: 18px; color: var(--text-dim); }
.station-item.selected .si-icon { color: var(--cyan); }
.station-item .si-info { flex: 1; }
.station-item .si-name { font-size: 14px; font-weight: 500; }
.station-item.selected .si-name { color: var(--cyan); }
.station-item .si-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.station-item .si-check { color: var(--cyan); font-size: 16px; }
.station-item .si-arrow { color: var(--text-dim); font-size: 20px; line-height: 1; }

.station-item-locate { background: rgba(3, 106, 203, 0.07); }
.station-item-locate:active { background: rgba(3, 106, 203, 0.15); }
.station-item-locate .si-locate { font-size: 18px; }
.station-item-locate .si-name { color: var(--ggyc-blue); font-weight: 600; }

.picker-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 0;
}

.picker-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 14px;
  gap: 12px;
}

/* ─── Install Prompts ───────────────────────────────────────────────────── */
.install-banner {
  margin: 0 16px 12px;
  background: rgba(0,212,255,0.06);
  border: 1px solid var(--cyan-dim);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.install-banner .ib-icon { font-size: 22px; }
.install-banner .ib-content { flex: 1; }
.install-banner .ib-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cyan);
  margin-bottom: 4px;
}
.install-banner .ib-body { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.install-banner .ib-body strong { color: var(--text); }
.install-banner .ib-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 0; flex-shrink: 0;
}

.install-btn-row {
  padding: 0 16px 8px;
  display: flex;
  gap: 10px;
}

/* ─── Utility ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.divider { height: 1px; background: var(--surface-border); margin: 4px 16px; }
