/* ============================================================
   LSG Lanes — Shared Theme
   Include on every page BEFORE any page-specific styles.
   The <html> element gets data-theme="dark" or data-theme="light"
   by theme.js. Dark is the default / fallback.
   ============================================================ */

/* ── Density tokens (theme-agnostic) ──────────────────────────
   Centralised spacing consumed by shared classes and page-level
   styles. Adjust here to tighten/loosen the entire platform.
   home.html and site-map.html opt out via local overrides. */
:root {
  --d-page-pad:      78px;
  --d-page-pad-y:    32px;
  --d-cell-pad-x:    8px;
  --d-cell-pad-y:    6px;
  --d-card-pad:      10px;
  --d-gap:           8px;
  --d-gap-sm:        5px;
  --d-title-size:    42px;
  --d-filter-pad:    6px;
  --d-input-pad-x:   8px;
  --d-input-pad-y:   6px;
  --d-btn-pad-x:     12px;
  --d-btn-pad-y:     6px;
}

/* ── Dark (default) ───────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --black:           #181818;
  --surface:         #1e1e1e;
  --surface-2:       #242424;
  --surface-3:       #2a2a2a;
  --topbar-bg:       #181818;
  --sidebar-bg:      #181818;
  --border:          rgba(255, 255, 255, 0.06);
  --border-strong:   rgba(255, 255, 255, 0.12);

  --white:           #FCFCFC;
  --text-primary:    #ededed;
  --text-secondary:  rgba(237, 237, 237, 0.78);
  --text-tertiary:   rgba(237, 237, 237, 0.55);
  --text-label:      rgba(237, 237, 237, 0.65);

  --red:             rgb(236, 62, 88, 0.7);
  --red-hover:       rgb(212, 54, 78, 0.7);
  --red-subtle:      rgba(236, 62, 88, 0.08);
  --amber:           rgba(249, 171, 54, 0.7);
  --amber-hover:     rgb(224, 154, 45, 0.7);
  --amber-subtle:    rgba(249, 171, 54, 0.08);
  --green:           rgb(106, 180, 106, 0.7);
  --green-hover:     rgb(94, 163, 94, 0.7);
  --green-subtle:    rgba(100, 180, 100, 0.08);
  --burgundy:        rgb(93, 59, 50, 0.7);
  --svc-warehousing:   rgba(236, 62, 88, 0.7);
  --svc-warehousing-subtle: rgba(236, 62, 88, 0.08);
  --svc-transport: rgba(249, 171, 54, 0.7);
  --svc-transport-subtle: rgba(249, 171, 54, 0.08);

  --table-header:    #1e1e1e;
  --table-row-alt:   rgba(255, 255, 255, 0.03);
  --table-row-bg:    rgb(24, 24, 24);
  --table-row-hover: rgba(24, 24, 24, 0.45);

  --input-bg:        #141414;
  --input-border:    rgba(255, 255, 255, 0.10);
  --input-focus:     rgba(236, 62, 88, 0.5);

  --shadow-sm:       0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md:       0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg:       0 8px 24px rgba(0, 0, 0, 0.6);

  --scrollbar-track: #181818;
  --scrollbar-thumb: #3a3a3a;

  /* Lane type colours — unchanged across themes */
  --lane-box:        #185fa5;
  --lane-curtain:    #EC3E58;
  --lane-reefer:     #854f0b;

  /* Sidebar (Phase 13b) — bg/icon/flyout tokens, theme-specific */
  --sb-bg:           #181818;
  --sb-logo-bg:      #181818;
  --sb-logo-border:  rgba(255, 255, 255, 0.06);
  --sb-icon:         #fcfcfc9b;
  --sb-active-bar:   #EC3E58;
  --sb-flyout-bg:    #1e1e1e;
  --sb-flyout-border: #fcfcfc43;
  --sb-flyout-heading: #fcfcfcd6;
  --sb-flyout-body:    #fcfcfcd6;
  --sb-solo-body:    #fcfcfcd6;

  color-scheme: dark;
}

