/* ==========================================================
   GLOBAL PAGE SETTINGS
   ========================================================== */

/* Colours: one place to change them (and the hook for a dark theme later) */
:root {
  --bg: #fff;
  --card: #fff;
  --border: #e3e7ec;
  --text: #183554;
  --control-h: 34px;   /* height shared by dropdowns, buttons and More menus */
  --toolbar-bg: #eef3f8;  /* light navy tint for toolbars */
}

/* Uniform control size: every button and More menu matches the dropdowns */
#refresh-button,
#download-button,
#download-confirm-button,
#export-download-button,
.modal-secondary-button,
.detail-nav button,
.more-menu > summary {
  height: var(--control-h);
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  font-size: 13px;
  line-height: 1;
}

/* Base page style */
body {
  font-family: Arial, sans-serif;   /* global font */
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  overflow-x: hidden;
  overflow-y: hidden;               /* keep the page chrome fixed while the plot area scrolls */
}

html,
body {
  height: 100%;
}

/* Dash container wrapper */
._dash-container {
  max-width: 1400px;                /* center content with max width */
  margin: auto;
  padding: 0 6px;                   /* no top/bottom gap: header and footer sit flush */
  box-sizing: border-box;
}

.dashboard-shell {
  height: 100vh;
  height: 100dvh;                   /* exact visible height where supported */
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Headings */
h1, h2, h3 {
  color: #183554;                   /* WHOI dark blue */
}


/* ==========================================================
   FLEX LAYOUT UTILITIES
   ========================================================== */

/* Horizontal layout */
.flex-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: stretch;
  width: 100%;
  box-sizing: border-box;
}

/* Vertical layout */
.flex-col {
  display: flex;
  flex-direction: column;
}


/* ==========================================================
   PANELS & CARDS
   ========================================================== */

/* Generic control panel: white with a thin border, no grey fill */
.panel {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  box-sizing: border-box;
}

/* Information cards (right panel) */
.card {
  background-color: var(--card);
  border-radius: 6px;
  padding: 10px;
}


/* ==========================================================
   HEADER + FOOTER (FULL WIDTH BARS)
   ========================================================== */

/* Shared header/footer layout */
.header-top,
.header-sub,
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;

  width: 100vw;                     /* stretch across full browser width */
  margin-left: calc(50% - 50vw);    /* escape Dash container centering */

  padding: 6px 24px;
  box-sizing: border-box;
}

/* Top dark banner */
.header-top {
  background-color: #183554;
  box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

/* Secondary white header */
.header-sub {
  background-color: #fff;
  padding: 4px 24px;
  margin-bottom: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Main title */
.header-title {
  color: #183554;
  font-size: 22px;
  font-weight: bold;
  white-space: nowrap;
  text-decoration: none;
}

.header-title:hover {
  text-decoration: underline;
}

.control-hint {
  font-size: 11px;
  color: #5a6b7b;
  margin-bottom: 2px;
}

/* Footer bar */
.footer {
  background-color: #183554;
  color: white;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 8px 24px;
  font-size: 13px;
  line-height: 1.25;
  box-shadow: 0 -2px 4px rgba(0,0,0,0.1);
}

/* Credit text wraps on narrow screens; links stay together on the right. */
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  white-space: nowrap;
}

.footer a {
  color: #fff;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Hover shows the developers (citation authors) and the other contributors. */
.footer-contributors {
  text-decoration: underline dotted;
  cursor: help;
}


/* ==========================================================
   BUTTONS
   ========================================================== */

button {
  font-size: 14px;
  padding: 6px 10px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  color: #fff;
  transition: background-color 0.2s ease;
}

/* Refresh / reset button style: grey, so it reads as secondary to Download */
#refresh-button {
  background-color: #6c757d;
  margin-bottom: 6px;
}

#refresh-button:hover {
  background-color: #565e64;
}


/* ==========================================================
   FORM LABELS & INPUT FIELDS
   ========================================================== */

/* Section titles */
.section-label {
  font-weight: bold;
  font-size: 18px;
  color: #183554;
  margin-bottom: 6px;
}

/* Field labels */
label {
  font-size: 13px;
  color: #183554;
}

