@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', 'Menlo', 'Consolas', monospace;

  --bg-panel: #ffffff;
  --bg-subtle: #f6f7f9;
  --bg-hover: #eef1f5;
  --bg-active: #e4ebf5;

  --ink-primary: #11161c;
  --ink-secondary: #4a5565;
  --ink-muted: #768293;

  --border-hairline: #dce1e8;
  --border-strong: #b8c2cf;

  --signal-blue: #0b4f8a;
  --signal-amber: #b85d19;
  --signal-vermilion: #d9460f;
  --signal-green: #146c43;
  --signal-red: #b02a37;

  font-family: var(--font-sans);
  color: var(--ink-primary);
  background: var(--bg-subtle);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
}

/* Main Split Layout */
.shell {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  height: 100dvh;
  min-height: 580px;
}

aside {
  background: var(--bg-panel);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: contain;
  z-index: 500;
}

/* Header Bar */
.panel-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.panel-header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink-primary);
}

.corridor-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 500;
  display: block;
}

.nav-link {
  font-size: 11px;
  font-weight: 500;
  color: var(--signal-blue);
  text-decoration: none;
  border: 1px solid var(--border-hairline);
  background: var(--bg-subtle);
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.nav-link:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

/* Control Section */
.control-block {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field {
  display: block;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  margin: 0 0 3px;
}

.field-Trip {
  margin-top: 0;
}

select,
input[type="text"],
input[type="date"],
input[type="datetime-local"],
input[type="file"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
  background: var(--bg-panel);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.4;
  min-height: 34px;
  box-sizing: border-box;
  transition: border-color 0.12s ease;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234a5565' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  background-size: 11px;
  padding-right: 28px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

select:focus,
input:focus {
  outline: none;
  border-color: var(--signal-blue);
}

.mono-input {
  font-family: var(--font-mono);
}

/* Action Toolbar (Add Trip & Export Toggles) */
.toolbar-container {
  position: relative;
  z-index: 520;
  flex-shrink: 0;
}

.toolbar-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border-hairline);
  background: var(--bg-subtle);
}

.tool-toggle {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--border-hairline);
  background: transparent;
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s ease;
}

.tool-toggle:last-child {
  border-right: 0;
}

.tool-toggle:hover {
  background: var(--bg-hover);
}

.tool-toggle.active {
  background: var(--bg-panel);
  color: var(--signal-blue);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--signal-blue);
}

.tool-toggle svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

/* In-Flow Push Down Drawers */
.drawer {
  display: none;
  padding: 12px 14px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-hairline);
  overflow-y: auto;
  max-height: min(340px, 42vh);
  flex-shrink: 0;
}

.drawer.open {
  display: block;
  animation: drawerPushDown 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes drawerPushDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-hairline);
}

.drawer-header h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
  margin: 0;
}

.drawer-close-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.drawer-close-btn:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
  border-color: var(--border-hairline);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
  background: var(--bg-panel);
  overflow: hidden;
  margin-bottom: 10px;
}

.tab-btn {
  border: 0;
  border-right: 1px solid var(--border-hairline);
  background: transparent;
  color: var(--ink-secondary);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 4px;
  cursor: pointer;
}

.tab-btn:last-child {
  border-right: 0;
}

.tab-btn.active {
  background: var(--ink-primary);
  color: #ffffff;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.form-row {
  margin-top: 8px;
}

.btn-action {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--ink-primary);
  border-radius: 4px;
  background: var(--ink-primary);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-action:hover {
  background: #252f3d;
}

.status-line {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-secondary);
}

/* Export List */
.export-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-export {
  width: 100%;
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
  background: var(--bg-panel);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 11.5px;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.btn-export:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.export-format {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
  border: 1px solid var(--border-hairline);
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-subtle);
}

/* Flush 4-Cell Instrument Readout Grid */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--border-hairline);
  background: var(--bg-panel);
}

