/* PORTIS UI — v2 "Bridge Glass" component layer
 * Canonical components. Consumes tokens (portis-tokens.css) + themes
 * (portis-themes.css) ONLY — zero raw hex, zero raw px font sizes.
 * Load order: portis-tokens.css → portis-themes.css → portis-ui.css → maritime.css (legacy, shrinking)
 * Icons: js/portis-icons.js injects the SVG sprite; use
 *   <svg class="icon"><use href="#i-name"/></svg>
 */

/* ── Ambient scene (static, cheap — replaces canvas mesh gradients) ── */
.scene {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 60% 40% at 78% -5%, var(--scene-a), transparent 62%),
    radial-gradient(ellipse 42% 30% at 10% 104%, var(--scene-b), transparent 60%);
}

/* ── Icons ── */
.icon {
  width: 16px; height: 16px; flex: none;
  stroke: currentColor; stroke-width: 1.7; fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-lg { width: 20px; height: 20px; }
.icon-sm { width: 13px; height: 13px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-body); font-size: var(--fs-base); font-weight: 600;
  min-height: 40px; padding: 0 16px;
  border-radius: var(--r-sm); border: 1px solid transparent; cursor: pointer;
  text-decoration: none;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-strong); box-shadow: var(--glow); }
.btn-secondary {
  background: var(--glass-bg); color: var(--text-primary);
  border-color: var(--glass-border);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--status-danger); color: var(--text-on-accent); }
.btn-danger:hover { box-shadow: 0 0 10px color-mix(in oklab, var(--status-danger) 55%, transparent); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-sm); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
@media (pointer: coarse) { .btn { min-height: 44px; } .btn-sm { min-height: 40px; } }

/* ── App shell ── */
.app-shell { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; position: relative; z-index: 1; }
.rail {
  border-right: 1px solid var(--border); padding: 16px 10px;
  display: flex; flex-direction: column; gap: 2px;
  background: color-mix(in oklab, var(--bg-surface) 80%, transparent);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.rail-brand {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md);
  padding: 6px 12px 16px; letter-spacing: -.01em; color: var(--text-primary);
  text-decoration: none;
}
.pip-live { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: var(--glow); flex: none; }
.rail-item {
  display: flex; align-items: center; gap: 11px;
  min-height: 38px; padding: 0 12px; border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-secondary);
  cursor: pointer; border: 1px solid transparent; text-decoration: none;
  background: transparent; width: 100%; text-align: left; font-family: var(--font-body);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.rail-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.rail-item .icon { color: var(--text-muted); }
.rail-item.active {
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%);
  color: var(--text-primary);
  border-color: color-mix(in oklab, var(--accent) 28%, transparent);
}
.rail-item.active .icon { color: var(--accent-text); }
.rail-item .count {
  margin-left: auto; font-family: var(--font-mono); font-size: var(--fs-xs);
  background: var(--accent-soft); color: var(--accent-text);
  border-radius: var(--r-pill); padding: 2px 7px;
}
.rail-spacer { flex: 1; }

/* ── Topbar ── */
.rail-topbar, .topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: var(--topbar-h); padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg-surface) 78%, transparent);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  position: sticky; top: 0; z-index: 20;
}
.rail-topbar h1, .topbar h1, .rail-topbar h2, .topbar h2 {
  font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700;
  letter-spacing: -.02em; margin: 0;
}
.live-tag {
  font-family: var(--font-mono); font-size: var(--fs-xs); letter-spacing: .1em;
  color: var(--status-ok); display: flex; align-items: center; gap: 7px;
}
.live-tag::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--status-ok); box-shadow: 0 0 8px var(--status-ok);
  animation: pip-pulse 2.2s infinite;
}
@keyframes pip-pulse { 50% { opacity: .35; } }

/* ── KPI glass cards (canonical stat pattern — replaces stat-grid/summary-bar/ds-cell) ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
  position: relative; overflow: hidden;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--r-lg); padding: 15px var(--card-pad);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  transition: transform var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.kpi:hover { transform: translateY(-1px); border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.kpi-label { font-size: var(--fs-xs); font-weight: 500; color: var(--text-muted); letter-spacing: .01em; }
.kpi-value {
  /* Fragment Mono ships 400 only — keep weight 400 and let size carry the hierarchy */
  font-family: var(--font-mono); font-size: var(--fs-2xl); font-weight: 400;
  margin-top: 7px; font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.kpi-value small { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 400; }
.kpi-delta { font-family: var(--font-mono); font-size: var(--fs-xs); margin-top: 5px; }
.kpi-delta.up { color: var(--status-ok); }
.kpi-delta.down { color: var(--status-warn); }
.kpi.is-warn { box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--status-warn) 40%, transparent); }
.kpi.is-warn .kpi-value { color: var(--status-warn); }
.kpi.is-danger { box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--status-danger) 42%, transparent); }
.kpi.is-danger .kpi-value { color: var(--status-danger); }
.kpi-spark { position: absolute; bottom: 0; left: 0; right: 0; height: 26px; opacity: .65; pointer-events: none; }

