/* divingOS — shared design system. Every module's views reuse these
   tokens/components rather than introducing new one-off colors/spacing.
   Palette: deep-ocean editorial — a seafoam-tinted ground, a deep-water
   teal as the one primary accent, coral as its reef counterpoint used
   sparingly. Fraunces carries headings (an editorial, field-journal
   character); Source Sans 3 carries everything else; JetBrains Mono is
   reserved for instrument-style readouts (stat tiles, dive numbers) —
   a deliberate nod to a dive computer's digital display. */

:root {
  --color-bg: #eef5f6;
  --color-surface: #ffffff;
  --color-surface-alt: #f4fafb;
  --color-border: #cfe1e6;
  --color-text: #0b2530;
  --color-text-muted: #527180;
  --color-primary: #0a5a78;
  --color-primary-hover: #084a63;
  --color-primary-light: #eaf4f7;
  --color-primary-contrast: #ffffff;
  --color-accent: #e2703a;
  --color-accent-light: #fdece2;
  --color-success: #157a5c;
  --color-success-bg: #dff3ea;
  --color-danger: #b23a2e;
  --color-danger-bg: #fbe8e4;
  --color-warning: #a8720e;
  --color-warning-bg: #fbf0dc;

  --radius-sm: 5px;
  --radius-md: 9px;
  --radius-lg: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 40px;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --shadow-card: 0 1px 2px rgba(10, 40, 55, 0.06), 0 4px 14px rgba(10, 40, 55, 0.07);
  --shadow-float: 0 10px 30px rgba(6, 25, 35, 0.16);
  --horizon-gradient: linear-gradient(90deg, var(--color-primary), var(--color-accent));
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #061318;
    --color-surface: #0e222b;
    --color-surface-alt: #0a1b22;
    --color-border: #1e3844;
    --color-text: #e7f3f5;
    --color-text-muted: #8fb0ba;
    --color-primary: #4fc3e0;
    --color-primary-hover: #6fd3ed;
    --color-primary-light: #0f2c35;
    --color-primary-contrast: #04141a;
    --color-accent: #f0895a;
    --color-accent-light: #2c1912;
    --color-success: #3fcf8e;
    --color-success-bg: #103524;
    --color-danger: #e57474;
    --color-danger-bg: #3a1c1c;
    --color-warning: #e0b04b;
    --color-warning-bg: #3a2f10;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-float: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
  margin: 0 0 var(--space-3);
}
h1 { font-size: 2rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.05rem; font-family: var(--font-sans); font-weight: 700; }

p { max-width: 68ch; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

.container-narrow {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-3);
}

/* Landing hero — the one page in the app that gets a genuine hero
   treatment; everything past it is a working tool, not a pitch. */
.hero {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-3) var(--space-4);
  text-align: center;
}
.hero-title {
  font-size: clamp(2.1rem, 5vw, 3rem);
  margin-bottom: var(--space-3);
}
.hero-sub {
  max-width: 52ch;
  margin: 0 auto var(--space-4);
  font-size: 1.1rem;
  color: var(--color-text-muted);
}
.hero-actions { display: flex; gap: var(--space-3); justify-content: center; flex-wrap: wrap; margin-bottom: var(--space-5); }
.btn-lg { padding: 13px 26px; font-size: 1rem; }
.hero-flow {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: var(--space-2);
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-text-muted);
}
.hero-flow-arrow { color: var(--color-accent); opacity: 0.7; }