.metric-cell {
  padding: 8px 10px;
  border-right: 1px solid var(--border-hairline);
  min-width: 0;
}

.metric-cell:last-child {
  border-right: 0;
}

.metric-cell small {
  display: block;
  font-size: 9.5px;
  color: var(--ink-muted);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-cell b {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
  display: block;
  white-space: nowrap;
}

/* Data Sections */
.section {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.section h2,
.table-section h2,
.section-header h2 {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
  margin: 0;
}

.info-grid {
  display: grid;
  grid-template-columns: 88px 1fr;
  row-gap: 3px;
  column-gap: 8px;
  font-size: 11px;
  margin: 0;
}

.info-grid dt {
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding-top: 1px;
}

.info-grid dd {
  margin: 0;
  color: var(--ink-primary);
  word-break: break-word;
  font-weight: 500;
}

.info-grid dd.mono {
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* Status Indicators (Restrained, Non-Slop) */
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--border-hairline);
}

.status-tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-tag.direct {
  color: var(--signal-blue);
  background: #f2f6fa;
  border-color: #c5d7ea;
}
.status-tag.direct::before {
  background: var(--signal-blue);
}

.status-tag.transit {
  color: var(--signal-amber);
  background: #fdf6f0;
  border-color: #ebd0b8;
}
.status-tag.transit::before {
  background: var(--signal-amber);
}

/* AIS Log Table */
.table-section {
  flex: 1;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border-hairline);
  overflow: hidden;
}

.ais-table-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
  background: var(--bg-panel);
}

.ais-table-wrap::-webkit-scrollbar {
  width: 6px;
}
.ais-table-wrap::-webkit-scrollbar-track {
  background: var(--bg-subtle);
}
.ais-table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
.ais-table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--ink-muted);
}

.ais-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ais-table th {
  position: sticky;
  top: 0;
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 5px 6px;
  border-bottom: 1px solid var(--border-hairline);
  z-index: 1;
}

.ais-table td {
  padding: 4px 6px;
  border-bottom: 1px solid #eef1f5;
  color: var(--ink-primary);
  line-height: 1.35;
}

.ais-table th:nth-child(1),
.ais-table td:nth-child(1) {
  width: 48px;
  text-align: left;
}

.ais-table th:nth-child(2),
.ais-table td:nth-child(2) {
  width: 135px;
  text-align: left;
}

.ais-table th:nth-child(3),
.ais-table td:nth-child(3) {
  width: 125px;
  text-align: left;
}

.ais-table th:nth-child(4),
.ais-table td:nth-child(4) {
  width: 55px;
  text-align: right;
  padding-right: 8px;
}

.ais-table tbody tr {
  cursor: pointer;
}

.ais-table tbody tr:hover {
  background: var(--bg-hover);
}

.ais-table tbody tr.active {
  background: var(--bg-active);
  font-weight: 600;
}

.ais-table tbody tr.active td:first-child {
  box-shadow: inset 3px 0 0 var(--signal-blue);
}

.footnote {
  padding: 10px 16px;
  font-size: 10.5px;
  color: var(--ink-muted);
  line-height: 1.5;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-subtle);
  margin: 0;
  flex-shrink: 0;
}

/* Map Area & Overlays */
.mapwrap {
  position: relative;
  min-height: 0;
}

#map {
  height: 100%;
  width: 100%;
  background: #dde5ed;
}

.legend {
  position: absolute;
  z-index: 450;
  left: 12px;
  top: 52px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--ink-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

/* Bottom Telemetry & Controls Console */
.controls {
  position: absolute;
  z-index: 990;
  left: 16px;
  right: 16px;
  bottom: 16px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border-strong);
  padding: 10px 14px 10px;
  border-radius: 6px;
  max-width: 860px;
  margin: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.control-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
}

.control-top strong {
  font-weight: 600;
  color: var(--ink-primary);
}

