/* Shared design system. Linked on every page.
   shared.css owns ALL nav CSS — never duplicate nav styling in a page <style> block. */

:root {
  --bg: #0f1117;
  --card: #1a1f2e;
  --border: #2d3748;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #90cdf4;
  --accent-strong: #63b3ed;
  --danger: #fc8181;
  --success: #68d391;
  --warm: #f6ad55; /* thermal/climb, paired with --accent-strong for glide — colorblind-safe */
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

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

/* ---- nav ---- */

.nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  letter-spacing: 0.02em;
}

.nav-links { display: flex; gap: 1.25rem; flex: 1; flex-wrap: wrap; }

.nav-links a {
  color: var(--text-dim);
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active { color: var(--accent); border-bottom-color: var(--accent); }

.nav-right { display: flex; align-items: center; gap: 0.75rem; }

/* ---- layout ---- */

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem; }
.container-narrow { max-width: 420px; margin: 0 auto; padding: 3rem 1.25rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }

/* ---- forms ---- */

.field { margin-bottom: 1rem; }

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-dim);
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button, .btn {
  padding: 0.6rem 1.1rem;
  background: var(--accent);
  color: #0b1220;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--accent-strong); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ---- feedback ---- */

.alert {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: none;
}
.alert.visible { display: block; }
.alert-error { background: rgba(252, 129, 129, 0.12); border: 1px solid var(--danger); color: var(--danger); }
.alert-success { background: rgba(104, 211, 145, 0.12); border: 1px solid var(--success); color: var(--success); }

.muted { color: var(--text-dim); font-size: 0.875rem; }

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.7rem;
  cursor: help;
  margin-left: 0.35rem;
}

/* ---- page/list components (flights, sites, equipment, contacts) ---- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.page-head h1 { margin: 0; }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.filter-row input, .filter-row select { width: auto; min-width: 9rem; flex: 1 1 9rem; }

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
th.sorted { color: var(--accent); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: rgba(144, 205, 244, 0.06); }
tbody tr.retired { opacity: 0.55; }
tbody tr.row-highlight { background: rgba(144, 205, 244, 0.18); transition: background 0.4s ease; }

.empty-state { padding: 2rem 0; text-align: center; }

.track-badge { font-weight: 700; cursor: default; }
.track-badge.track-yes { color: var(--success); }
.track-badge.track-no { color: var(--text-dim); }

.pagination {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1.25rem;
}
.pagination button:disabled { opacity: 0.35; }

.btn-danger { background: var(--danger); color: #2b0b0b; }
.btn-danger:hover { background: #f56565; }

.field-row { display: flex; gap: 0.9rem; }
.field-row .field { flex: 1; }

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin: 0.3rem 0 0;
  min-height: 1em;
}

/* ---- drawer (add/edit panels) ---- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 1.25rem;
  overflow-y: auto;
  z-index: 21;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.drawer-head h2 { margin: 0; }
.drawer-head button { font-size: 1.3rem; line-height: 1; padding: 0.25rem 0.6rem; }

.drawer-actions { display: flex; gap: 0.6rem; margin-top: 1.25rem; }

.delete-confirm {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: rgba(252, 129, 129, 0.08);
}
.delete-confirm p { margin: 0 0 0.7rem; }
.delete-confirm .btn-danger { margin-right: 0.5rem; }

.checkbox-row { display: flex; flex-direction: column; gap: 0.5rem; }
.checkbox-row label { display: flex; align-items: flex-start; gap: 0.5rem; font-weight: 400; }
.checkbox-row input { margin-top: 0.2rem; }
.checkbox-row .muted { display: block; }

.key-reveal {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--success);
  border-radius: var(--radius);
  background: rgba(104, 211, 145, 0.08);
}
.key-reveal p { margin: 0 0 0.7rem; }
.key-reveal code {
  display: block;
  padding: 0.6rem;
  margin-bottom: 0.7rem;
  background: var(--bg);
  border-radius: var(--radius);
  word-break: break-all;
  user-select: all;
}

/* ---- detail pages ---- */

.detail-grid {
  display: grid;
  grid-template-columns: 10rem 1fr;
  row-gap: 0.6rem;
  column-gap: 1rem;
  margin: 1rem 0;
}
.detail-grid dt { color: var(--text-dim); font-size: 0.875rem; }
.detail-grid dd { margin: 0; }

/* ---- map (sites) ---- */

.site-map { height: 420px; border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.site-map.armed { outline: 2px solid var(--accent); cursor: crosshair; }
.site-pin { background: none; border: none; }

.track-map { height: 320px; border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.barogram-container { position: relative; height: 220px; margin-bottom: 1.25rem; }

/* ---- stat tiles & charts (stats page) ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
  margin: 1rem 0 1.5rem;
}
.stat-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.stat-tile .stat-label { color: var(--text-dim); font-size: 0.8rem; margin-bottom: 0.3rem; }
.stat-tile .stat-value { font-size: 1.4rem; font-weight: 700; }
.stat-tile .stat-value a { color: inherit; }

.chart-container { position: relative; height: 260px; margin-bottom: 1.25rem; }

.tab-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.tab-row button {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-weight: 500;
  padding: 0.4rem 0.9rem;
}
.tab-row button.active { background: var(--accent); color: #0b1220; border-color: var(--accent); }

/* ---- responsive ---- */

@media (max-width: 640px) {
  .nav { gap: 0.75rem; padding: 0.6rem 0.9rem; }
  .nav-links { gap: 0.9rem; order: 3; width: 100%; }
  .container { padding: 1rem 0.9rem; }
  .container-narrow { padding: 1.5rem 0.9rem; }
  .card { padding: 1.1rem; }
}
