/* ════════════════════════════════════════════════════════════════════════════
 * CONTAINER FIT 3D — Apple-Inspired Minimalist UI
 * Design System: Clean whites, soft grays, muted blue accent, generous spacing
 * ════════════════════════════════════════════════════════════════════════════ */

/* ── Google Fonts ──────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-app:        #f5f5f7;
  --bg-panel:      #ffffff;
  --bg-panel-alt:  #f9f9f9;

  /* Borders */
  --border-light:  #e5e5e5;
  --border-medium: #d1d1d6;

  /* Text */
  --text-primary:   #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted:     #aeaeb2;

  /* Accent — muted Apple blue */
  --accent-primary: #0071e3;
  --accent-hover:   #0077ed;
  --accent-soft:    #e8f1fd;
  --accent-glow:    rgba(0,113,227,0.18);

  /* Status */
  --status-success: #34c759;
  --status-success-text: #1a7734;
  --status-warning: #ff9f0a;
  --status-warning-text: #7d4e00;
  --status-error:   #ff3b30;
  --status-error-text: #8b1a14;

  /* Panel dimensions */
  --panel-width:    320px;
  --topbar-h:       34px;
  --panel-radius:   0px;
  --shadow-panel:   0 2px 20px rgba(0,0,0,0.07);
  --transition:     0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, 'Inter', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-primary); color: #fff; }

/* ════════════════════════════════════════════════════════════════════════════
 * TOPBAR
 * ════════════════════════════════════════════════════════════════════════════ */
#topbarStatus {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: var(--topbar-h);
  background: rgba(255,255,255,0.88);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.1px;
  z-index: 300;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
}

#topbarStatus .topbar-item { display: inline-flex; align-items: center; gap: 3px; }
#topbarStatus .topbar-sep  { color: var(--border-medium); margin: 0 6px; user-select: none; }
#topbarStatus .topbar-label{ color: var(--text-muted); }
#topbarStatus .topbar-value{ color: var(--text-primary); font-weight: 600; }

/* ════════════════════════════════════════════════════════════════════════════
 * LAYOUT — scene + left/right panels
 * ════════════════════════════════════════════════════════════════════════════ */
#scene-container {
  position: fixed;
  top: var(--topbar-h);
  left: var(--panel-width);
  right: var(--panel-width);
  bottom: 0;
  background: radial-gradient(ellipse at 40% 30%, #f0f4f8, #e4eaf0 70%, #dde4ec);
  transition: left var(--transition), right var(--transition);
  z-index: 0;
}

/* Left panel collapsed */
body.left-collapsed   #scene-container { left: 0; }
body.left-collapsed   #control-panel   { transform: translateX(calc(-1 * var(--panel-width))); }
body.left-collapsed   #left-panel-toggle { left: 0; }

/* Right panel collapsed */
body.right-collapsed  #scene-container { right: 0; }
body.right-collapsed  #results-panel   { transform: translateX(var(--panel-width)); }
body.right-collapsed  #right-panel-toggle { right: 0; }

/* Both collapsed — used when bottom table opens */
body.cargo-table-open #scene-container  { left: 0; right: 0; }
body.cargo-table-open #control-panel    { transform: translateX(calc(-1 * var(--panel-width))); }
body.cargo-table-open #results-panel    { transform: translateX(var(--panel-width)); }
body.cargo-table-open #cargoTablePanel  { left: 0; right: 0; }
body.cargo-table-open #actionPanel      { max-width: calc(100% - 20px); }
body.cargo-table-open #left-panel-toggle  { left: 0; }
body.cargo-table-open #right-panel-toggle { right: 0; }

/* ════════════════════════════════════════════════════════════════════════════
 * PANELS — shared styles for left & right
 * ════════════════════════════════════════════════════════════════════════════ */