/* Input boxes */
input[type="number"],
input[type="text"],
input[type="email"],
select {
  font-size: 13px;
  width: 100%;
  padding: 4px;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-sizing: border-box;
}


/* ==========================================================
   PLOT CONTAINERS
   ========================================================== */

/* Each plot sits in a card with a one-line toolbar above it */
.plot-card {
  flex: 0 0 auto;
  max-width: 100%;
  margin-bottom: 0;
  padding: 8px;
}

/* Cruise track and transect take a full row */
.plot-card-wide {
  flex-basis: 100%;
}

/* T-S and profile share a row, wrapping only when the plots can't fit */
.plot-card:not(.plot-card-wide) {
  flex: 1 1 516px;
  min-width: 0;
}

.plot-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  /* full card width, tinted to stand apart from the plot */
  margin: -8px -8px 6px;
  padding: 6px 8px;
  background-color: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
}

.plot-toolbar .section-label {
  margin-bottom: 0;
  font-size: 16px;
  white-space: nowrap;
}

.toolbar-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-field label {
  white-space: nowrap;
}

.toolbar-control {
  width: 160px;
}

.toolbar-control-narrow {
  width: 120px;
}

.toolbar-control:has(.toolbar-radio) {
  width: auto;
}

.toolbar-radio {
  display: flex;
  gap: 10px;
  font-size: 13px;
  color: #183554;
}

.toolbar-radio label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.toolbar-check label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* Secondary options: popover that floats over the plot */
.more-menu {
  position: relative;
  margin-left: auto;
}

/* Export button sits at the right edge, just before More */
.export-open-button {
  margin-left: auto;
  height: var(--control-h);
  box-sizing: border-box;
  padding: 0 10px;
  font-size: 13px;
  line-height: 1;
  color: #183554;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 5px;
  cursor: pointer;
}

.export-open-button:hover {
  background-color: #e8eef5;
}

.export-open-button + .more-menu {
  margin-left: 8px;
}

.export-status {
  min-height: 18px;
  margin-top: 6px;
  font-size: 12px;
  color: #183554;
}

.more-menu > summary {
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  color: #183554;
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background-color: #fff;
  user-select: none;
}

.more-menu > summary::-webkit-details-marker {
  display: none;
}

.more-menu[open] > summary {
  background-color: #e8eef5;
}

.more-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  width: 340px;
  padding: 10px;
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  box-sizing: border-box;
}

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

.range-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 4px;
}

.range-sep {
  color: #183554;
  font-size: 13px;
}


/* ==========================================================
   PANEL WIDTH STRUCTURE
   ========================================================== */

/* Main plot/control workspace */
.global-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: #fff;
  padding-bottom: 2px;
}

.global-panel {
  display: block;
  padding: 6px 8px;
  margin-bottom: 0;
  background-color: var(--toolbar-bg);
}

.global-panel .section-label {
  display: block;
  margin-bottom: 8px;
}

.global-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 145px));
  align-items: end;
  gap: 10px;
}

/* DATA title, Dataset, Data file, Download ... More, Refresh
   (right corner), on one centred row with labels beside their dropdowns */
.global-panel .global-fields {
  grid-template-columns:
    auto
    minmax(200px, 320px)
    minmax(200px, 320px)
    auto
    1fr
    auto;
  align-items: center;
}

.global-panel .global-fields > .section-label {
  margin-bottom: 0;
  font-size: 16px;
  white-space: nowrap;
}

.global-panel .control-field {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0;
}

.global-panel .control-field > :not(label) {
  flex: 1 1 auto;
  min-width: 0;
}

.global-more {
  align-self: center;
  justify-self: end;
}

.global-more .more-panel {
  width: 460px;   /* two columns wide enough for the dropdowns */
}

/* Two columns of fields inside a More popover */
.more-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
}

/* Square icon-only refresh button, same height as the dropdowns */
#refresh-button {
  align-self: center;
  justify-self: start;
  width: var(--control-h);
  min-width: 0;
  padding: 0;
  margin-bottom: 0;
  font-size: 18px;
}

.global-panel label {
  font-size: 13px;
  white-space: nowrap;
}

