/* Compass Calibration — Modern Nautical UI */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-soft: #e0f2fe;
  --west-bg: #fef2f2;
  --west-fg: #b91c1c;
  --east-bg: #ecfdf5;
  --east-fg: #047857;
  --zero-bg: #f1f5f9;
  --zero-fg: #475569;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #070d19;
  --surface: #0f172a;
  --surface-muted: #1e293b;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-muted: #cbd5e1;
  --text-faint: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --west-bg: rgba(239, 68, 68, 0.16);
  --west-fg: #fca5a5;
  --east-bg: rgba(16, 185, 129, 0.16);
  --east-fg: #6ee7b7;
  --zero-bg: #1e293b;
  --zero-fg: #94a3b8;
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-sans); background: var(--bg); color: var(--text); font-size: 13.5px; line-height: 1.45; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.hidden { display: none !important; }
.print-only { display: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left, .topbar-actions { display: flex; align-items: center; gap: 10px; }
.back-link {
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.back-link:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--accent); }
.brand h1 { margin: 0; font-size: 16px; color: var(--text); letter-spacing: -0.02em; line-height: 1.15; }
.subtitle { font-size: 11.5px; color: var(--text-faint); }

/* Buttons */
.btn, .icon-btn, .now-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn { height: 34px; padding: 0 12px; }
.icon-btn { width: 34px; height: 34px; padding: 0; }
.now-btn { height: 30px; padding: 0 8px; font-size: 11px; color: var(--text-muted); border-color: var(--border); background: var(--surface-muted); }
.btn:hover, .icon-btn:hover, .now-btn:hover { background: var(--surface-muted); border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #ffffff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #ffffff; }

/* Page Layout */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
.hint { font-size: 11.5px; color: var(--text-faint); }

/* Setup Form Grid */
.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
}
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.inline-inputs { display: flex; align-items: center; gap: 4px; }
.input {
  height: 34px;
  width: 100%;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.is-invalid { border-color: var(--danger); background: var(--danger-soft); }
.input.sm { max-width: 68px; text-align: center; }
.input.time-in { width: 88px; height: 30px; text-align: center; }
.input.rrb-in { width: 64px; height: 30px; text-align: center; }
.sep, .unit { color: var(--text-faint); font-weight: 700; font-size: 14px; }

.toggle-check { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; user-select: none; }
.toggle-check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

.banner {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
}
.banner.info { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--text); }
.banner.error { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-muted); }
.data-table.compact { table-layout: fixed; }
.data-table.compact thead th,
.data-table.compact tbody td {
  padding: 8px 10px;
  text-align: center;
}
.data-table.compact tbody td { font-size: 13.5px; }
.time-cell { display: flex; align-items: center; gap: 5px; }
.hdg-card {
  display: inline-block;
  margin-left: 5px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-faint);
  font-family: var(--font-sans);
}
.sightings-table.details-hidden .detail-col { display: none; }