/* ── Light ────────────────────────────────────────────────── */
[data-theme="light"] {
  --black:           #fcfcfc;
  --surface:         #ffffff;
  --surface-2:       #f5f5f5;
  --surface-3:       #ebebeb;
  --topbar-bg:       #ec3e58;   /* topbar goes light in light mode */
  --sidebar-bg:      #f8f8f8;
  --border:          rgba(0, 0, 0, 0.08);
  --border-strong:   rgba(0, 0, 0, 0.15);

  --white:           #1E1E1E;   /* inverted — "white" now means primary text */
  --text-primary:    #1a1a1a;
  --text-secondary:  rgba(26, 26, 26, 0.6);
  --text-tertiary:   rgba(26, 26, 26, 0.4);
  --text-label:      rgba(26, 26, 26, 0.4);

  --red:             #EC3E58;
  --red-hover:       #d4364e;
  --red-subtle:      rgba(236, 62, 88, 0.10);
  --amber:           #F9AB36;
  --amber-hover:     #e09a2d;
  --amber-subtle:    rgba(249, 171, 54, 0.10);
  --green:           #4a9c4a;
  --green-hover:     #408840;
  --green-subtle:    rgba(74, 156, 74, 0.10);
  --burgundy:        #7a504e;
  --svc-warehousing:   rgb(236, 62, 88);
  --svc-warehousing-subtle: rgba(236, 62, 88, 0.12);
  --svc-transport: rgb(249, 171, 54);
  --svc-transport-subtle: rgba(249, 171, 54, 0.12);

  --table-header:    rgb(211, 205, 205);
  --table-row-alt:   rgba(0, 0, 0, 0.025);
  --table-row-bg:    #fcfcfc;
  --table-row-hover: rgba(211, 205, 205, 0.315);

  --input-bg:        #ffffff;
  --input-border:    rgba(0, 0, 0, 0.15);
  --input-focus:     rgba(236, 62, 88, 0.4);

  --shadow-sm:       0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md:       0 4px 12px rgba(0, 0, 0, 0.12);
  --shadow-lg:       0 8px 24px rgba(0, 0, 0, 0.15);

  --scrollbar-track: #e8e8e8;
  --scrollbar-thumb: #c0c0c0;

  /* Sidebar (Phase 13b) — light theme uses coral red bg */
  --sb-bg:           #EC3E58;
  --sb-logo-bg:      #ec3e58;
  --sb-logo-border: rgba(0, 0, 0, 0.08);
  --sb-icon:         #fcfcfc;
  --sb-active-bar:   #FCFCFC;
  --sb-flyout-bg:    #FCFCFC;
  --sb-flyout-border: #bcb2b27a;
  --sb-flyout-heading: #1e1e1e;
  --sb-flyout-body:  #1E1E1E;
  --sb-solo-body:    #1e1e1e;

  color-scheme: light;
}

/* ── Base resets that consume the variables ───────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background-color: var(--black);
  color: var(--text-primary);
  font-family: 'Barlow', sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Noise texture — same on both themes, lighter opacity in light */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

[data-theme="light"] body::before {
  opacity: 0.02;
}

/* ── Scrollbar styling ────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ── Theme toggle button ──────────────────────────────────── */
/*
   Drop this element into each page's topbar:
   <button class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
     <svg class="icon-sun" ...>...</svg>
     <svg class="icon-moon" ...>...</svg>
   </button>
   theme.js handles showing the right icon and wiring the click.
*/
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text-secondary);  /* adapts to topbar theme */
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--table-row-hover);
  border-color: var(--border-strong);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.5;
  display: none; /* shown/hidden by theme.js via .visible class */
}

.theme-toggle svg.visible {
  display: block;
}

/* ── Shared topbar ────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
  z-index: 1000;
}

.topbar-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.topbar-spacer {
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Shared sidebar (legacy — only used on home.html now) ─── */
.sidebar {
  position: fixed;
  top: 32px;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 900;
  transition: background-color 0.2s ease;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--d-gap-sm);
  padding: var(--d-btn-pad-y) var(--d-btn-pad-x);
  border-radius: 5px;
  border: none;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--red);
  color: #fff;
}
.btn-primary:hover {
  background: var(--red-hover);
}