.timestamp {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
  font-size: 11.5px;
  font-weight: 500;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

button.play-btn {
  border: 1px solid var(--ink-primary);
  border-radius: 3px;
  background: var(--ink-primary);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 12px;
  cursor: pointer;
  min-width: 76px;
}

button.play-btn:hover {
  background: #252f3d;
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--signal-blue);
  height: 4px;
  cursor: pointer;
}

.point-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 68px;
  text-align: right;
}

.leaflet-popup-content {
  font-family: var(--font-sans);
  font-size: 11.5px;
  line-height: 1.6;
}

/* Map Top Toolbar & Layer Toggles */
.map-top-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-hairline);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.map-pill-btn {
  background: transparent;
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-secondary);
  padding: 4px 9px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.map-pill-btn:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

.map-pill-btn.active {
  background: var(--bg-active);
  border-color: var(--border-strong);
  color: var(--signal-blue);
  font-weight: 600;
}

/* Integrated Speed Profile Sub-panel */
.speed-profile-box {
  border-bottom: 1px solid var(--border-hairline);
  padding-bottom: 8px;
  margin-bottom: 8px;
  transition: all 0.2s ease;
}

.speed-profile-box.collapsed .speed-canvas-wrap {
  display: none;
}
.speed-profile-box.collapsed {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 4px;
}

.speed-profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.speed-profile-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
}

.speed-canvas-wrap {
  width: 100%;
  height: 54px;
  position: relative;
  cursor: crosshair;
}

.speed-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}
  margin-bottom: 4px;
}

.speed-profile-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
}

.speed-canvas-wrap {
  width: 100%;
  height: 72px;
  position: relative;
  cursor: crosshair;
}

.speed-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.btn-xs-icon {
  background: none;
  border: 1px solid transparent;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
}
.btn-xs-icon:hover {
  background: var(--bg-hover);
  color: var(--ink-primary);
}

/* Multi-Trip Comparison Card */
.comparison-panel {
  display: none;
  background: #f8fafc;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 10px;
  margin-top: 10px;
  font-size: 11px;
}

.comparison-panel.active {
  display: block;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}

.comparison-stat {
  background: #ffffff;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-hairline);
}
.comparison-stat small {
  display: block;
  font-size: 9.5px;
  color: var(--ink-muted);
  text-transform: uppercase;
}
.comparison-stat b {
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--ink-primary);
}

/* Anomaly Badges */
.badge-anomaly-ok {
  background: #def7ec;
  color: #03543f;
  border: 1px solid #bcf0da;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
}

.badge-anomaly-warn {
  background: #fef08a;
  color: #854d0e;
  border: 1px solid #fde047;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}

/* Print Stylesheet for Executive Voyage Report */
@media print {
  body {
    overflow: visible !important;
    background: #ffffff !important;
    font-size: 11pt !important;
  }
  .map-top-bar,
  .controls,
  .panel-header .nav-link,
  .drawer-toggle-group,
  .drawer,
  .speed-profile-container,
  .mapwrap .legend {
    display: none !important;
  }
  .shell {
    display: block !important;
    height: auto !important;
  }
  aside {
    border-right: none !important;
    height: auto !important;
    width: 100% !important;
  }
  .mapwrap {
    height: 380px !important;
    page-break-after: avoid;
    border: 1px solid #000000;
    margin-top: 15px;
  }
  #map {
    height: 100% !important;
  }
  .ais-table-wrap {
    max-height: 400px !important;
    overflow: visible !important;
  }
}

@media (max-width: 820px) {
  body {
    overflow-y: auto;
  }
  .shell {
    display: block;
    height: auto;
  }
  aside {
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-hairline);
    overflow: visible;
  }
  .table-section {
    flex: none;
    min-height: 0;
    height: auto;
    padding: 10px 14px;
  }
  .ais-table-wrap {
    flex: none;
    height: 300px;
    max-height: 45vh;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }
  .mapwrap {
    height: 75dvh;
    min-height: 440px;
  }
  .controls {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 8px 10px;
  }
}