/* Header/nav */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: relative;
}
.site-header::after {
  /* the "horizon line" — the one deliberate flourish in the whole system */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 2px;
  background: var(--horizon-gradient);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand span { color: var(--color-primary); }
.nav-links { display: flex; gap: var(--space-3); align-items: center; list-style: none; margin: 0; padding: 0; }
.nav-links a { color: var(--color-text-muted); text-decoration: none; font-size: 0.95rem; }
.nav-links a:hover { color: var(--color-primary); }

/* Grouped dropdown nav (Dive / Plan / Explore / Gear / Journal / Progress /
   Account) — click-to-toggle (JS in app.js), one open at a time, closes on
   outside click and Escape. */
.nav-group { position: relative; }
.nav-group-trigger {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 0.95rem; font-family: var(--font-sans);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 7px;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-group-trigger:hover { background: var(--color-primary-light); color: var(--color-primary); }
.nav-group-trigger .arrow { font-size: 10px; transition: transform 0.2s ease; opacity: 0.7; }
.nav-group-trigger[aria-expanded="true"] .arrow { transform: rotate(180deg); }
.nav-dropdown {
  display: none;
  position: absolute; left: 0; top: calc(100% + 7px);
  min-width: 185px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  z-index: 1000;
}
/* The right-most group (Account) opens right-aligned so it doesn't overflow past the viewport edge. */
.nav-group.align-right .nav-dropdown { left: auto; right: 0; }
.nav-dropdown.show { display: block; }
.nav-dropdown a, .nav-dropdown .dropdown-link {
  display: block; width: 100%;
  padding: 11px 16px;
  background: none; border: none; text-align: left;
  color: var(--color-text); text-decoration: none; font-size: 0.9rem; font-family: var(--font-sans);
  cursor: pointer; white-space: nowrap;
}
.nav-dropdown a:hover, .nav-dropdown .dropdown-link:hover { background: var(--color-primary-light); color: var(--color-primary); }
.nav-dropdown .dropdown-divider { height: 1px; background: var(--color-border); margin: 5px 0; }
.nav-dropdown .logout { color: var(--color-danger) !important; }
.nav-dropdown .logout:hover { background: var(--color-danger-bg) !important; }
.nav-dropdown form { margin: 0; }

/* Mobile nav toggle (hamburger) — hidden on desktop/tablet-landscape,
   shown below the --breakpoint-nav width where the 7-group horizontal nav
   no longer fits. */
.nav-toggle {
  display: none;
  flex-direction: column; justify-content: center; gap: 5px;
  width: 40px; height: 40px;
  background: none; border: none; cursor: pointer;
  padding: 0;
}
.nav-toggle span { display: block; width: 100%; height: 2px; background: var(--color-text); border-radius: 2px; transition: transform 0.2s ease, opacity 0.2s ease; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Below this width the grouped nav can't fit on one line (phones and
   portrait tablets) — collapse it behind the hamburger into a full-width
   stacked panel; dropdowns become inline accordions instead of floating
   over content. Desktop/tablet-landscape behavior above this width is
   completely unchanged. */
@media (max-width: 860px) {
  .site-header .container { flex-wrap: wrap; height: auto; padding-top: var(--space-2); padding-bottom: var(--space-2); }
  .nav-toggle { display: flex; }
  .nav-links {
    display: none;
    flex-direction: column; align-items: stretch;
    width: 100%;
    gap: 0;
    padding-top: var(--space-2);
  }
  .nav-links.mobile-open { display: flex; }
  .nav-group, .nav-links > li { width: 100%; }
  .nav-group-trigger { width: 100%; justify-content: space-between; }
  .nav-dropdown, .nav-group.align-right .nav-dropdown {
    position: static;
    box-shadow: none; border: none; border-radius: 0;
    left: auto; right: auto;
    width: 100%; min-width: 0;
    border-left: 2px solid var(--color-border);
    margin-left: var(--space-2);
  }
  .nav-links > li:last-child { margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--color-border); }
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
}

/* Forms */
.form-group { margin-bottom: var(--space-3); }
label { display: block; margin-bottom: var(--space-1); font-size: 0.875rem; font-weight: 600; color: var(--color-text); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 9px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  font-family: var(--font-sans);
  transition: border-color 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--color-text-muted); }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  border-color: var(--color-primary);
}
.help-text { font-size: 0.85rem; color: var(--color-text-muted); margin-top: var(--space-1); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--color-primary); color: var(--color-primary-contrast); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-light); }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; }

/* Alerts */
.alert { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); margin-bottom: var(--space-3); font-size: 0.9rem; border: 1px solid transparent; }
.alert-error { background: var(--color-danger-bg); color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 25%, transparent); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: color-mix(in srgb, var(--color-success) 25%, transparent); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: color-mix(in srgb, var(--color-warning) 25%, transparent); }

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
}
.badge-active { background: var(--color-success-bg); color: var(--color-success); }
.badge-planned { background: var(--color-border); color: var(--color-text-muted); }
.badge-disabled { background: var(--color-danger-bg); color: var(--color-danger); }

/* Tables — every table on every page is wrapped in .table-scroll (see
   views) so a wide table scrolls horizontally within its own card on a
   narrow screen instead of breaking the page layout or forcing zoom-out. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 11px var(--space-2); border-bottom: 1px solid var(--color-border); white-space: nowrap; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.03em; text-transform: uppercase; }
td { font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--color-surface-alt); }

/* Utility */
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); }
.muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }
.text-center { text-align: center; }

.site-footer {
  margin-top: var(--space-5);
  padding: var(--space-4) 0;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* Admin layout */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-3);
}
.admin-sidebar .brand { display: block; margin-bottom: var(--space-4); }
.admin-sidebar nav a {
  display: block;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.admin-sidebar nav a:hover { background: var(--color-primary-light); color: var(--color-primary); }
.admin-main { flex: 1; padding: var(--space-4); }

@media (max-width: 860px) {
  .admin-shell { flex-direction: column; min-height: 0; }
  .admin-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); padding: var(--space-3); }
  .admin-sidebar nav { display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .admin-sidebar nav a { padding: var(--space-2) var(--space-2); }
}

/* Stat tiles — instrument-readout styling: a dive computer's digital
   display for the app's headline numbers. */
.stat-tile {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  min-width: 100px;
}
.stat-tile .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--color-primary);
  line-height: 1.1;
}
.stat-tile .label {
  color: var(--color-text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 4px;
}

/* A measured/computed figure — depth, pressure, SAC, temperature — styled
   like a dive computer's own digital readout. Reserved for numbers, never
   free text, so it stays a meaningful accent rather than a default. */
.readout { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