#download-button {
  align-self: center;
  justify-self: start;
  width: auto;
  min-width: 110px;
  background-color: #007bff;
  margin-bottom: 0;
}

#download-button:hover {
  background-color: #0056b3;
}

#download-button:disabled {
  background-color: #8a9690;
  cursor: not-allowed;
}

#download-confirm-button,
#export-download-button {
  background-color: #007bff;
  color: #fff;
}

#download-confirm-button:hover,
#export-download-button:hover {
  background-color: #0056b3;
}

#download-confirm-button:disabled {
  background-color: #8a9690;
  cursor: not-allowed;
}

.download-status {
  min-height: 15px;
  margin-top: 2px;
  font-size: 11px;
  color: #b00020;
}

.download-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0,0,0,0.35);
}

.download-modal-backdrop.hidden {
  display: none;
}

.download-modal {
  width: min(420px, calc(100vw - 32px));
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.25);
  padding: 14px;
  box-sizing: border-box;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

#export-modal-backdrop .download-modal {
  width: min(1040px, calc(100vw - 32px));
}

.download-modal-header,
.download-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.download-modal-header {
  margin-bottom: 10px;
}

.download-modal-title {
  font-size: 16px;
  font-weight: bold;
  color: #183554;
}

.download-modal-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.modal-close-button,
.modal-secondary-button {
  background-color: #6c757d;
}

.modal-close-button {
  min-width: 32px;
  padding: 4px 8px;
}

.modal-close-button:hover,
.modal-secondary-button:hover {
  background-color: #5c636a;
}

/* Global controls on top, plot/details area fills the rest. */
.dashboard-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Plots scroll on the left; Details stays in view on the right. */
.dashboard-body {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  gap: 10px;
  overflow: hidden;
  box-sizing: border-box;
}

.plot-workspace {
  flex: 1 1 auto;
  min-width: 0;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
  padding: 2px 4px 10px 2px;
  box-sizing: border-box;
}

.analysis-details {
  flex: 0 0 var(--details-width, 360px);
  min-width: var(--details-width, 360px);
  max-width: var(--details-width, 360px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 10px;
  box-sizing: border-box;
}

/* Default sizes; the W/H options override them inline. */
/* The figure carries its own size, so the box just wraps it. */
.plot-area {
  width: fit-content;
  margin: 0 auto;
}

/* Plot with a side panel (scatter fit summary) */
.plot-body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
}

.plot-body > .plot-area {
  margin: 0;
  min-width: 0;
}

.fit-summary {
  flex: 0 0 230px;
  font-size: 13px;
  line-height: 1.6;
  color: #183554;
  border: 1px solid var(--border);
}

.fit-title {
  font-weight: bold;
  margin-bottom: 4px;
}

.fit-equation {
  margin: 0 0 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.fit-note {
  margin-top: 6px;
  font-size: 12px;
  color: #5a6b7d;
}

.control-field {
  margin-bottom: 6px;
}

/* Right info panel */
.right-panel {
  flex: 0 0 var(--details-width, 360px);
  min-width: var(--details-width, 360px);
  max-width: var(--details-width, 360px);

  font-size: 13px;
  color: #183554;
  line-height: 1.35;

  padding-left: 8px;
}

/* Ring over the Details point on the linked plots (assets/details.js) */
.detail-ring {
  position: absolute;
  z-index: 5;
  width: 18px;
  height: 18px;
  border: 2.5px solid #e00000;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-sizing: border-box;
}

/* Drag handle between the plots and Details (assets/details.js) */
.details-resizer {
  flex: 0 0 6px;
  margin: 0 -2px;
  cursor: col-resize;
  border-radius: 3px;
  transition: background-color 0.15s ease;
}

.details-resizer:hover,
.details-resizer.dragging {
  background-color: #b8c7d9;
}

body.resizing-details {
  cursor: col-resize;
  user-select: none;
}

/* Details title with Prev/Next point buttons */
.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  padding-right: 8px;  /* match the panel's left padding */
}

.detail-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}


.detail-nav button {
  background-color: #007bff;
}

.detail-nav button:hover {
  background-color: #0056b3;
}