#control-panel,
#results-panel {
  position: fixed;
  top: var(--topbar-h);
  width: var(--panel-width);
  height: calc(100vh - var(--topbar-h));
  background: var(--bg-panel);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 24px;
  z-index: 100;
  transition: transform var(--transition);
  box-shadow: var(--shadow-panel);
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

#control-panel { left: 0; border-right: 1px solid var(--border-light); }
#results-panel { right: 0; border-left: 1px solid var(--border-light); }

#control-panel::-webkit-scrollbar,
#results-panel::-webkit-scrollbar { width: 4px; }
#control-panel::-webkit-scrollbar-thumb,
#results-panel::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* ── Panel collapse button ───────────────────────────────────────────── */
.panel-collapse-btn {
  position: fixed;
  top: 50vh;
  transform: translateY(-50%);
  width: 20px;
  height: 48px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  transition: color var(--transition), background var(--transition), left var(--transition), right var(--transition), opacity var(--transition);
  box-shadow: 2px 0 8px rgba(0,0,0,0.06);
  padding: 0;
  line-height: 1;
}
.panel-collapse-btn:hover { background: var(--accent-soft); color: var(--accent-primary); }

#left-panel-toggle {
  left: var(--panel-width);
  border-radius: 0 8px 8px 0;
  border-left: none;
  transition: left var(--transition), color var(--transition), background var(--transition), opacity var(--transition);
}
body.left-collapsed #left-panel-toggle  { left: 0; }

/* Make the small panel toggle match primary CTA blue */
#left-panel-toggle {
  background: var(--accent-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 12px var(--accent-glow);
}
#left-panel-toggle:hover {
  background: var(--accent-hover);
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.panel-collapse-btn-right {
  right: var(--panel-width);
  left: auto;
  border-radius: 8px 0 0 8px;
  border-right: none;
  box-shadow: -2px 0 8px rgba(0,0,0,0.06);
  transition: right var(--transition), color var(--transition), background var(--transition), opacity var(--transition);
}
body.right-collapsed .panel-collapse-btn-right { right: 0; }

/* Make the right panel collapse tab match primary CTA blue */
#right-panel-toggle,
.panel-collapse-btn-right {
  background: var(--accent-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 12px var(--accent-glow);
}
#right-panel-toggle:hover,
.panel-collapse-btn-right:hover {
  background: var(--accent-hover);
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}

/* ── Panel header ────────────────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.1px;
}

/* ── Section labels ──────────────────────────────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 8px;
  margin-top: 16px;
}
.section-label:first-of-type { margin-top: 0; }

/* ════════════════════════════════════════════════════════════════════════════
 * ACTION PANEL — floating top-right pill toolbar
 * ════════════════════════════════════════════════════════════════════════════ */
#actionPanel {
  position: fixed;
  top: calc(var(--topbar-h) + 10px);
  right: calc(var(--panel-width) + 12px);
  display: flex;
  gap: 5px;
  z-index: 150;
  flex-wrap: wrap;
  max-width: calc(100% - var(--panel-width) * 2 - 28px);
  transition: right var(--transition), max-width var(--transition);
}
body.right-collapsed #actionPanel { right: 12px; max-width: calc(100% - var(--panel-width) - 24px); }
body.left-collapsed  #actionPanel { max-width: calc(100% - var(--panel-width) - 24px); }

#actionPanel button {
  padding: 5px 12px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
#actionPanel button:hover {
  background: #fff;
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: 0 2px 10px var(--accent-glow);
}
#actionPanel button:active { transform: scale(0.97); }
#actionPanel #btnClear { color: var(--status-error-text); }
#actionPanel #btnClear:hover {
  border-color: var(--status-error);
  color: var(--status-error-text);
  background: #fff5f4;
  box-shadow: 0 2px 10px rgba(255,59,48,0.15);
}

/* ════════════════════════════════════════════════════════════════════════════
 * MODE TOGGLE
 * ════════════════════════════════════════════════════════════════════════════ */
.mode-toggle { display: flex; gap: 5px; margin-bottom: 14px; }

