/* ─────────────────────────────────────────────
   Cascade H2O shared design tokens + primitives.
   Light theme matching the Cascade H2O brand:
     navy primary, orange accent, blue secondary, on white.
   Variable names kept stable so existing styles continue to work;
   values are remapped to the new palette.
   ───────────────────────────────────────────── */

:root {
  /* Brand stays the same in both themes. */
  --navy:        #1B3D6B;
  --navy-deep:   #122B4F;
  --orange:      #E8841C;
  --orange-soft: #FFF3E6;
  --blue:        #2A6FB5;
  --blue-soft:   #E8F1FB;

  --danger:      #DC2626;
  --success:     #16A34A;
  --water:       var(--blue);
  --warning:     var(--orange);

  --status-active:   var(--blue);
  --status-prospect: var(--orange);
  --status-inactive: var(--dim);
  --status-dead:     var(--danger);

  /* Light theme defaults (kept on legacy var names so existing styles work). */
  --obsidian:    #FFFFFF;     /* page background */
  --charcoal:    #F7F9FC;     /* card / header surface */
  --gunmetal:    #E2E8F0;     /* hairline border */
  --ivory:       #0F172A;     /* primary text */
  --champagne:   var(--navy); /* headings */
  --gold:        var(--navy); /* primary action color */
  --dim:         #64748B;     /* muted text */
  --on-primary:  #FFFFFF;     /* text on a primary (gold) button */
  --shadow-card: 0 4px 14px rgba(15, 23, 42, 0.10);
  --map-bg:      #F2EEE8;     /* tile loading background */
}

[data-theme="dark"] {
  --obsidian:    #0A1220;
  --charcoal:    #0F1B2D;
  --gunmetal:    rgba(255, 255, 255, 0.10);
  --ivory:       #F5F7FA;
  --champagne:   #F5F7FA;
  --gold:        var(--navy); /* primary CTA stays navy in dark too */
  --dim:         #8896AB;
  --on-primary:  #FFFFFF;
  --shadow-card: 0 6px 22px rgba(0, 0, 0, 0.45);
  --map-bg:      #0A1220;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  background: var(--obsidian);
  color: var(--ivory);
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 300;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--champagne); text-decoration: none; }

button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase;
  border: 1px solid var(--gunmetal);
  color: var(--ivory);
  background: var(--charcoal);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--gold); }
.btn--primary { background: var(--gold); color: var(--on-primary); border-color: var(--gold); }
.btn--primary:hover { background: var(--navy-deep); border-color: var(--navy-deep); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--danger); border-color: var(--danger); }

.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  background: var(--charcoal);
  border: 1px solid var(--gunmetal);
  color: var(--ivory);
  border-radius: 6px;
  font: inherit;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--gold); }

.label {
  display: block;
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 6px;
}

.pill {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  background: var(--charcoal);
  border: 1px solid var(--gunmetal);
  color: var(--dim);
}
.pill--active   { color: var(--blue);    border-color: var(--blue); }
.pill--prospect { color: var(--orange);  border-color: var(--orange); }
.pill--inactive { color: var(--dim);     border-color: var(--gunmetal); }
.pill--dead     { color: var(--danger);  border-color: var(--danger); }
.pill--sent     { color: var(--blue);    border-color: var(--blue); }
.pill--signed   { color: var(--success); border-color: var(--success); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--gunmetal);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* TOAST */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 80px);
  background: var(--charcoal);
  border: 1px solid var(--gunmetal);
  color: var(--ivory);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 2000;
  transition: transform 0.2s ease;
  max-width: calc(100vw - 32px);
}
.toast[data-kind="error"] { border-color: var(--danger); color: var(--danger); }
.toast[data-kind="success"] { border-color: var(--success); color: var(--success); }
.toast--show { transform: translate(-50%, 0); }