.btn-secondary {
  background: var(--amber);
  color: #fff;
}
.btn-secondary:hover {
  background: var(--amber-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-amber {
  background: var(--amber);
  color: #1a1a1a;
}
.btn-amber:hover {
  background: var(--amber-hover);
}

.btn-success {
  background: var(--green-subtle);
  color: var(--green);
  border: 1px solid var(--green);
}
.btn-success:hover {
  background: var(--green);
  color: #fff;
}

.btn-sm {
  font-size: 0.78rem;
  padding: 4px 10px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Tables ───────────────────────────────────────────────── */

/* Scrollable table wrapper — place around any .data-table to
   get horizontal scroll when the viewport is too narrow.
   Also serves as the card-like visual container (surface bg,
   border, radius). Pages may extend with local overrides. */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

/* ── Column header (site-wide canonical) ─────────────────────
   Used for the header row of any tabular data layout — both real
   <table> elements (via .data-table th) and custom div/span-based
   layouts that need a column-header band.

   Distinct from .field-label: heavier weight + slightly smaller
   size + background tint. Use .col-header on any element to opt
   into this styling; .data-table th gets it automatically. */
.col-header,
.data-table th {
  background: var(--table-header);
  color: var(--text-primary);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: none;
  padding: var(--d-cell-pad-y) var(--d-cell-pad-x);
  text-align: left;
  border-bottom: 2px solid var(--border);
  border-right: 2px solid var(--border);
  white-space: nowrap;
}
.data-table th:last-child { border-right: none; }

/* ── Field label (site-wide canonical) ───────────────────────
   Sentence-case form field labels — readable as natural English,
   suited to "user-reads-and-types-here" UX. All form/filter/meta
   labels across the platform use this single class. Local overrides
   should be rare — only for legitimate visual distinctions (e.g.
   coloured signal text). Theme.css owns the look. */
.field-label {
  display: block;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-primary);
  margin-bottom: var(--d-gap-sm);
}

.data-table td {
  padding: var(--d-cell-pad-y) var(--d-cell-pad-x);
  border-bottom: 2px solid var(--border);
  border-right: 2px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.data-table td:last-child { border-right: none; }

.data-table tbody tr {
  background: var(--table-row-bg);
}

.data-table tbody tr:hover {
  background: var(--surface);
}

/* ── Form inputs ──────────────────────────────────────────── */
input, select, textarea {
  background: var(--input-bg);
}

.form-input,
.form-select,
.form-textarea {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 5px;
  color: var(--text-primary);
  font-family: 'Barlow', sans-serif;
  font-size: 0.9rem;
  padding: var(--d-input-pad-y) var(--d-input-pad-x);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--input-focus);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-tertiary);
}

/* ── Section labels ───────────────────────────────────────── */
.section-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-label);
}

/* ── Toast notifications ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: var(--d-cell-pad-y) var(--d-page-pad);
  border-radius: 6px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.2s ease forwards;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}

.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Status badges ────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-open     { background: var(--amber-subtle); color: var(--amber); }
.badge-active   { background: var(--amber-subtle); color: var(--amber); }
.badge-completed{ background: rgba(100,180,100,0.15); color: #6ab46a; }
.badge-closed   { background: var(--surface-3); color: var(--text-secondary); }
.badge-archived { background: var(--surface-3); color: var(--text-secondary); }
.badge-pending  { background: var(--red-subtle); color: var(--red); }
.badge-confirmed{ background: rgba(100,180,100,0.15); color: #6ab46a; }
.badge-rejected { background: var(--red-subtle); color: var(--red); }

/* ── Fade-up animation (staggered lists) ──────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-up {
  animation: fadeUp 0.35s ease forwards;
  opacity: 0;
}

/* ============================================================
   Capability multi-select dropdown (cap-select.js)
   Trigger styled to match .form-input / .edit-input elsewhere.
   Popover uses the native Popover API.
   ============================================================ */

.cap-select {
  position: relative;
  display: inline-block;
  width: 100%;
  min-width: 140px;
}

.cap-select-trigger {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: 'Barlow', sans-serif;
  font-size: 13.5px;
  padding: var(--d-input-pad-y) var(--d-input-pad-x);
  cursor: pointer;
  text-align: left;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cap-select-trigger:hover  { border-color: var(--border-strong); }
.cap-select-trigger:focus,
.cap-select-trigger[aria-expanded="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--input-focus);
}

.cap-select-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}
.cap-select-placeholder {
  flex: 1;
  color: var(--text-tertiary);
}
.cap-select-caret {
  width: 12px; height: 12px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: transform 0.18s;
}

/* Compact variant — for tight table rows */
.cap-select-compact .cap-select-trigger {
  padding: 6px 8px;
  font-size: 12.5px;
}

/* Popover — light-dismiss via the Popover API */
.cap-select-pop {
  /* Popover positioning: align under trigger. Since <div popover> is rendered
     in the top layer, we need inset positioning rather than absolute. */
  margin: 0;
  padding: 4px;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
}
/* Popover API handles open/closed visibility; only override spacing */
.cap-select-pop:popover-open {
  position: absolute;
}

.cap-select-option {
  display: flex; align-items: center; gap: 8px;
  padding: var(--d-gap-sm) var(--d-input-pad-x);
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Barlow', sans-serif;
  font-size: 13px;
  transition: background 0.12s;
  user-select: none;
}
.cap-select-option:hover { background: var(--surface-2); }
.cap-select-option.checked { background: var(--amber-subtle); }
.cap-select-option input[type="checkbox"] {
  width: 14px; height: 14px; flex-shrink: 0;
  accent-color: var(--red);
  cursor: pointer;
}
.cap-select-option span {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.cap-select-loading,
.cap-select-empty {
  padding: var(--d-input-pad-y) var(--d-input-pad-x);
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
}

/* ── Modal backdrop (site-wide) ──────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1200 !important;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }

