/*
 * TropicalInfo Design System — Tokens
 * ====================================
 * Source of truth for colors, spacing, typography, and shadows used by the
 * redesigned UI. Page-specific stylesheets (app-shell.css, reader.css)
 * reference these tokens; never hardcode color values in those files.
 *
 * Tokens follow a "semantic name → raw value" pattern so we can re-skin
 * (e.g., switch to a light mode) by changing this file alone.
 */

:root {
  color-scheme: dark;  /* tells browsers to render native form elements, scrollbars, etc. in dark mode */

  /* --- Surface / background colors (dark theme baseline) --- */
  --bg:           #0d1117;   /* page background */
  --surface-1:    #161b22;   /* cards, top bar, rail */
  --surface-2:    #1c2230;   /* hover state, slightly raised */
  --surface-3:    #232a39;   /* pressed / active surface */

  /* --- Borders --- */
  --border:       #30363d;   /* primary borders (dividers, card edges) */
  --border-soft:  #21262d;   /* subtle dividers within cards */

  /* --- Text --- */
  --text:         #e6edf3;   /* primary text */
  --text-2:       #9da7b3;   /* secondary / muted text */
  --text-muted:   #6e7681;   /* most muted: labels, hints */

  /* --- Brand / accent --- */
  --accent:       #2f81f7;   /* primary brand accent (links, focus, active) */
  --accent-soft:  rgba(47,129,247,0.15);  /* accent background tint */

  /* --- Semantic colors --- */
  --warn:         #d29922;   /* warning yellow (caution alerts) */
  --danger:       #f85149;   /* hurricane red, error state */
  --success:      #3fb950;   /* success green */
  --purple:       #a371f7;   /* premium / pro tier */

  /* --- Typography --- */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --fs-xs:    11px;
  --fs-sm:    12px;
  --fs-base:  14px;
  --fs-md:    16px;
  --fs-lg:    18px;
  --fs-xl:    22px;
  --fs-2xl:   28px;
  --lh-tight: 1.3;
  --lh-base:  1.5;
  --lh-loose: 1.7;

  /* --- Spacing scale (4px grid) --- */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;
  --space-7:  48px;

  /* --- Border radii --- */
  --radius-sm:  4px;
  --radius:     6px;
  --radius-md:  8px;
  --radius-lg:  10px;
  --radius-xl:  12px;
  --radius-pill: 9999px;

  /* --- Shadows --- */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow:    0 2px 6px rgba(0,0,0,0.25);
  --shadow-lg: 0 6px 24px rgba(0,0,0,0.5);

  /* --- Z-layers --- */
  --z-rail:    50;
  --z-topbar:  60;
  --z-tooltip: 100;
  --z-modal:   1000;

  /* --- Layout constants --- */
  --topbar-height: 64px;     /* needs to hold the TropicalInfo wordmark legibly */
  --rail-width:    240px;    /* collapsed single-rail width (Option B from mockup review) */
  --rail-icons-height: 44px; /* horizontal strip at top of rail showing primary icons */

  /* --- Bootstrap variable overrides (dark theme) --- */
  /* Map Bootstrap's own CSS vars to our palette so Bootstrap components and
     any template inline styles using --bs-* automatically get dark values. */
  --bs-body-bg:                  #0d1117;
  --bs-body-bg-rgb:              13, 17, 23;
  --bs-body-color:               #e6edf3;
  --bs-body-color-rgb:           230, 237, 243;
  --bs-secondary-bg:             #1c2230;
  --bs-tertiary-bg:              #232a39;
  --bs-card-bg:                  #161b22;
  --bs-card-border-color:        #30363d;
  --bs-border-color:             #30363d;
  --bs-border-color-translucent: rgba(48, 54, 61, 0.175);
  --bs-emphasis-color:           #e6edf3;
  --bs-secondary-color:          #9da7b3;
  --bs-tertiary-color:           #6e7681;
  --bs-form-control-bg:          #1c2230;
  --bs-form-control-border-color:#30363d;
  --bs-input-bg:                 #1c2230;
  --bs-input-border-color:       #30363d;
  --bs-input-color:              #e6edf3;
  --bs-modal-bg:                 #161b22;
  --bs-modal-header-border-color:#30363d;
  --bs-dropdown-bg:              #161b22;
  --bs-dropdown-border-color:    #30363d;
  --bs-dropdown-link-color:      #e6edf3;
  --bs-dropdown-link-hover-bg:   #1c2230;
  --bs-list-group-bg:            #161b22;
  --bs-list-group-border-color:  #30363d;
  --bs-table-bg:                 transparent;
  --bs-table-border-color:       #30363d;
  --bs-table-striped-bg:         rgba(48, 54, 61, 0.2);
}