.mode-btn {
  flex: 1;
  padding: 7px 10px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px; font-weight: 500;
  cursor: pointer; border-radius: 8px;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.mode-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.mode-btn.active {
  background: var(--accent-primary);
  color: #fff; border-color: transparent;
  font-weight: 600;
}

/* PRO mode toggle */
.pro-mode-row  { margin-top: 0; margin-bottom: 12px; }
.pro-mode-btn  {
  padding: 8px 12px;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.1px;
  transition: background var(--transition), box-shadow var(--transition), transform 0.08s;
}
.pro-mode-btn:hover { background: var(--accent-hover); box-shadow: 0 3px 12px var(--accent-glow); }
.pro-mode-btn:active { transform: scale(0.98); }
.pro-mode-btn.active {
  background: var(--accent-primary);
  color: #fff; border-color: transparent;
}

/* ════════════════════════════════════════════════════════════════════════════
 * FORM GROUPS & INPUTS
 * ════════════════════════════════════════════════════════════════════════════ */
.form-group {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group select,
.form-group input[type="number"],
.form-group input[type="text"] {
  padding: 6px 8px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  border-radius: 8px;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none;
  -webkit-appearance: none;
}
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236e6e73' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group input.input-error {
  border-color: var(--status-error) !important;
  background: #fff5f4;
}

/* Checkbox group */
.form-group.checkbox-group {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.form-group.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  cursor: pointer;
  flex: 1;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 400;
}
.form-group.checkbox-group input[type="checkbox"] {
  width: auto;
  cursor: pointer;
  margin: 0; padding: 0;
  accent-color: var(--accent-primary);
}

.form-help {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 3px;
  line-height: 1.4;
}
#container-manual-group .form-group { margin-bottom: 7px; }

/* ════════════════════════════════════════════════════════════════════════════
 * CARGO CONTROLS & ACCORDION
 * ════════════════════════════════════════════════════════════════════════════ */
#cargo-controls { margin-bottom: 10px; }

#add-cargo-btn {
  width: 100%;
  padding: 8px 12px;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
  transition: background var(--transition), box-shadow var(--transition);
}
#add-cargo-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 3px 12px var(--accent-glow);
}
#add-cargo-btn:active { transform: scale(0.98); }

/* File actions */
.cargo-file-actions { display: flex; gap: 6px; margin-bottom: 6px; }
#download-template-btn,
#upload-cargo-btn {
  flex: 1;
  padding: 6px 8px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  border-radius: 7px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
#download-template-btn:hover,
#upload-cargo-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-soft);
}

/* Cargo accordion list */
#cargo-list { margin-bottom: 10px; }

.cargo-item {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg-panel);
  overflow: hidden;
}
.cargo-item + .cargo-item { margin-top: 0; }

.cargo-item summary {
  padding: 6px 10px;
  background: var(--bg-panel-alt);
  cursor: pointer;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  list-style: none;
  transition: background var(--transition), color var(--transition);
}
.cargo-item summary::-webkit-details-marker { display: none; }
.cargo-item summary:hover { background: var(--accent-soft); color: var(--accent-primary); }
.cargo-item[open] summary {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border-light);
  color: var(--accent-primary);
}

.cargo-color-swatch {
  display: inline-block !important;
  width: 10px; height: 10px;
  margin-left: 8px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 3px;
  vertical-align: middle;
  flex-shrink: 0;
}