/* Camera frame that failed to load (set by assets/details.js) */
.frame-block[data-frame-missing] img {
  display: none;
}

.frame-block[data-frame-missing]::after {
  content: "Frame not available";
  display: block;
  margin-bottom: 12px;
  padding: 10px;
  font-size: 12px;
  color: #5a6b7d;
  text-align: center;
  background-color: var(--card);
  border: 1px dashed var(--border);
  border-radius: 6px;
}

/* Right panel titles */
.right-panel .section-label {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 4px;
}

/* Scrollable data card */
.right-panel .card {
  font-size: 12.5px;
  padding: 6px 8px;
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;

  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}


/* ==========================================================
   RESPONSIVE BEHAVIOR
   ========================================================== */

/* Medium screens */
@media (max-width: 1200px) {

  ._dash-container {
    max-width: 100%;
  }

  .right-panel,
  .analysis-details {
    flex: 0 0 var(--details-width, 300px);
    min-width: var(--details-width, 300px);
    max-width: var(--details-width, 300px);
  }
}

/* Small screens (stack layout) */
@media (max-width: 900px) {

  body {
    overflow-y: auto;
  }

  ._dash-container {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .dashboard-shell {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .flex-row {
    flex-direction: column;
  }

  .right-panel,
  .analysis-details {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-width: 100%;
    padding-left: 0;
  }

  .details-resizer {
    display: none;
  }

  .dataset-panel,
  .options-panel,
  .layout-panel {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }

  .global-panel {
    display: block;
  }

  .global-controls {
    position: static;
  }

  .dashboard-main {
    display: block;
  }

  .dashboard-body {
    flex-direction: column;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .plot-workspace {
    overflow: visible;
  }

  /* Plots fill the screen width; custom W settings apply on wide screens only. */
  .plot-card {
    flex-basis: 100%;
  }

  .more-panel {
    width: min(340px, calc(100vw - 40px));
  }

  .plot-body {
    flex-direction: column;
    align-items: stretch;
  }

  .fit-summary {
    flex-basis: auto;
  }
}


/* ==========================================================
   PLOTLY RENDERING FIX
   ========================================================== */

/* Ensures Plotly plots always fill their container
   after CSS resizing */

/* Multi-panel export: one row per panel, all settings on one line */
.export-panel-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 8px 8px;
  margin-bottom: 8px;
  border: 1px solid #ccd5df;
  border-radius: 6px;
}

.export-panel-letter {
  font-weight: bold;
  font-size: 16px;
  color: #183554;
  padding-bottom: 6px;
}

.export-panel-field {
  flex: 1 1 0;
  min-width: 0;
}

.export-panel-field.export-panel-range {
  flex: 0 0 84px;
}

.export-panel-field.export-panel-range input {
  width: 100%;
  box-sizing: border-box;
}

.export-panel-field label {
  display: block;
  font-size: 12px;
  margin-bottom: 2px;
}

.export-panel-add {
  margin-bottom: 8px;
}

.export-switch label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: bold;
  color: #183554;
  cursor: pointer;
}

.export-switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 21px;
  margin: 0;
  border-radius: 11px;
  background-color: #b8c2cd;
  cursor: pointer;
  transition: background-color 0.15s;
}

.export-switch input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background-color: #fff;
  transition: transform 0.15s;
}

.export-switch input[type="checkbox"]:checked {
  background-color: #1f6fb2;
}

.export-switch input[type="checkbox"]:checked::before {
  transform: translateX(17px);
}

.export-panel-labels {
  flex: 0 0 100%;
  font-size: 12px;
}

.export-panel-labels summary {
  cursor: pointer;
  color: #183554;
}

/* A dot on "Labels" when this panel has custom text */
.export-panel-labels:has(input:not(:placeholder-shown)) summary::after {
  content: " 2";
  color: #1f6fb2;
}

.export-panel-label-fields {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.export-panel-label-fields input {
  width: 100%;
  box-sizing: border-box;
}

/* The page options show only while "Combine panels" is on */
#export-combined-block {
  display: none;
}

#export-modal-backdrop:has(#export-multi input:checked) #export-combined-block {
  display: block;
}