/* ---------- Base reset / element defaults ---------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
}

img { max-width: 100%; }

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- Hurricane icon utility ---------- */
/* Behaves like an icon-font glyph: scales with font-size, inherits color. */
.hurricane-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  fill: currentColor;
}

/* ---------- Common utility classes ---------- */

.muted { color: var(--text-muted); }
.text-2 { color: var(--text-2); }
.small { font-size: var(--fs-sm); }
.center { text-align: center; }

.pill {
  display: inline-block;
  font-size: var(--fs-xs);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.pill-pro     { background: rgba(163,113,247,0.18); color: var(--purple); }
.pill-danger  { background: rgba(248,81,73,0.18);  color: var(--danger); }
.pill-warn    { background: rgba(210,153,34,0.18); color: var(--warn); }
.pill-success { background: rgba(63,185,80,0.18);  color: var(--success); }
.pill-accent  { background: var(--accent-soft);    color: var(--accent); }

.badge-cat {
  font-size: var(--fs-xs);
  padding: 3px 9px;
  border-radius: 12px;
  color: white;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-cat.cat-5 { background: #7e22ce; }
.badge-cat.cat-4 { background: #dc2626; }
.badge-cat.cat-3 { background: #ea580c; }
.badge-cat.cat-2 { background: #d97706; }
.badge-cat.cat-1 { background: #ca8a04; }
.badge-cat.cat-ts { background: #0284c7; }
.badge-cat.cat-td { background: #64748b; }

/* ---------- Form controls (used by auth shell + any inline form) ---------- */

.form-group { margin-bottom: var(--space-4); }

.form-label {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-2);
  margin-bottom: var(--space-1);
  font-weight: 500;
}

.form-control {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px var(--space-3);
  border-radius: var(--radius);
  font-size: var(--fs-base);
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.form-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-help {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--fs-sm);
  color: var(--danger);
  margin-top: var(--space-1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px var(--space-4);
  border-radius: var(--radius);
  font-size: var(--fs-base);
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: #4493f8; border-color: #4493f8; color: white; text-decoration: none; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-3); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.btn-block { width: 100%; }
.btn-lg { padding: 12px var(--space-5); font-size: var(--fs-md); }

/* Provider sign-in button (Google etc.) */
.btn-provider {
  background: white;
  color: #1f2937;
  border-color: var(--border);
}
.btn-provider:hover { background: #f3f4f6; color: #1f2937; text-decoration: none; }

/* Alerts (flash messages) */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  font-size: var(--fs-sm);
  border: 1px solid transparent;
}
.alert-warning { background: rgba(210,153,34,0.10); color: var(--warn); border-color: rgba(210,153,34,0.3); }
.alert-error   { background: rgba(248,81,73,0.10);  color: var(--danger); border-color: rgba(248,81,73,0.3); }
.alert-success { background: rgba(63,185,80,0.10);  color: var(--success); border-color: rgba(63,185,80,0.3); }
.alert-info    { background: var(--accent-soft);    color: var(--accent); border-color: rgba(47,129,247,0.3); }

/* Divider with center label ("or") */
.divider-or {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.divider-or::before,
.divider-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-soft);
}

/* ---------- Shared mobile primary-nav drawer ---------- */
/* Hamburger + slide-in labeled menu, used by the reader shell (which has no
   rail). Hidden on desktop; on phones the unlabeled icon strip is hidden and
   this labeled drawer becomes the main menu. Toggled via body.mnav-open. */
.mnav-toggle, .mnav-backdrop, .mnav-drawer { display: none; }
@media (max-width: 899px) {
  .mnav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--text);
    font-size: 22px; padding: 4px 8px; cursor: pointer; line-height: 1;
  }
  .mnav-backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); opacity: 0; pointer-events: none;
    transition: opacity 0.2s; z-index: calc(var(--z-modal) + 100);  /* above Leaflet (z 1000) */
  }
  body.mnav-open .mnav-backdrop { opacity: 1; pointer-events: auto; }
  .mnav-drawer {
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(84vw, 320px);
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: calc(var(--z-modal) + 101);  /* above Leaflet (z 1000) + its own backdrop */
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: var(--space-5);
  }
  body.mnav-open .mnav-drawer { transform: translateX(0); }
  .mnav-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-4); border-bottom: 1px solid var(--border);
    font-weight: 600; color: var(--text);
  }
  .mnav-close { background: transparent; border: none; color: var(--text-2); font-size: 20px; cursor: pointer; line-height: 1; }
  .mnav-item {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 14px var(--space-4); color: var(--text);
    text-decoration: none; font-size: var(--fs-md);
  }
  .mnav-item:hover, .mnav-item.active { background: var(--surface-2); text-decoration: none; }
  .mnav-item.active { color: var(--accent); }
  .mnav-item i, .mnav-item .hurricane-icon { width: 20px; text-align: center; color: var(--text-muted); font-size: 18px; }
  .mnav-item.active i, .mnav-item.active .hurricane-icon { color: var(--accent); fill: var(--accent); }
  .mnav-divider { height: 1px; background: var(--border); margin: var(--space-2) 0; }
}

/* ---------- Key stats grid (shared) ---------- */
/* Generic stat-card grid used by both shells (dashboard/account in the app
   shell; storm-history detail etc. in the reader shell). Lives here — not in
   app-shell.css — so the reader shell, which doesn't load app-shell.css, styles
   it too (otherwise .stat label/value render as raw stacked divs). */
.key-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.stat {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.stat .label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat .value { font-size: var(--fs-xl); font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: var(--fs-sm); color: var(--text-2); margin-top: 2px; }

/* ---------- Content panel (shared) ---------- */
/* Card-style panel used by both shells (app product panels; hurricane-risk on
   the reader shell). Shared here so the reader shell — which doesn't load
   app-shell.css — styles it too. */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-5);
}
.panel-header {
  padding: var(--space-3) 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h2 {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.panel-header .actions {
  display: flex;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: 13px;
}
.panel-header .actions span {
  cursor: pointer;
  padding: 4px var(--space-3);
  border-radius: var(--radius);
}
.panel-header .actions span:hover { background: var(--surface-3); color: var(--text); }
.panel-body { padding: 20px; }

@media (max-width: 899px) {
  .form-check input[type="checkbox"] { width: 20px; height: 20px; }
  .panel-header .actions span { padding: 10px var(--space-3); }
  /* iOS Safari auto-zooms when a focused input's font-size < 16px */
  input, select, textarea { font-size: 16px; }
  /* Touch-friendly button height (~44 px) */
  .btn { padding: 12px var(--space-4); }
  /* Body font nudge for readability on phones (px tokens are independent of html font-size) */
  html { font-size: 15px; }
}

@media (max-width: 480px) {
  /* Terminology definition list: stack dt/dd on tiny phones */
  .term-grid { grid-template-columns: 1fr !important; }
  /* Climatology bar chart: 6 columns (2 rows of 6) on tiny phones */
  .climo-grid { grid-template-columns: repeat(6, 1fr) !important; }
}