.cargo-item details > :not(summary),
.cargo-item[open] > *:not(summary) { padding: 8px 10px; }
.cargo-item .form-group {
  margin-bottom: 6px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.cargo-item .form-group:last-of-type { margin-bottom: 0; }

/* Inline labels + inputs inside cargo cards to save vertical space */
.cargo-item .form-group label {
  width: 36%;
  margin-bottom: 0;
  font-size: 12px;
  color: var(--text-secondary);
}
.cargo-item .form-group select,
.cargo-item .form-group input[type="number"],
.cargo-item .form-group input[type="text"] {
  flex: 1;
  min-width: 0;
}
.cargo-item .form-group.checkbox-group {
  flex-direction: row;
  justify-content: space-between;
  gap: 8px;
}

@media (max-width: 420px) {
  .cargo-item .form-group {
    flex-direction: column;
    align-items: stretch;
  }
  .cargo-item .form-group label { width: auto; margin-bottom: 4px; }
}

.remove-cargo-btn {
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--status-error-text);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.remove-cargo-btn:hover {
  background: #fff5f4;
  border-color: var(--status-error);
}

/* ════════════════════════════════════════════════════════════════════════════
 * PRIMARY CTA BUTTONS
 * ════════════════════════════════════════════════════════════════════════════ */
#calculate-btn,
#pallet-calculate-btn,
#exportPdfBtn {
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  transition: background var(--transition), box-shadow var(--transition), transform 0.1s;
}
#pallet-calculate-btn {
  background: var(--accent-primary);
  color: #fff;
}
#pallet-calculate-btn:hover { background: var(--accent-hover); box-shadow: 0 4px 14px var(--accent-glow); }

#exportPdfBtn {
  background: var(--bg-panel-alt);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
#exportPdfBtn:hover { background: var(--accent-soft); border-color: var(--accent-primary); color: var(--accent-primary); }
#exportPdfBtn:disabled { opacity: 0.5; cursor: not-allowed; }

#calculate-btn {
  background: var(--bg-panel-alt);
  color: var(--status-error-text);
  border: 1px solid var(--border-light);
}
#calculate-btn:hover { background: #fff5f4; border-color: var(--status-error); }

/* ════════════════════════════════════════════════════════════════════════════
 * FORM MODES
 * ════════════════════════════════════════════════════════════════════════════ */
.mode-form { display: none; }
.mode-form.active { display: block; }

/* ════════════════════════════════════════════════════════════════════════════
 * ERROR MESSAGE
 * ════════════════════════════════════════════════════════════════════════════ */
#error-message {
  background: #fff5f4;
  border: 1px solid #ffccc7;
  color: var(--status-error-text);
  padding: 8px 12px;
  margin-top: 10px;
  font-size: 12px;
  border-radius: 8px;
  font-weight: 500;
}

/* ════════════════════════════════════════════════════════════════════════════
 * RESULT BLOCK (inside right panel)
 * ════════════════════════════════════════════════════════════════════════════ */
#result-block {
  background: transparent;
  margin-top: 0;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-item {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
}
.stat-item-wide {
  grid-column: 1 / -1;
  padding: 10px 14px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 10px;
  margin-bottom: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-value {
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 700;
  font-family: -apple-system, 'SF Pro Display', 'Inter', sans-serif;
  letter-spacing: -0.5px;
}

/* Weight info */
#weight-info {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 12px;
}
.weight-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; color: var(--text-secondary); }
.weight-item:last-child { margin-bottom: 0; }
.weight-label { font-weight: 500; color: var(--text-secondary); }
.weight-value { color: var(--text-primary); font-weight: 700; }

/* Status message */
.status-message {
  text-align: center;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  margin-bottom: 8px;
  line-height: 1.4;
}
.status-message.success {
  background: #f0faf3;
  border: 1px solid #a8d5b5;
  color: var(--status-success-text);
}
.status-message.error {
  background: #fff5f4;
  border: 1px solid #ffccc7;
  color: var(--status-error-text);
}