/* ── Cards ── */
.card {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px var(--card-pad); border-bottom: 1px solid var(--border);
}
.card-title {
  font-family: var(--font-display); font-size: var(--fs-md); font-weight: 600;
  letter-spacing: -.01em; display: flex; align-items: center; gap: 9px; margin: 0;
}
.card-title .icon { color: var(--accent-text); }
.card-body { padding: var(--card-pad); }

/* ── Status pips & chips (retire the left-border stripe) ── */
.pip { width: 7px; height: 7px; border-radius: 50%; flex: none; display: inline-block; }
.pip.ok     { background: var(--status-ok);     box-shadow: 0 0 8px color-mix(in oklab, var(--status-ok) 75%, transparent); }
.pip.warn   { background: var(--status-warn);   box-shadow: 0 0 8px color-mix(in oklab, var(--status-warn) 75%, transparent); }
.pip.danger { background: var(--status-danger); box-shadow: 0 0 8px color-mix(in oklab, var(--status-danger) 75%, transparent); }
.pip.info   { background: var(--status-info);   box-shadow: 0 0 8px color-mix(in oklab, var(--status-info) 75%, transparent); }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .02em;
  padding: 4px 11px; border-radius: var(--r-pill);
}
.chip.ok      { background: var(--status-ok-soft);     color: var(--status-ok); }
.chip.warn    { background: var(--status-warn-soft);   color: var(--status-warn); }
.chip.danger  { background: var(--status-danger-soft); color: var(--status-danger); }
.chip.info    { background: var(--status-info-soft);   color: var(--accent-text); }
.chip.neutral { background: var(--bg-hover);           color: var(--text-secondary); }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto; border-radius: var(--r-lg);
  border: 1px solid var(--glass-border); background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
}
table.ui { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.ui thead th {
  text-align: left; font-size: var(--fs-xs); font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted);
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg-surface) 55%, transparent);
}
table.ui td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.ui tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
table.ui tbody tr:hover { background: var(--row-hover); }
table.ui tbody tr:last-child td { border-bottom: 0; }
.cell-main { font-weight: 600; color: var(--text-primary); }
.cell-sub { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); margin-top: 1px; }
td.mono, th.mono { font-family: var(--font-mono); color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }
.field label .req { color: var(--status-danger); }
.input, .select, .textarea {
  font-family: var(--font-body); font-size: var(--fs-md);
  min-height: 44px; padding: 0 14px; width: 100%;
  color: var(--text-primary); background: var(--bg-surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.textarea { padding: 12px 14px; min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent), transparent 78%);
}
.input.is-error, .select.is-error {
  border-color: var(--status-danger);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--status-danger), transparent 82%);
}
.field .error { font-size: var(--fs-xs); color: var(--status-danger); display: flex; align-items: center; gap: 6px; }
.field .hint  { font-size: var(--fs-xs); color: var(--text-muted); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23808fa0' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.seg {
  display: inline-flex; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 2px;
}
.seg button {
  font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 600;
  min-height: 34px; padding: 0 14px; border: 0;
  border-radius: calc(var(--r-sm) - 2px);
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--text-on-accent); }
.toggle {
  position: relative; width: 42px; height: 24px; flex: none;
  border-radius: var(--r-pill); background: var(--bg-sunken);
  border: 1px solid var(--border-strong); cursor: pointer;
  transition: background-color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--text-muted);
  transition: transform var(--dur-base) var(--ease-spring), background-color var(--dur-base);
}
.toggle[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.toggle[aria-checked="true"]::after { transform: translateX(18px); background: var(--text-on-accent); }

/* Selection cards (wizard notification cards, confirm cards, radio/check items) */
.select-card {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 13px 15px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--bg-surface); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.select-card:hover { border-color: var(--border-strong); }
.select-card:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.select-card:has(input:focus-visible) { box-shadow: var(--focus-ring); }
.select-card input { accent-color: var(--accent); }

/* ── Tabs ── */
.tab-bar { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab-btn {
  font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 600;
  min-height: 40px; padding: 0 16px; border: 0; background: transparent;
  color: var(--text-secondary); cursor: pointer; position: relative;
  transition: color var(--dur-fast) var(--ease-out);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn[aria-selected="true"], .tab-btn.active { color: var(--accent-text); }
.tab-btn[aria-selected="true"]::after, .tab-btn.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--accent); box-shadow: var(--glow);
}

/* ── Modal (canonical) ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in oklab, var(--bg-sunken) 55%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box, .modal {
  width: min(480px, 100%); max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--bg-raised); border: 1px solid var(--glass-border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-3);
  animation: modal-in var(--dur-slow) var(--ease-spring);
}
.modal-box--medium { width: min(640px, 100%); }
.modal-box--large  { width: min(880px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: inherit;
}
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: var(--fs-md); font-weight: 700; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg-surface) 60%, transparent);
}

/* ── Toast (canonical, single system) ── */
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 11px;
  min-height: 44px; padding: 10px 16px; max-width: 380px;
  background: var(--bg-raised); border: 1px solid var(--glass-border);
  border-radius: var(--r-md); box-shadow: var(--shadow-2);
  font-size: var(--fs-sm); font-weight: 500;
  animation: toast-in var(--dur-slow) var(--ease-spring);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.toast .icon { color: var(--status-ok); }
.toast.err .icon { color: var(--status-danger); }
.toast.warn .icon { color: var(--status-warn); }

/* ── Empty state (canonical) ── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 44px 24px; gap: 6px; }
.empty .glyph {
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; margin-bottom: 8px;
}
.empty .glyph .icon { width: 22px; height: 22px; color: var(--accent-text); }
.empty h4 { margin: 0; font-family: var(--font-display); font-size: var(--fs-md); font-weight: 700; }
.empty p { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); max-width: 300px; }
.empty .btn { margin-top: 12px; }

/* ── Legacy alias bridge (v2) ──
 * Old code references these; keep them pointing at CORRECT v2 tokens.
 * --accent-light was historically (wrongly) used as a text color — map it
 * to --accent-text so all legacy call sites become readable. */
:root, [data-theme] {
  --bg-primary:   var(--bg-base);
  --bg-secondary: var(--bg-surface);
  --bg-panel:     var(--bg-raised);
  --bg-card:      var(--bg-raised);
  --border-light: var(--border);
  --accent-light: var(--accent-text);
  --error:        var(--status-danger);
  --success:      var(--status-ok);
}

/* ── Hull identity block (Phase 430) ──────────────────────────────────────
 * Styles the ONE shared identifier component (js/vessel-identity.js), which
 * mounts into all five vessel-capture surfaces. Deliberately styled here in
 * the component layer rather than per-surface: five copies of these rules is
 * how five copies of the component happen.
 *
 * The durable/non-durable split is carried VISUALLY, not just in prose. IMO
 * and official number read as identity; call sign and MMSI are demoted with a
 * muted "not a durable identifier" tag. A developer skimming the rendered form
 * should not be able to mistake MMSI for a key.
 *
 * Tokens only — zero raw hex, per this file's header contract. */
.identity-block {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 15px 4px;
  margin-bottom: 14px;
  background: var(--bg-sunken);
}
.identity-block-heading {
  font-family: var(--font-body);
  font-size: var(--fs-sm); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.identity-block-heading .req { color: var(--status-danger); }
.identity-block-heading--secondary {
  margin-top: 6px; padding-top: 12px;
  border-top: 1px dashed var(--border);
  color: var(--text-muted);
}
.identity-block-note {
  font-size: var(--fs-xs); color: var(--text-muted);
  line-height: 1.45; margin: 0 0 12px;
}
.identity-block-note--warn { color: var(--text-secondary); }
.identity-block-note--warn strong { color: var(--status-warn); }

/* The demotion tag. Never let this read as decoration — it is the whole
 * reason call sign and MMSI are allowed on this form at all. */
.identity-not-durable {
  display: inline-block; margin-left: 6px;
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--status-warn);
  border: 1px solid color-mix(in oklab, var(--status-warn), transparent 62%);
  border-radius: var(--r-pill);
  padding: 1px 7px;
  vertical-align: middle;
}

.identity-block .field-hint {
  font-size: var(--fs-xs); color: var(--text-muted);
  line-height: 1.4; margin-top: 3px;
}

/* Errors BLOCK the save; warnings do not. They share a slot, so they must not
 * share an appearance — a captain has to be able to tell "you must fix this"
 * from "you should know this" without reading the sentence twice. */
.identity-block .error-msg,
.identity-block .field-error-msg {
  display: block; min-height: 15px; margin-top: 3px;
  font-size: var(--fs-xs); line-height: 1.35;
  color: var(--status-danger);
}
.identity-block .error-msg.is-warning,
.identity-block .field-error-msg.is-warning {
  color: var(--status-warn);
}
.identity-block .has-error .input,
.identity-block .has-error input,
.identity-block .has-error select {
  border-color: var(--status-danger);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--status-danger), transparent 82%);
}
.identity-block input,
.identity-block select {
  font-family: var(--font-body); font-size: var(--fs-md);
  min-height: 40px; padding: 0 12px; width: 100%;
  color: var(--text-primary); background: var(--bg-surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
}
.identity-block input:focus-visible,
.identity-block select:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent), transparent 78%);
}
.identity-block label {
  display: block; margin-bottom: 4px;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary);
}
.identity-block .form-group,
.identity-block .modal-form-group { margin-bottom: 10px; }

@media (max-width: 480px) {
  .identity-block { padding: 12px 12px 2px; }
}
