/* Current Diagram — Harmonized Ali Sailing Tools UI (Light & Night Bridge Themes) */

:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --muted: #475569;
  --faint: #64748b;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-soft: #e0f2fe;
  --teal: #0d9488;
  --track: #c2410c;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --warn-fg: #92400e;
  --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"] {
  color-scheme: dark;
  --bg: #070d19;
  --surface: #0f172a;
  --surface-muted: #1e293b;
  --border: #1e293b;
  --border-strong: #334155;
  --ink: #f1f5f9;
  --muted: #cbd5e1;
  --faint: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --teal: #2dd4bf;
  --track: #fb923c;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --warn-border: #f59e0b;
  --warn-fg: #fde68a;
  --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(--ink);
  font-size: 13.5px;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
button, a, input, select { touch-action: manipulation; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Unified Ali Sailing Tools Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1460px;
  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;
  flex-wrap: wrap;
}
.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(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.back-link:hover { border-color: var(--accent); color: var(--accent); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--accent);
}
.brand-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.subtitle {
  display: block;
  font-size: 11.5px;
  color: var(--faint);
}

/* View Switcher Segmented Control */
.view-seg {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.seg-link {
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 5px 11px;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.seg-link:hover:not(.active) { color: var(--ink); }
.seg-link.active {
  background: var(--accent);
  color: #ffffff;
}
.nav-link {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 5px 6px;
  border-radius: 6px;
}
.nav-link:hover { color: var(--accent); }

/* Buttons */
.btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn { height: 34px; padding: 0 12px; white-space: nowrap; }
.btn.subtle { background: var(--surface-muted); border-color: var(--border); color: var(--muted); }
.icon-btn { width: 34px; height: 34px; padding: 0; }
.btn:hover, .icon-btn:hover { background: var(--surface-muted); border-color: var(--accent); color: var(--accent); }

/* Main Container & Page Head */
main {
  max-width: 1460px;
  margin: 0 auto;
  padding: 18px 18px 28px;
}
.page-head, .plot-head, .log-head, .dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.page-head { margin-bottom: 16px; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 4px;
  color: var(--accent);
}
.line {
  display: inline-block;
  vertical-align: middle;
  width: 18px;
  height: 2px;
  background: var(--accent);
  margin-right: 6px;
  border-radius: 1px;
}
h1, h2, h3, p { margin-top: 0; }
h1 {
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.025em;
  margin: 0;
}
h2 {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.25;
}
.sub { color: var(--faint); margin: 4px 0 0; font-size: 13px; }
.print { flex-shrink: 0; }

/* Workspace Layout & Cards */
.layout {
  display: grid;
  grid-template-columns: clamp(248px, 21vw, 295px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  border-bottom: 1px solid var(--border);
  padding: 13px 16px;
}
.control-body { padding: 14px 16px 18px; }

/* Form Controls */
label, legend {
  display: block;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 5px;
}
label small {
  float: right;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--faint);
}
select, input[type="date"], input[type="time"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  height: 36px;
  padding: 0 9px;
  font-size: 13px;
  min-width: 0;
  outline: none;
}
select:focus, input[type="date"]:focus, input[type="time"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; }
fieldset { border: 0; padding: 0; margin: 14px 0; }
legend { padding: 0; }

.segmented {
  display: flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  padding: 6px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: #ffffff;
}

.endpoints label { display: flex; align-items: center; gap: 6px; }
.endpoints label:not(:first-child),
input + label,
select + label { margin-top: 12px; }
.origin, .destination {
  width: 8px;
  height: 8px;
  border: 2px solid var(--track);
  border-radius: 50%;
  flex-shrink: 0;
}
.destination { background: var(--track); }

hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.speed-read { display: flex; align-items: baseline; gap: 5px; }
.speed-read output {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.speed-read span, .range-ends { color: var(--faint); font-size: 11.5px; }
#speed, .scrub input {
  accent-color: var(--accent);
  width: 100%;
  margin: 6px 0 3px;
  cursor: pointer;
}
.scrub { margin-top: 6px; }
.range-ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10.5px;
}
#gribPanel { margin-top: 10px; }
#gribFiles { width: 100%; font-size: 11.5px; }

/* Plot & Legend */
.plot-head, .log-head { padding: 13px 18px; }
.plot-head .eyebrow, .log-head .eyebrow { font-size: 10px; margin: 0 0 2px; }
.source-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 99px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}
.source-tag i {
  width: 7px;
  height: 7px;
  background: var(--teal);
  border-radius: 50%;
  flex-shrink: 0;
}
.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 9px 18px;
  border-block: 1px solid var(--border);
  background: var(--surface-muted);
  font-size: 11.5px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 9px; border-radius: 3px; }