/* Warnings */
#result-warnings {
  background: #fffbf0;
  border: 1px solid #ffe0a0;
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 8px;
}
.warnings-title { color: var(--status-warning-text); font-size: 10px; font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
#warnings-list { font-size: 11px; color: var(--text-primary); line-height: 1.6; }
#warnings-list > div { margin-bottom: 4px; padding-left: 8px; border-left: 2px solid var(--status-warning); }

/* Cargo result items */
.result-details { margin-top: 6px; }
.result-cargo   { padding: 5px 10px; border-radius: 6px; margin-bottom: 4px; font-size: 11.5px; font-weight: 500; display: block; }
.result-cargo.cargo-success { background: #f0faf3; color: var(--status-success-text); border: 1px solid #a8d5b5; }
.result-cargo.cargo-fail    { background: #fff5f4; color: var(--status-error-text);   border: 1px solid #ffccc7; }

/* Stat subitem (for wide card) */
.stat-subitem {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
  line-height: 1;
  gap: 8px;
}
.stat-subitem:last-child { border-bottom: none; padding-bottom: 0; }
.stat-subitem:first-child { padding-top: 0; }
.stat-subitem .stat-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.stat-subitem .stat-value {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}
.stat-unit { color: var(--text-muted); font-size: 11px; margin-left: 2px; }

/* ── Axle balance button ─────────────────────────────────────────────── */
.axle-actions-row { display: flex; gap: 6px; }
#axle-balance-btn {
  width: 100%;
  padding: 7px 12px;
  background: #5e35b1;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
}
#axle-balance-btn:hover { background: #512da8; box-shadow: 0 4px 14px rgba(94,53,177,0.3); }

#axle-debug-panel {
  font-family: inherit;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
}

/* ════════════════════════════════════════════════════════════════════════════
 * CARGO TABLE PANEL — bottom collapsible
 * ════════════════════════════════════════════════════════════════════════════ */
#cargoTablePanel {
  position: fixed;
  bottom: 0;
  left: var(--panel-width);
  right: var(--panel-width);
  z-index: 120;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-light);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
  max-height: 32vh;
  display: flex;
  flex-direction: column;
  transition: left var(--transition), right var(--transition);
  border-radius: 12px 12px 0 0;
}

#cargoTableToggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg-panel-alt);
  border-bottom: 1px solid var(--border-light);
  user-select: none;
  flex-shrink: 0;
  border-radius: 12px 12px 0 0;
  transition: background var(--transition), color var(--transition);
}
#cargoTableToggle:hover { background: var(--accent-soft); color: var(--accent-primary); }

#cargoTableArrow { font-size: 10px; color: var(--text-muted); transition: transform 0.2s; }
#cargoTablePanel.collapsed #cargoTableWrapper { display: none; }
#cargoTablePanel.collapsed #cargoTableArrow   { transform: rotate(-90deg); }
#cargoTableWrapper { overflow-y: auto; flex: 1; }
#cargoTableWrapper::-webkit-scrollbar { width: 4px; }
#cargoTableWrapper::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* Stretch cargo table panel to fill freed space when side panels are collapsed */
body.left-collapsed  #cargoTablePanel { left: 0; }
body.right-collapsed #cargoTablePanel { right: 0; }

/* ── Cargo table ─────────────────────────────────────────────────────── */
#cargoTable { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
#cargoTable thead { position: sticky; top: 0; z-index: 1; }

#cargoTable th {
  background: var(--bg-panel-alt);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 6px 4px;
  text-align: center;
  border-bottom: 1px solid var(--border-light);
}
#cargoTable td {
  padding: 5px 3px;
  text-align: center;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
#cargoTable tbody tr { transition: background var(--transition); }
#cargoTable tbody tr:hover { background: var(--accent-soft); }
#cargoTable tbody tr.cargo-row-selected {
  background: var(--accent-soft);
  color: var(--accent-primary);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent-primary);
}