/* SHEET (bottom on mobile, side on desktop) */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 1500;
}
.sheet {
  width: 100%;
  max-height: 85vh;
  background: var(--charcoal);
  border-top: 1px solid var(--gunmetal);
  border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  animation: sheet-up 0.18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet__handle {
  width: 40px; height: 4px; background: var(--gunmetal);
  border-radius: 2px; margin: 8px auto 0;
}
.sheet__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
}
.sheet__title { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 400; color: var(--champagne); }
.sheet__close { font-size: 24px; color: var(--dim); padding: 0 4px; }
.sheet__body { padding: 4px 18px 18px; overflow-y: auto; }
.sheet__actions { padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0)); display: flex; gap: 8px; border-top: 1px solid #1f1f1f; }
.sheet__actions:empty { display: none; }
.sheet__actions .btn { flex: 1; }

@media (min-width: 900px) {
  .sheet-backdrop { align-items: stretch; justify-content: flex-end; }
  .sheet {
    width: 460px; max-width: 100%; max-height: none; height: 100vh;
    border-radius: 0; border-left: 1px solid var(--gunmetal); border-top: 0;
  }
  .sheet__handle { display: none; }
}

/* HEADER (shared between /field/ and /hq/, layout differs slightly) */
.app-header {
  background: var(--charcoal);
  border-bottom: 1px solid var(--gunmetal);
  padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 1000;
}
.app-header__brand {
  display: flex; align-items: center; gap: 12px;
}
.app-header__mark {
  width: 32px; height: 32px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Cormorant Garamond', serif;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 1px;
}
.app-header__title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 17px; font-weight: 400;
  color: var(--champagne); letter-spacing: 2px;
}
.app-header__sub {
  font-size: 9px; color: var(--dim);
  letter-spacing: 3px; text-transform: uppercase;
}
.online-pill {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px;
  background: var(--obsidian); color: var(--dim);
  border: 1px solid var(--gunmetal);
}
.online-pill[data-state="offline"] { color: var(--warning); border-color: var(--warning); }

/* AUTH SCREEN (shared) */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--charcoal);
  border: 1px solid var(--gunmetal);
  border-radius: 12px;
  padding: 28px 22px;
}
.auth-card h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 24px; font-weight: 400;
  color: var(--champagne); letter-spacing: 2px;
  margin-bottom: 6px;
}
.auth-card .auth-sub {
  font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--dim); margin-bottom: 22px;
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-toggle {
  margin-top: 14px; font-size: 12px; color: var(--dim); text-align: center;
}
.auth-toggle button { color: var(--gold); }

/* MISC */
.muted { color: var(--dim); }
.section { padding: 16px 18px; border-bottom: 1px solid var(--gunmetal); }
.section h3 {
  font-size: 10px; letter-spacing: 3px; text-transform: uppercase;
  color: var(--dim); margin-bottom: 10px;
}
.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 6px; }
.grow { flex: 1; }

/* Theme toggle (sun/moon icon button) */
.theme-toggle {
  width: 36px; height: 36px;
  border: 1px solid var(--gunmetal);
  border-radius: 50%;
  background: transparent;
  color: var(--dim);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  flex-shrink: 0;
}
.theme-toggle:hover {
  color: var(--orange);
  border-color: var(--orange);
}
.theme-toggle svg { display: block; }

/* Dark-mode tweaks for Leaflet's UI chrome (zoom buttons, attribution, controls)
   so they don't render as a stark white panel in the middle of a dark map. */
[data-theme="dark"] .leaflet-bar,
[data-theme="dark"] .leaflet-control-layers {
  background: var(--charcoal) !important;
  border: 1px solid var(--gunmetal) !important;
  color: var(--ivory) !important;
}
[data-theme="dark"] .leaflet-bar a {
  background: var(--charcoal) !important;
  color: var(--ivory) !important;
  border-bottom-color: var(--gunmetal) !important;
}
[data-theme="dark"] .leaflet-bar a:hover {
  background: var(--obsidian) !important;
}
[data-theme="dark"] .leaflet-control-layers label {
  color: var(--ivory) !important;
}
[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(15, 27, 45, 0.85) !important;
  color: var(--dim) !important;
}
[data-theme="dark"] .leaflet-control-attribution a { color: var(--orange) !important; }
[data-theme="dark"] .leaflet-container { background: var(--map-bg); }