.fair { background: #a2cbbd; border: 1px solid #6fa695; }
.adverse { background: #e3c99b; border: 1px solid #c5a16a; }
.legend .track { height: 3px; width: 17px; background: #c2410c; border-radius: 2px; }
.legend .station-track { height: 0; width: 18px; border-top: 2px dashed #304956; border-radius: 0; }
html[data-theme="dark"] .fair { background: #167a68; border-color: #2dd4bf; }
html[data-theme="dark"] .adverse { background: #9a5820; border-color: #f59e0b; }
html[data-theme="dark"] .legend .track { background: #fb923c; }
html[data-theme="dark"] .legend .station-track { border-top-color: #94a3b8; }
.units { margin-left: auto; color: var(--faint); font-family: var(--font-mono); font-size: 11px; }

#comparison {
  padding: 10px 18px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.5;
}
#comparison strong { display: block; color: var(--ink); }
#comparison small { color: var(--muted); }

#status:not(:empty) {
  padding: 10px 18px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 500;
}
#status button {
  border: 1px solid currentColor;
  background: transparent;
  margin-left: 10px;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 600;
}

.plot-scroll, .table-scroll { overflow-x: auto; }
.plot-scroll { background: var(--surface); }
#plot { position: relative; margin: 0 8px; min-width: 660px; min-height: 580px; }
#plot canvas { position: absolute; pointer-events: none; }
#plot svg { display: block; width: 100%; position: relative; touch-action: pan-x pan-y; }

.inspect {
  border-top: 1px solid var(--border);
  padding: 10px 18px;
  min-height: 39px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.inspect strong { color: var(--ink); }

/* Predictions Table */
.log { margin: 16px 0; }
.log-head { border-bottom: 1px solid var(--border); }
#summary {
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: 12px;
  color: var(--faint);
  flex-wrap: wrap;
}
#summary b {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  text-align: left;
}
th, td {
  padding: 9px 16px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
th {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
  background: var(--surface-muted);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-muted); }
td:first-child { font-weight: 600; }
.favorable { color: #047857; font-weight: 600; }
.opposed { color: #b45309; font-weight: 600; }
html[data-theme="dark"] .favorable { color: #34d399; }
html[data-theme="dark"] .opposed { color: #fbbf24; }

/* Footer */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 2px 4px;
  font-size: 12px;
  color: var(--faint);
  flex-wrap: wrap;
}
footer strong { color: var(--muted); }

/* Data & Method Dialog */
dialog {
  width: min(660px, calc(100% - 28px));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 20px 22px;
  color: var(--ink);
  background: var(--surface);
  max-height: 85vh;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.25);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(2px); }
.dialog-head { margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.dialog-head button {
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  border-radius: 8px;
  width: 32px;
  height: 32px;
}
dialog p { font-size: 13px; line-height: 1.55; color: var(--muted); }
dialog h3 { font-size: 14.5px; margin: 16px 0 8px; color: var(--ink); }
#stationList p { margin: 6px 0; border-top: 1px solid var(--border); padding-top: 6px; }
#stationList small { display: block; color: var(--faint); font-family: var(--font-mono); font-size: 11px; }

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .control-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 14px;
    align-items: center;
  }
  .control-body > label { margin: 8px 0 4px; }
  .control-body > fieldset,
  .endpoints,
  .control-body > hr,
  .control-body > #speed,
  .control-body > .range-ends,
  .scrub,
  #gribPanel { grid-column: 1 / -1; }
  .endpoints { display: grid; grid-template-columns: 48px 1fr 32px 1fr; align-items: center; gap: 8px; }
  .endpoints label:not(:first-child) { margin: 0; }
  fieldset { margin: 8px 0; }
  .control-body hr { margin: 10px 0; }
  .speed-read { justify-content: flex-end; }
  .legend { gap: 10px; }
  .log-head { align-items: flex-start; flex-wrap: wrap; }
  #summary { gap: 12px; }
}

@media (max-width: 600px) {
  .topbar-inner { padding: 10px 12px; }
  .subtitle, .nav-link { display: none; }
  main { padding: 12px 12px 22px; }
  .page-head { flex-wrap: wrap; }
  .endpoints { grid-template-columns: 44px 1fr; }
  .endpoints label { margin: 0; }
  select, input[type="date"], input[type="time"] { height: 42px; font-size: 15px; }
  .card-head, .control-body, .plot-head, .log-head { padding: 12px 14px; }
  .legend { padding: 8px 14px; }
  .units { display: none !important; }
  footer { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* Print Layout */
@media print {
  @page { size: landscape; margin: 9mm; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .topbar, .controls, .print, .inspect, footer, dialog, #status button { display: none !important; }
  body { background: #ffffff !important; color: #0f172a !important; }
  main { padding: 0; max-width: none; }
  .page-head { padding: 0 0 10px; margin-bottom: 8px; }
  .layout { display: block; }
  .plot-scroll, .table-scroll { overflow: visible; }
  .card { break-inside: avoid; box-shadow: none; border-color: #cbd5e1; }
  .log { break-before: page; }
  .log table { font-size: 10px; }
  .chart-card { max-width: 980px; }
  h1 { font-size: 24px; }
}