.cargo-tbl-color {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
  vertical-align: middle;
  margin-right: 3px;
}
.cargo-tbl-input {
  width: 100%; max-width: 56px;
  padding: 3px 2px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  text-align: center;
  background: transparent;
  color: var(--text-primary);
  transition: border-color var(--transition), background var(--transition);
  box-sizing: border-box;
}
.cargo-tbl-input:hover { border-color: var(--accent-primary); background: var(--accent-soft); }
.cargo-tbl-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.cargo-tbl-check { cursor: pointer; accent-color: var(--accent-primary); }
.cargo-tbl-del {
  padding: 2px 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.cargo-tbl-del:hover { color: var(--status-error-text); background: #fff5f4; border-color: #ffccc7; }

/* Column widths */
#cargoTable th:nth-child(1) { width: 36px; }
#cargoTable th:nth-child(2),
#cargoTable th:nth-child(3),
#cargoTable th:nth-child(4) { width: 56px; }
#cargoTable th:nth-child(5) { width: 64px; }
#cargoTable th:nth-child(6) { width: 48px; }
#cargoTable th:nth-child(7) { width: 40px; }
#cargoTable th:nth-child(8) { width: 36px; }

/* ════════════════════════════════════════════════════════════════════════════
 * TUTORIAL MODAL
 * ════════════════════════════════════════════════════════════════════════════ */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(0,0,0,0.40);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 1;
  transition: opacity 0.25s ease;
}
.tutorial-overlay.tutorial-hidden { opacity: 0; pointer-events: none; }

.tutorial-modal {
  position: relative;
  background: var(--bg-panel);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 2px 12px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(0);
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.tutorial-overlay.tutorial-hidden .tutorial-modal { transform: translateY(16px); }

.tutorial-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 28px; height: 28px;
  border: none;
  background: var(--bg-panel-alt);
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  z-index: 1;
}
.tutorial-close:hover { background: var(--accent-soft); color: var(--accent-primary); }

.tutorial-header {
  padding: 28px 28px 16px;
  text-align: center;
  background: linear-gradient(160deg, var(--accent-soft) 0%, var(--bg-panel) 100%);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.tutorial-logo { font-size: 36px; margin-bottom: 8px; line-height: 1; }
.tutorial-header h2 { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.tutorial-subtitle { font-size: 12px; color: var(--text-secondary); }

.tutorial-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tutorial-body::-webkit-scrollbar { width: 4px; }
.tutorial-body::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.tutorial-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-panel-alt);
  border-radius: 10px;
  border: 1px solid var(--border-light);
  transition: border-color var(--transition);
}
.tutorial-step:hover { border-color: var(--accent-primary); }
.tutorial-step-icon { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; margin-top: 1px; }
.tutorial-step > div { flex: 1; min-width: 0; }
.tutorial-step strong { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.tutorial-step p { font-size: 11.5px; color: var(--text-secondary); line-height: 1.5; margin: 0; }

/* ════════════════════════════════════════════════════════════════════════════
 * FREIGHT CALCULATOR MODAL
 * ════════════════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(0,0,0,0.40);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-dialog {
  position: relative;
  background: var(--bg-panel);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 2px 12px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.modal-close-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.modal-close-btn:hover { color: var(--text-primary); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.modal-footer {
  border-top: 1px solid var(--border-light);
  padding: 12px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.freight-cargo-item {
  display: grid;
  grid-template-columns: 70px minmax(120px,1.4fr) 160px 120px;
  gap: 8px;
  align-items: center;
  padding: 9px 12px;
  background: var(--bg-panel-alt);
  border-radius: 0 4px 4px 0;
  border-left: 4px solid #4a90e2;
  font-size: 12px;
  line-height: 1.4;
}
.freight-cargo-item > div:last-child { text-align: right; }

.freight-cargo-item strong { color: var(--text-primary); font-weight: 600; }

.tutorial-footer { padding: 14px 20px 18px; border-top: 1px solid var(--border-light); text-align: center; flex-shrink: 0; }
.tutorial-ok-btn {
  display: inline-block;
  padding: 9px 28px;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
}
.tutorial-ok-btn:hover { background: var(--accent-hover); box-shadow: 0 4px 14px var(--accent-glow); }

/* ════════════════════════════════════════════════════════════════════════════
 * AXLE DEBUG PANEL (PRO mode)
 * ════════════════════════════════════════════════════════════════════════════ */
.axle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 12.5px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
  gap: 8px;
  flex-wrap: wrap;
}
.axle-status-ok   { color: var(--status-success-text); }
.axle-status-warn { color: var(--status-error-text); }
.axle-profile-name { font-size: 10px; font-weight: 400; color: var(--text-muted); }

.axle-summary-row {
  display: flex;
  gap: 10px 14px;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.axle-row {
  display: grid;
  grid-template-columns: 66px minmax(90px,1fr) minmax(120px,1fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  width: 100%;
}
.axle-lbl { font-size: 11.5px; font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.axle-bar-wrap { background: var(--border-light); border-radius: 4px; height: 8px; overflow: hidden; }
.axle-bar { height: 100%; border-radius: 4px; display: block; transition: width 0.3s; }
.axle-bar-ok   { background: var(--status-success); }
.axle-bar-warn { background: var(--status-warning); }
.axle-bar-over { background: var(--status-error); }
.axle-nums {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.axle-pct      { color: var(--text-muted); }
.axle-pct-over { color: var(--status-error-text); font-weight: 700; }
.axle-badge-over {
  display: inline-block;
  padding: 1px 4px;
  background: var(--status-error);
  color: #fff;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.axle-hint { margin-top: 6px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border-light); padding-top: 5px; }
.axle-already-ok { margin-top: 5px; font-size: 11.5px; color: var(--status-success-text); font-weight: 600; }

/* ── CARGO LOTS ────────────────────────────────────────────────────── */
.lot-card {
  border: 1px solid var(--border-light);
  border-radius: 4px;
  margin-bottom: 8px;
  overflow: hidden;
}
.lot-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: var(--bg-panel-alt);
  border-bottom: 1px solid var(--border-light);
}
.lot-card-name { font-size: 12px; font-weight: 600; }
.lot-card-body { padding: 6px 10px; font-size: 11px; color: var(--text-secondary); line-height: 1.6; }
.lot-card-btn {
  font-size: 11px;
  padding: 2px 7px;
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.5;
}
.lot-card-btn:hover { background: #e0e0e0; }
.lot-card-btn-del { color: #d32f2f; }
.lot-add-btn {
  width: 100%;
  padding: 9px;
  background: none;
  border: 2px dashed #4a90e2;
  border-radius: 4px;
  color: #4a90e2;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
  margin-top: 4px;
}
.lot-add-btn:hover { background: rgba(74,144,226,0.06); }
.lot-editor {
  border: 1px solid #4a90e2;
  border-radius: 4px;
  padding: 12px;
  background: #f8f9ff;
  margin-top: 8px;
}
.lot-assign-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 4px;
}
.lot-assign-table th {
  text-align: left;
  padding: 5px 8px;
  background: #e8e8e8;
  border-bottom: 1px solid #ccc;
  font-weight: 600;
}
.lot-assign-table td { padding: 5px 8px; border-bottom: 1px solid #f0f0f0; }
.lot-compact-row {
  font-size: 11px;
  padding: 4px 8px;
  color: var(--text-muted);
  border-left: 3px solid var(--border-medium);
  margin-bottom: 4px;
  border-radius: 0 3px 3px 0;
}
.lot-unalloc-banner {
  margin-bottom: 10px;
  padding: 7px 10px;
  background: #fff8e1;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid #ffe082;
}
#btnDistributeLots:not([disabled]) { opacity: 1 !important; }

/* freight grid when showing lots */
.freight-lot-item {
  display: grid;
  grid-template-columns: 70px minmax(120px,1.4fr) 160px 120px;
  gap: 8px;
  align-items: center;
  padding: 9px 12px;
  border-left: 4px solid #ff9800;
  font-size: 12px;
  line-height: 1.4;
  background: #fffcf5;
  border-radius: 0 4px 4px 0;
}
.freight-lot-item strong { font-weight: 600; }
.freight-lot-item > div:last-child { text-align: right; }