/* Quick Heading Jump Bar (shown on mobile/tablet) */
.heading-jump-bar {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.jump-chip {
  height: 36px;
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.jump-chip:hover, .jump-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.dev-pill {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 12.5px;
  background: var(--zero-bg);
  color: var(--zero-fg);
}
.dev-pill.west { background: var(--west-bg); color: var(--west-fg); }
.dev-pill.east { background: var(--east-bg); color: var(--east-fg); }

/* Results Grid */
.results-grid {
  display: grid;
  grid-template-columns: minmax(290px, 370px) 1fr;
  gap: 16px;
  align-items: start;
}
.chart-box { position: relative; width: 100%; height: 310px; }

.coeff-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.coeff-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.coeff-head h3 { margin: 0; font-size: 13.5px; }
.coeff-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.coeff-box {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
}
.coeff-k { font-size: 11px; font-weight: 800; color: var(--accent); }
.coeff-v { font-size: 14px; font-weight: 700; color: var(--text); }
.coeff-sub { font-size: 10px; color: var(--text-faint); }

.notes-card ul { margin: 8px 0 0; padding-left: 18px; color: var(--text-muted); font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }

@media (max-width: 900px) {
  .results-grid { grid-template-columns: 1fr; }
  .coeff-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Mobile Cockpit Mode: Card-based 8-point Sightings & Large Touch Controls */
@media (max-width: 768px) {
  .page { padding: 12px; gap: 12px; }
  .card { padding: 14px; }
  .topbar-inner { padding: 10px 12px; }
  .subtitle { display: none; }

  /* Full-width primary capture button & 2-col touch-friendly setup form */
  .head-actions { width: 100%; }
  .head-actions .btn { width: 100%; height: 44px; font-size: 14px; }
  .setup-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px 10px;
  }
  .setup-grid .field-date,
  .setup-grid .field-coord { grid-column: 1 / -1; }
  .setup-grid .input {
    height: 44px;
    font-size: 16px; /* prevents iOS Safari auto-zoom */
    padding: 0 10px;
  }
  .setup-grid .input.sm { max-width: 82px; }

  .toggle-check { padding: 6px 0; font-size: 13px; }
  .toggle-check input { width: 18px; height: 18px; }

  /* Show heading jump bar on mobile */
  .heading-jump-bar { display: grid; }

  /* Transform wide 9-column sightings table into stacked touch-friendly cards */
  .sightings-wrap { overflow-x: visible; }
  .sightings-table,
  .sightings-table tbody { display: block; width: 100%; }
  .sightings-table thead { display: none; }

  .sightings-table tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .sightings-table tbody tr {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 10px 8px;
    padding: 12px;
    background: var(--surface-muted);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
    scroll-margin-top: 72px;
  }
  .sightings-table tbody tr:hover { background: var(--surface-muted); }
  .sightings-table tbody tr.is-active,
  .sightings-table tbody tr:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--surface);
  }

  .sightings-table tbody td {
    display: block;
    padding: 0;
    border: none;
    white-space: normal;
  }

  /* Row 1: Heading (left) + Deviation pill (right) */
  .sightings-table td.cell-hdg {
    grid-column: 1 / 6;
    display: flex;
    align-items: center;
    gap: 7px;
  }
  .sightings-table .hdg-deg {
    font-size: 18px;
    letter-spacing: -0.02em;
  }
  .sightings-table .hdg-card {
    margin-left: 0;
    padding: 2px 7px;
    border-radius: 99px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    font-size: 11px;
    color: var(--text-muted);
  }
  .sightings-table td.cell-dev {
    grid-column: 6 / 11;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  .sightings-table td.cell-dev .dev-pill {
    font-size: 13.5px;
    padding: 4px 11px;
    min-width: 58px;
  }

  /* Row 2: Time + Now (left 6 cols) and RRB (right 4 cols) */
  .sightings-table td.cell-time {
    grid-column: 1 / 7;
    order: 2;
  }
  .sightings-table td.cell-rrb {
    grid-column: 7 / 11;
    order: 3;
  }
  .sightings-table td.cell-time::before,
  .sightings-table td.cell-rrb::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
    margin-bottom: 4px;
    font-family: var(--font-sans);
  }
  .sightings-table .time-cell { gap: 6px; }
  .sightings-table .input.time-in,
  .sightings-table .input.rrb-in {
    width: 100%;
    height: 44px;
    font-size: 16px;
    font-weight: 600;
    background: var(--surface);
  }
  .sightings-table .now-btn {
    height: 44px;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
  }

  /* Row 3: 5-cell mini detail strip inside card when Show Calculation Details is ON */
  .sightings-table td.detail-col {
    grid-column: span 2;
    order: 4;
    padding-top: 8px;
    border-top: 1px dashed var(--border-strong);
    text-align: center;
    font-size: 12px;
  }
  .sightings-table td.detail-col::before {
    content: attr(data-label);
    display: block;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
    margin-bottom: 2px;
    font-family: var(--font-sans);
  }
}

@media (max-width: 480px) {
  .topbar-actions { width: 100%; justify-content: space-between; }
  .topbar-actions .btn { flex: 1; height: 38px; }
  .topbar-actions .icon-btn { width: 38px; height: 38px; flex-shrink: 0; }
  .sightings-table td.detail-col { font-size: 11px; }
}

/* Clean Cockpit Deviation Card Print Layout */
@media print {
  @page { size: portrait; margin: 0.45in; }
  body { background: #fff !important; color: #000 !important; }
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  .print-header { border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 14px; }
  .print-header h2 { margin: 0 0 4px; font-size: 16pt; }
  .page { padding: 0; max-width: none; }
  .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
  .results-grid { grid-template-columns: 1fr; }
  .chart-box { height: 300px; }
}
