/* ── Tokens ──────────────────────────────────────────────── */
:root {
  --bg:          #F4F6FB;
  --surface:     #FFFFFF;
  --surface-2:   #EEF1F8;
  --surface-3:   #E4E9F4;
  --border:      #DDE2EE;
  --border-2:    #C8CEDF;

  --accent:      #2357E8;
  --accent-h:    #1A44C9;
  --accent-dim:  #EAF0FF;
  --accent-text: #1A44C9;

  --text:        #141829;
  --text-2:      #3D4460;
  --text-3:      #7A82A0;
  --text-inv:    #FFFFFF;

  --success:     #0F7A3C;
  --success-bg:  #EDFBF3;
  --success-b:   #A8DFC0;
  --warn:        #B45309;
  --warn-bg:     #FFFBEB;
  --warn-b:      #FCD34D;
  --danger:      #C62020;
  --danger-bg:   #FFF1F1;
  --danger-b:    #FBCACA;
  --neutral:     #4B5280;

  --shadow-sm:   0 1px 3px rgba(20,24,41,.07), 0 1px 2px rgba(20,24,41,.04);
  --shadow-md:   0 4px 16px rgba(20,24,41,.09), 0 1px 4px rgba(20,24,41,.05);
  --shadow-lg:   0 12px 40px rgba(20,24,41,.14), 0 2px 8px rgba(20,24,41,.06);

  --sidebar-w:   228px;
  --topbar-h:    56px;
  --radius:      8px;
  --radius-lg:   12px;

  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono:        'Cascadia Code', 'Consolas', 'Courier New', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #0D1117;
    --surface:    #141926;
    --surface-2:  #1C2336;
    --surface-3:  #232C42;
    --border:     #2A3352;
    --border-2:   #3A4566;
    --accent:     #3B6EF5;
    --accent-h:   #5585FF;
    --accent-dim: #1A2A52;
    --accent-text:#7FAAFF;
    --text:       #E4EAF8;
    --text-2:     #A8B2CC;
    --text-3:     #5A6480;
    --success:    #22C55E;
    --success-bg: #0A2218;
    --success-b:  #166534;
    --warn:       #F59E0B;
    --warn-bg:    #1C1500;
    --warn-b:     #78350F;
    --danger:     #F87171;
    --danger-bg:  #2A0A0A;
    --danger-b:   #7F1D1D;
    --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
    --shadow-md:  0 4px 16px rgba(0,0,0,.4);
    --shadow-lg:  0 12px 40px rgba(0,0,0,.5);
  }
}

:root[data-theme="light"] {
  --bg:         #F4F6FB; --surface: #FFFFFF; --surface-2: #EEF1F8;
  --surface-3:  #E4E9F4; --border: #DDE2EE; --border-2: #C8CEDF;
  --accent:     #2357E8; --accent-h: #1A44C9; --accent-dim: #EAF0FF;
  --accent-text:#1A44C9; --text: #141829; --text-2: #3D4460; --text-3: #7A82A0;
  --success: #0F7A3C; --success-bg: #EDFBF3; --success-b: #A8DFC0;
  --warn: #B45309; --warn-bg: #FFFBEB; --warn-b: #FCD34D;
  --danger: #C62020; --danger-bg: #FFF1F1; --danger-b: #FBCACA;
  --shadow-sm: 0 1px 3px rgba(20,24,41,.07), 0 1px 2px rgba(20,24,41,.04);
  --shadow-md: 0 4px 16px rgba(20,24,41,.09);
  --shadow-lg: 0 12px 40px rgba(20,24,41,.14);
}

:root[data-theme="dark"] {
  --bg: #0D1117; --surface: #141926; --surface-2: #1C2336;
  --surface-3: #232C42; --border: #2A3352; --border-2: #3A4566;
  --accent: #3B6EF5; --accent-h: #5585FF; --accent-dim: #1A2A52;
  --accent-text: #7FAAFF; --text: #E4EAF8; --text-2: #A8B2CC; --text-3: #5A6480;
  --success: #22C55E; --success-bg: #0A2218; --success-b: #166534;
  --warn: #F59E0B; --warn-bg: #1C1500; --warn-b: #78350F;
  --danger: #F87171; --danger-bg: #2A0A0A; --danger-b: #7F1D1D;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); font-size: 14px; background: var(--bg); color: var(--text); }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; } }

/* ── Login screen ────────────────────────────────────────── */
.login-shell { display: flex; width: 100%; height: 100%; }

.login-showcase {
  flex: 1.3; min-width: 0; overflow-y: auto;
  background: linear-gradient(160deg, var(--accent-dim) 0%, var(--surface-2) 55%, var(--surface-3) 100%);
  color: var(--text); padding: 56px 64px; display: flex; flex-direction: column; justify-content: center;
}
.login-showcase .brand-mark { background: var(--accent); color: #fff; }
.login-showcase h1 { font-size: 30px; font-weight: 800; margin: 18px 0 8px; color: var(--text); }
.login-tagline { font-size: 15px; color: var(--text-2); margin-bottom: 28px; max-width: 440px; line-height: 1.5; }
.login-illustration { width: 100%; max-width: 420px; margin-bottom: 32px; display: block; }
.login-feature { display: flex; gap: 14px; margin-bottom: 22px; align-items: flex-start; max-width: 440px; }
.login-feature-icon {
  font-size: 18px; line-height: 1; flex-shrink: 0; width: 36px; height: 36px; border-radius: 10px;
  background: var(--surface); box-shadow: var(--shadow-sm); display: flex; align-items: center; justify-content: center;
}
.login-feature-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; color: var(--text); }
.login-feature-desc { font-size: 13px; color: var(--text-3); line-height: 1.5; }

.login-panel {
  flex: 1; min-width: 340px; max-width: 480px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 32px; overflow-y: auto;
}
.login-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--text-3); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.btn-sso {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s;
}
.btn-sso:hover { background: var(--surface-2); }

@media (max-width: 860px) {
  .login-showcase { display: none; }
  .login-panel { flex: 1; max-width: none; }
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: var(--text-inv);
  display: grid; place-items: center;
  font-size: 16px; font-weight: 800; letter-spacing: -.5px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-size: 14px; font-weight: 700; color: var(--text); }

.sidebar-section-label {
  padding: 16px 16px 6px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-3);
}

.sidebar-nav { padding: 0 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 7px;
  font-size: 13.5px; font-weight: 500;
  color: var(--text-2); cursor: pointer;
  transition: background .12s, color .12s;
  border: none; background: none; width: 100%; text-align: left;
  text-decoration: none;
  position: relative;
}
.nav-item:hover:not(.disabled) { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim); color: var(--accent-text);
  font-weight: 600;
}
.nav-item.disabled { opacity: .4; cursor: not-allowed; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 700;
  background: var(--accent); color: var(--text-inv);
  padding: 1px 6px; border-radius: 10px;
}

.nav-skeleton {
  height: 34px; border-radius: 7px;
  background: var(--surface-2); margin: 2px 0;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.6} 50%{opacity:.3} }

.sidebar-spacer { flex: 1; }
.sidebar-bottom {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}

.theme-toggle {
  width: 32px; height: 32px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 15px;
  display: grid; place-items: center;
  color: var(--text-2); transition: border-color .15s, background .15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ── Layout Main ─────────────────────────────────────────── */
.layout-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
}
.topbar-title { font-size: 16px; font-weight: 700; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-area { flex: 1; padding: 28px; }

/* ── Pages ───────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

.page-lead {
  font-size: 13.5px; color: var(--text-3);
  max-width: 560px; margin-bottom: 24px; line-height: 1.6;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 80px 24px; gap: 12px;
}
.empty-icon { font-size: 44px; margin-bottom: 4px; }
.empty-state h3 { font-size: 18px; font-weight: 700; color: var(--text); }
.empty-state p { font-size: 13.5px; color: var(--text-3); }

/* ── Sources Grid ────────────────────────────────────────── */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

/* ── Simulation page ─────────────────────────────────────── */
.sim-section { margin-bottom: 2.25rem; }
.sim-section:last-child { margin-bottom: 0; }
.sim-section-head { margin-bottom: 1rem; }
.sim-section-head h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 700; color: var(--text); margin: 0 0 4px;
}
.sim-section-head p { margin: 0; font-size: 13px; color: var(--text-3); max-width: 640px; line-height: 1.55; }
.sim-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.sim-tool-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 1rem 1.1rem;
}
.sim-tool-card .card-title { font-size: 14px; }
.sim-tool-desc { margin: 0; font-size: 12.5px; color: var(--text-3); line-height: 1.5; flex: 1; }
.sim-tool-card .btn { align-self: flex-start; }

/* ── Plan Results map markers ────────────────────────────── */
.route-stop-pin, .route-depot-pin { background: none; border: none; }
.route-stop-pin-inner {
  width: 24px; height: 24px; border-radius: 50%; color: #fff;
  font-size: 11px; font-weight: 700; font-family: var(--sans, inherit);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.4);
}
.route-depot-pin-inner {
  width: 18px; height: 18px; border-radius: 50%;
  background: #1a1a1a; border: 3px solid; box-shadow: 0 1px 5px rgba(0,0,0,.4);
}
.plan-animate-bar { display: flex; gap: 8px; align-items: center; }

/* ── Route animation: truck marker + live info popup ─────── */
.route-truck-pin { background: none; border: none; }
.route-truck-pin-inner {
  width: 30px; height: 30px; border-radius: 50%; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.anim-info-popup .leaflet-popup-content-wrap { border-radius: 10px; }
.anim-info-popup .leaflet-popup-content { margin: 10px 14px; font-size: 12.5px; }
.anim-info-row {
  display: flex; align-items: center; gap: 6px; padding: 2px 0; color: var(--text-2);
}
.anim-info-row .anim-info-label { color: var(--text-3); }
.anim-info-row .anim-info-value { margin-left: auto; font-weight: 600; color: var(--text); }
.anim-info-divider { border-top: 1px solid var(--border); margin: 6px 0; }
.anim-info-waiting { color: var(--warn); font-weight: 600; }
.anim-info-early { color: var(--warn); font-size: 11.5px; }

.source-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow .15s, border-color .15s;
}
.source-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-2); }
.source-card.is-active { border-color: var(--accent); }
.source-card.is-active .card-top { background: var(--accent-dim); }

.card-top {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: flex-start;
}
.card-icon {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 18px;
  flex-shrink: 0;
}
.card-meta { flex: 1; min-width: 0; }
.card-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.card-desc { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  letter-spacing: .2px;
}
.badge-method   { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 10.5px; }
.badge-get      { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.badge-post     { background: #EFF6FF; color: #1D4ED8; border-color: #BFDBFE; }
.badge-put      { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }
.badge-patch    { background: #F5F3FF; color: #5B21B6; border-color: #DDD6FE; }
.badge-delete   { background: #FFF1F2; color: #9F1239; border-color: #FECDD3; }
.badge-auth     { background: var(--surface-3); color: var(--text-2); }
.badge-active   { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-b); }
.badge-inactive { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }

:root[data-theme="dark"] .badge-get    { background:#022C22; color:#6EE7B7; border-color:#065F46; }
:root[data-theme="dark"] .badge-post   { background:#1E3A5F; color:#93C5FD; border-color:#1D4ED8; }
:root[data-theme="dark"] .badge-put    { background:#2D1F00; color:#FCD34D; border-color:#78350F; }
:root[data-theme="dark"] .badge-patch  { background:#2E1065; color:#C4B5FD; border-color:#5B21B6; }
:root[data-theme="dark"] .badge-delete { background:#3B0012; color:#FDA4AF; border-color:#9F1239; }

.card-url-row {
  padding: 10px 16px;
  font-size: 12px; font-family: var(--mono);
  color: var(--text-3); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.card-actions {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2);
}
.card-action-spacer { flex: 1; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 7px;
  font-size: 13px; font-weight: 600;
  border: none; cursor: pointer;
  transition: opacity .12s, transform .1s, background .12s;
  line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border-2); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost  { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--accent-text); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0; }
.btn-link:hover { opacity: .7; }
.btn-icon { font-size: 12px; }
.full-w { width: 100%; justify-content: center; }

/* ── Drawer ──────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 12, 24, .35);
  backdrop-filter: blur(2px);
  display: none;
}
.drawer-overlay.open { display: block; }

.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 201;
  width: 480px; max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  flex-shrink: 0;
}
.drawer-title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.drawer-subtitle { font-size: 12px; color: var(--text-3); line-height: 1.5; }
.drawer-close {
  width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13px; color: var(--text-3); cursor: pointer;
  display: grid; place-items: center; transition: color .12s, border-color .12s;
}
.drawer-close:hover { border-color: var(--danger); color: var(--danger); }

.drawer-body {
  flex: 1; overflow-y: auto; padding: 0;
  display: flex; flex-direction: column;
}

.drawer-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* ── Form Sections ───────────────────────────────────────── */
.form-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 14px;
}
.form-section:last-child { border-bottom: none; }

.section-label {
  font-size: 10px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .9px;
  color: var(--text-3);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: 12px; font-weight: 600; color: var(--text-2);
}
.req { color: var(--danger); }
.hint-inline { font-weight: 400; color: var(--text-3); font-size: 11px; }

.field-row-header { display: flex; align-items: center; justify-content: space-between; }
.field-row-header label { margin: 0; font-size: 12px; font-weight: 600; color: var(--text-2); }

input[type=text], input[type=password], input[type=number], input[type=date],
select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text); border-radius: 7px;
  padding: 8px 11px; font-size: 13px;
  outline: none; width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 87, 232, .12);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }

/* Our own global `* { margin:0; padding:0; box-sizing:border-box }` reset (and the
   input/select/textarea rule above) was also bleeding into DevExtreme's own DOM —
   including popups/overlays it appends directly to <body>, outside any of our own
   containers. That zeroed-out spacing threw off its internal position/size math
   (popups rendering in a random corner, filter-row inputs squashed to icons).
   Revert just the reset properties on anything DevExtreme renders — matched by a
   "dx-" class substring, since that covers overlays teleported to <body> too. */
[class*="dx-"] {
  margin: revert;
  padding: revert;
  box-sizing: revert;
}
/* Scoped to the datagrid filter row only — the earlier version of this rule
   matched every `.dx-widget input` and, because dxDateBox/dxNumberBox/etc.
   are dx-widgets too, `all: revert` stripped their internal input's layout
   (flex sizing, transparent background, no border) along with the reset.
   That left free-standing editors like the planner's date picker rendered
   as a bare native input with its dropdown button pushed out of view —
   unstyled and unclickable. Filter-row inputs are the only ones actually
   squashed by the global reset, so only revert those. */
.dx-datagrid-filter-row input,
.dx-datagrid-filter-row select,
.dx-datagrid-filter-row textarea {
  all: revert;
}

/* ── Compact, crisper dxDataGrid styling (matches the app's own density/branding) ── */
.dx-datagrid { font-family: inherit; font-size: 12.5px; }
.dx-datagrid .dx-row > td,
.dx-datagrid .dx-row > tr > td {
  padding: 5px 10px;
}
.dx-datagrid-headers {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text-2);
}
.dx-datagrid-headers .dx-row > td { padding: 7px 10px; }
.dx-datagrid-borders > .dx-datagrid-rowsview,
.dx-datagrid-borders > .dx-datagrid-total-footer,
.dx-datagrid-borders .dx-datagrid-headers {
  border-color: var(--border);
}
.dx-datagrid .dx-row.dx-data-row:hover:not(.dx-row-focused) {
  background: var(--surface-2);
}
.dx-datagrid .dx-icon { color: var(--text-3); }
.dx-datagrid .dx-header-filter { color: var(--accent); }
.dx-datagrid .dx-sort-up, .dx-datagrid .dx-sort-down { color: var(--accent); }
.dx-datagrid-filter-row .dx-icon { color: var(--accent); }
.dx-pager { padding: 8px 12px; font-size: 12.5px; }
.dx-pager .dx-selection { background: var(--accent); }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* load type toggle */
.load-type-toggle   { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.load-type-toggle-3 { grid-template-columns: 1fr 1fr 1fr; }
.load-type-option { display: contents; }
.load-type-option input[type=radio] { display: none; }
.load-type-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; border: 2px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: border-color .15s, background .15s;
  background: var(--surface); text-align: center;
}
.load-type-card:hover { border-color: var(--accent); background: var(--accent-dim); }
.load-type-option input:checked + .load-type-card {
  border-color: var(--accent); background: var(--accent-dim);
}
.load-type-label { font-size: 12.5px; font-weight: 700; color: var(--text); }
.load-type-desc  { font-size: 10.5px; color: var(--text-3); }

/* shelf config block */
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.shelf-config-header {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-2); margin-bottom: 10px; margin-top: 4px;
}
.shelf-dim-note {
  font-size: 11px; color: var(--text-3); margin-bottom: 12px;
  padding: 6px 10px; background: var(--surface-2); border-radius: 6px;
  border-left: 3px solid var(--accent);
}
.shelf-total-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-2); margin-top: 8px;
  padding: 7px 10px; background: var(--accent-dim);
  border-radius: 7px; border: 1px solid var(--accent);
}
.shelf-total-row svg { color: var(--accent); flex-shrink: 0; }

/* shelf layout picker */
.shelf-layout-picker { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 4px; }
.shelf-layout-option { display: contents; }
.shelf-layout-option input[type=radio] { display: none; }
.shelf-layout-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px; border: 2px solid var(--border); border-radius: 9px;
  cursor: pointer; transition: border-color .15s, background .15s;
  background: var(--surface); text-align: center;
}
.shelf-layout-card:hover { border-color: var(--accent); background: var(--accent-dim); }
.shelf-layout-option input:checked + .shelf-layout-card { border-color: var(--accent); background: var(--accent-dim); }
.shelf-layout-label { font-size: 11.5px; font-weight: 700; color: var(--text); }
.shelf-layout-desc  { font-size: 10px; color: var(--text-3); line-height: 1.35; }
.field-hint { font-size: 10.5px; color: var(--text-3); margin-top: 3px; }

.input-group { display: flex; gap: 0; }
.method-select {
  border-radius: 7px 0 0 7px; border-right: none;
  background: var(--surface-2); font-weight: 700;
  font-family: var(--mono); font-size: 12px;
  color: var(--text); width: auto; flex-shrink: 0;
  padding: 8px 10px;
}
.url-input { border-radius: 0 7px 7px 0; flex: 1; }

/* ── Auth tabs ───────────────────────────────────────────── */
.auth-tabs {
  display: flex; gap: 0;
  border: 1px solid var(--border); border-radius: 7px;
  overflow: hidden;
}
.auth-tab {
  flex: 1; padding: 7px 6px;
  background: var(--bg); color: var(--text-2);
  border: none; border-right: 1px solid var(--border);
  cursor: pointer; font-size: 12px; font-weight: 600;
  transition: background .12s, color .12s;
}
.auth-tab:last-child { border-right: none; }
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-tab:not(.active):hover { background: var(--surface-2); color: var(--text); }
.auth-fields .hint-text { font-size: 12.5px; color: var(--text-3); }

/* ── Key-Value list (headers) ────────────────────────────── */
.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; gap: 6px; align-items: center; }
.kv-row input { flex: 1; min-width: 0; }
.kv-remove {
  width: 26px; height: 26px; border-radius: 6px; flex-shrink: 0;
  border: 1px solid var(--border); background: none;
  color: var(--text-3); cursor: pointer; font-size: 13px;
  display: grid; place-items: center;
  transition: border-color .12s, color .12s, background .12s;
}
.kv-remove:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

/* ── Code editor / textarea ──────────────────────────────── */
.code-editor {
  font-family: var(--mono); font-size: 12.5px;
  min-height: 100px; resize: vertical; line-height: 1.6;
}

/* ── Test panel ──────────────────────────────────────────── */
.test-panel {
  margin-top: 10px;
  border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden;
}
.test-meta {
  padding: 8px 12px;
  font-size: 12px; font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.test-meta.ok   { color: var(--success); }
.test-meta.fail { color: var(--danger);  }
.test-response {
  background: var(--bg);
  padding: 12px; margin: 0;
  font-family: var(--mono); font-size: 12px;
  color: var(--text-2); line-height: 1.6;
  overflow-x: auto; max-height: 220px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}

/* ── Mapping drawer ──────────────────────────────────────── */
.drawer-wide { width: 600px; }

.map-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.map-grid-header {
  display: contents;
}
.map-grid-header span {
  padding: 8px 12px;
  font-size: 10px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.map-grid-header span:first-child { border-right: 1px solid var(--border); }

.map-row { display: contents; }
.map-row:last-child .map-cell { border-bottom: none; }

.map-cell {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.map-cell-left {
  border-right: 1px solid var(--border);
  gap: 8px;
}
.map-cell-left .field-required {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--danger); flex-shrink: 0;
}
.map-cell-left .field-optional {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border-2); flex-shrink: 0;
}
.map-field-label {
  font-size: 13px; font-weight: 600; color: var(--text);
}
.map-field-desc {
  font-size: 11px; color: var(--text-3); margin-top: 1px;
}
.map-cell-right select {
  background: transparent; border: none; border-radius: 0;
  padding: 2px 4px; font-size: 12.5px; color: var(--text);
  width: 100%; box-shadow: none;
}
.map-cell-right select:focus {
  border: none; box-shadow: none; outline: 1px solid var(--accent); border-radius: 4px;
}
.map-cell-right select option { background: var(--surface); }

.result-inline {
  padding: 8px 12px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500;
  border: 1px solid transparent;
}
.result-inline.ok   { background: var(--success-bg); color: var(--success); border-color: var(--success-b); }
.result-inline.fail { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-b);  }

.badge-mapped   { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-b); }
.badge-unmapped { background: var(--warn-bg);    color: var(--warn);    border: 1px solid var(--warn-b); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(10,12,24,.5); backdrop-filter: blur(3px);
  display: grid; place-items: center;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 32px 28px; width: 360px; max-width: 90vw;
  text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 10px;
}
.modal-icon { font-size: 36px; }
.modal h3 { font-size: 17px; font-weight: 700; color: var(--text); }
.modal p  { font-size: 13.5px; color: var(--text-3); line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-wide {
  width: 640px; max-width: 92vw; max-height: 80vh; overflow-y: auto;
  text-align: left; align-items: stretch;
}
.modal-xwide { width: 920px; }
.session-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px; color: var(--accent-text);
}
.session-banner-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.session-banner-close {
  background: none; border: none; cursor: pointer; color: var(--accent-text);
  font-size: 14px; opacity: .7; line-height: 1;
}
.session-banner-close:hover { opacity: 1; }
.nearby-delivery-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; margin: 0 -10px; border-radius: 6px;
  border-bottom: 1px solid var(--border); font-size: 12.5px;
  transition: background .12s;
}
.nearby-delivery-item:last-child { border-bottom: none; }
.nearby-delivery-item:hover { background: var(--surface-2); }
.nearby-delivery-item.nearby-selected { background: var(--accent-dim); }

/* ── AI planning-assist prompt box ──────────────────────── */
.ai-prompt-box {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-top: 4px; background: var(--surface-2);
}
.ai-prompt-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px;
}
.ai-status-badge {
  font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: var(--surface); color: var(--text-3); border: 1px solid var(--border);
}
.ai-status-badge.ok   { background: var(--success-bg); color: var(--success); border-color: var(--success-b); }
.ai-status-badge.warn { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-b); }
.ai-prompt-box textarea { width: 100%; resize: vertical; }
.ai-prompt-box + .ai-prompt-box { margin-top: 12px; }
.plan-option-row {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  padding: 6px 2px; font-size: 13px; color: var(--text);
}
.plan-option-row input[type=checkbox] { margin-top: 3px; width: auto; }
.plan-option-row strong { display: block; font-weight: 600; }
.plan-option-row small { display: block; color: var(--text-3); font-size: 11.5px; font-weight: 400; }
.plan-estimate-row {
  margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-3);
}

/* ── Coming soon ─────────────────────────────────────────── */
.coming-soon {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; gap: 12px;
  color: var(--text-3); text-align: center;
}
.cs-icon { font-size: 48px; }
.coming-soon h2 { font-size: 22px; font-weight: 700; color: var(--text); }
.coming-soon p  { font-size: 14px; }

/* ── Vehicles map page ────────────────────────────────────── */
.vmap-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 12px; flex-wrap: wrap;
}
.vmap-layout {
  display: flex; gap: 16px; height: calc(100vh - 200px); min-height: 420px;
}
.vmap-sidebar {
  width: 280px; flex: none; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.vmap-sidebar-head {
  padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px;
}
.vmap-sidebar-actions { display: flex; gap: 8px; font-size: 12px; }
.vmap-sidebar-actions button {
  background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0;
}
.vmap-sidebar-actions button:hover { text-decoration: underline; }
.vmap-vehicle-list { flex: 1; overflow-y: auto; }
.vmap-vehicle-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.vmap-vehicle-item:hover { background: var(--surface-2); }
.vmap-vehicle-item.active-route { background: var(--accent-dim); }
.vmap-vehicle-item.active-route .plate { color: var(--accent-text); }
.vmap-vehicle-item .plate { font-weight: 600; color: var(--text); }
.vmap-vehicle-item .meta  { color: var(--text-3); font-size: 12px; }
.vmap-vehicle-item.no-geo { opacity: .5; }
.vmap-map-wrap {
  flex: 1; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); position: relative; display: flex; flex-direction: column;
  isolation: isolate;  /* contains Leaflet's internal z-index (controls go up to 1000) so it can never paint over a modal/dropdown elsewhere on the page */
}
#vmap-map, #cmap-map, #plan-map, #dispatch-map { width: 100%; flex: 1; }
/* Unplanned Orders grid's inline "MAP VIEW" toggle — replaces the table body in place. */
.mg-inline-map-wrap {
  height: calc(100vh - 320px); min-height: 420px; border-radius: var(--radius-lg);
  overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  position: relative; isolation: isolate;
}
#plan-unplanned-allmap { width: 100%; height: 100%; }
.route-detail-map {
  width: 100%; height: 280px; border-radius: var(--radius); overflow: hidden;
  margin-bottom: 12px; border: 1px solid var(--border);
  position: relative; isolation: isolate;  /* same containment as .vmap-map-wrap, for the standalone per-route mini-map */
}
/* Route View's Map tab (both the live Planner and Dispatched Orders) shows
   the map as its own dedicated tab — nothing else below it — so it can use
   the full height of the detail panel instead of the shared 280px default. */
#plan-route-detail-map, #dispatch-route-detail-map { height: calc(100vh - 340px); min-height: 420px; }
:root[data-theme="dark"] .route-detail-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }
.vmap-fence-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 8px 12px; display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--text);
}
.vmap-fence-banner-actions { display: flex; gap: 6px; }
.vmap-vehicle-item-row { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.vmap-vehicle-item-row label.vmap-vehicle-item {
  border-bottom: none; padding: 0; flex: 1; min-width: 0;
}
.vmap-fence-btn {
  background: none; border: none; cursor: pointer; color: var(--text-3); padding: 4px; flex: none;
  display: flex; align-items: center; border-radius: 6px;
}
.vmap-fence-btn:hover { color: var(--accent); background: var(--surface-2); }
:root[data-theme="dark"] #vmap-map .leaflet-tile-pane,
:root[data-theme="dark"] #cmap-map .leaflet-tile-pane,
:root[data-theme="dark"] #plan-map .leaflet-tile-pane,
:root[data-theme="dark"] #unplanned-map .leaflet-tile-pane,
:root[data-theme="dark"] #plan-unplanned-allmap .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }
:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip { background: var(--surface); color: var(--text); }
:root[data-theme="dark"] .leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }

/* ── Orders page ─────────────────────────────────────────── */
.page-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 12px; flex-wrap: wrap;
}
.toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }
.badge-count {
  background: var(--accent-dim); color: var(--accent-text);
  border-radius: 20px; padding: 4px 12px; font-size: 13px; font-weight: 600;
}
.plan-notice-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-dim); color: var(--accent-text); border: none;
  border-radius: 20px; padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.plan-notice-toggle:hover { background: color-mix(in srgb, var(--accent-dim) 80%, var(--accent) 20%); }
.plan-notice-toggle .chev { font-size: 9px; transition: transform .15s; }
.plan-notice-toggle.open .chev { transform: rotate(180deg); }
.plan-notices-panel {
  margin: 0 0 1rem; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden;
}
.plan-notice-item {
  padding: 8px 14px; font-size: 12.5px; color: var(--text-2); border-bottom: 1px solid var(--border);
}
.plan-notice-item:last-child { border-bottom: none; }
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th {
  padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--text-3);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text-2);
  background: var(--surface);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.td-empty { text-align: center; color: var(--text-3); padding: 2rem !important; }
.btn-link {
  background: none; border: none; color: var(--accent-text);
  cursor: pointer; font-size: 12.5px; font-weight: 600; padding: 0; text-decoration: underline;
}
.btn-icon-danger {
  background: none; border: none; cursor: pointer; font-size: 14px;
  opacity: .6; transition: opacity .15s;
}
.btn-icon-danger:hover { opacity: 1; }
.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.status-pending    { background: var(--warn-bg);    color: var(--warn); }
.status-planned    { background: var(--accent-dim); color: var(--accent-text); }
.status-done       { background: var(--success-bg); color: var(--success); }
.status-dispatched { background: var(--success-bg); color: var(--success); }
.status-system     { background: var(--accent-dim); color: var(--accent-text); }
.status-manual     { background: var(--warn-bg);    color: var(--warn); }
.status-ai-manual  { background: var(--surface-2);  color: var(--text-2); border: 1px solid var(--border); }
.lines-panel {
  margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden;
}
.lines-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px;
}
.lines-panel-header button {
  background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text-3);
}

/* ── API Management ──────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; margin-bottom: 0;
  box-shadow: var(--shadow-sm);
}
.card-header-row {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--text); }
.ref-block { margin-bottom: 1.5rem; }
.ref-label { font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-3); margin-bottom: 6px; }
.ref-code-row { display: flex; align-items: center; gap: 8px; }
.ref-code-row code {
  flex: 1; font-family: var(--mono); font-size: 13px; background: var(--surface-2);
  padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); color: var(--text);
}
.btn-copy {
  padding: 6px 12px; font-size: 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer;
  color: var(--text-2); white-space: nowrap;
}
.btn-copy:hover { background: var(--surface-3); }
.code-block {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-family: var(--mono); font-size: 12px;
  color: var(--text); white-space: pre-wrap; word-break: break-all; overflow-x: auto; margin: 0;
}
.tester-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tester-input { flex: 1; min-width: 180px; }
.tester-select { min-width: 180px; }

/* ── Audit Log filter bar ────────────────────────────────── */
.audit-filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.audit-filter-bar select, .audit-filter-bar input { width: auto; font-size: 12px; padding: 6px 10px; }
.audit-filter-bar #audit-filter-event { min-width: 150px; }
.audit-filter-bar #audit-filter-username { width: 130px; }
.audit-filter-bar input[type=date] { width: 140px; }
.audit-filter-sep { color: var(--text-3); font-size: 12px; }

/* ── Master Data ─────────────────────────────────────────── */
.status-pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.pill-active   { background: var(--success-bg); color: var(--success); }
.pill-inactive { background: var(--surface-2);  color: var(--text-3); }
.td-actions {
  white-space: nowrap; text-align: right; position: sticky; right: 0;
  background: var(--surface); z-index: 1; box-shadow: -6px 0 6px -6px rgba(0,0,0,.15);
}
.th-actions { position: sticky; right: 0; background: var(--surface); z-index: 2; }
.btn-icon {
  background: none; border: none; cursor: pointer; font-size: 13px;
  opacity: .55; transition: opacity .15s; margin-left: 2px;
}
.btn-icon:hover { opacity: 1; }

/* ── Row inline buttons (rib) ────────────────────────────── */
.rib-group {
  display: flex; align-items: center; gap: 2px;
  opacity: 0; transition: opacity .12s;
}
.mg-table tbody tr:hover .rib-group { opacity: 1; }
.rib {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid transparent; background: none;
  color: var(--text-3); cursor: pointer;
  transition: background .1s, border-color .1s, color .1s;
}
.rib:hover { background: var(--surface-2); border-color: var(--border); color: var(--text-1); }
.rib-delete:hover { background: color-mix(in srgb, var(--danger,#d93737) 10%, transparent); border-color: var(--danger,#d93737); color: var(--danger,#d93737); }
.rib-uom:hover { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ── Row action dropdown (legacy, kept for reference) ────── */
.row-action-wrap { position: relative; display: inline-block; }
.row-action-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid transparent;
  opacity: 0;
  background: transparent; color: var(--text-2,#666);
  font-size: 16px; font-weight: 700; cursor: pointer; line-height: 1;
  transition: background .12s, border-color .12s, color .12s;
  letter-spacing: -1px;
}
.row-action-btn:hover,
.row-action-btn.active {
  background: var(--surface-2); border-color: var(--border);
  color: var(--text-1);
}
.row-action-menu {
  display: none; position: fixed; z-index: 9990;
  min-width: 190px; padding: 6px 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
}
.row-action-menu.open { display: block; }
.row-action-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 16px; background: none; border: none;
  text-align: left; font-size: 13px; color: var(--text-1);
  cursor: pointer; transition: background .1s; white-space: nowrap;
}
.row-action-menu button svg { opacity: .55; flex-shrink: 0; }
.row-action-menu button:hover { background: var(--surface-2); }
.row-action-menu button:hover svg { opacity: .85; }
.row-action-menu button.danger { color: var(--danger,#d93737); }
.row-action-menu button.danger svg { opacity: .7; }
.row-action-menu button.danger:hover { background: color-mix(in srgb, var(--danger,#d93737) 8%, transparent); }
.row-action-menu .menu-divider { height: 1px; background: var(--border); margin: 5px 0; }
.bool-yes { font-size: 11px; font-weight: 600; color: var(--success); }
.bool-no  { font-size: 11px; color: var(--text-3); }
.master-fields textarea { width: 100%; resize: vertical; }

/* ── UOM drawer ───────────────────────────────────────────── */
.iuom-drawer-wide { width: 620px; display: flex; flex-direction: column; }
.iuom-list-section { flex: 1; overflow-y: auto; }
.iuom-table { font-size: 12px; }
.iuom-table th, .iuom-table td { padding: 8px 10px; }
#iuom-form-section {
  border-top: 2px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.iuom-form-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px 0;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.iuom-base-row td { background: color-mix(in srgb, var(--primary,#3b6ef5) 6%, transparent); }
.badge-base {
  display: inline-block; padding: 2px 7px; border-radius: 12px;
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
  background: var(--primary,#3b6ef5); color: #fff;
}
.field-label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-2,#666); margin-bottom: 3px;
}

/* ── Simulation ───────────────────────────────────────────── */
.sim-list { display: flex; flex-direction: column; gap: 10px; }
.sim-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.sim-card-main { min-width: 0; flex: 1; }
.sim-card-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.sim-card-badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 10px;
  background: var(--accent-dim); color: var(--accent);
}
.sim-card-query {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px;
}
.sim-card-lastrun { font-size: 11.5px; color: var(--text-3); }
.sim-card-lastrun.sim-never { font-style: italic; }
.sim-ok  { color: #198754; font-weight: 600; }
.sim-err { color: #d93737; font-weight: 600; }
.sim-pending { color: var(--text-3); }
.sim-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.sim-inline-status { font-size: 12px; line-height: 1.5; }

.sim-drawer-wide { width: 640px; }
.sim-drawer-wide textarea {
  width: 100%; font-family: var(--mono); font-size: 12px; resize: vertical;
}
.sim-preview-table-wrap {
  max-height: 200px; overflow: auto; border: 1px solid var(--border); border-radius: 8px;
}
.sim-preview-table { width: 100%; border-collapse: collapse; font-size: 11.5px; white-space: nowrap; }
.sim-preview-table th {
  position: sticky; top: 0; background: var(--surface-3); color: var(--text-2);
  padding: 6px 10px; text-align: left; font-weight: 600; border-bottom: 1px solid var(--border);
}
.sim-preview-table td { padding: 5px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
.sim-fieldmap-empty { font-size: 12px; color: var(--text-3); font-style: italic; }
.sim-fieldmap-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

/* ── Nav group (Masters) ──────────────────────────────────── */
.nav-group { margin: 2px 0; }
.nav-group-header {
  display: flex; align-items: center; gap: 8px;
  width: 100%; background: none; border: none; cursor: pointer;
  padding: 7px 12px; border-radius: var(--radius);
  font-size: 12.5px; font-weight: 600; color: var(--text-3);
  letter-spacing: .03em; text-transform: uppercase;
  transition: background .15s, color .15s;
}
.nav-group-header:hover { background: var(--surface-2); color: var(--text-2); }
.nav-group-header .nav-icon { font-size: 15px; width: 20px; text-align: center; }
.nav-group-header span:nth-child(2) { flex: 1; text-align: left; }
.nav-group-arrow { font-size: 10px; color: var(--text-3); }
.nav-sub-item { padding-left: 32px !important; font-size: 13px !important; }
.nav-sub-item .nav-icon { font-size: 13px !important; }

/* ── MasterGrid ───────────────────────────────────────────── */

/* top bar: group zone + search/export */
.mg-topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 6px 10px; margin-bottom: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.mg-group-zone {
  flex: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  min-height: 28px; padding: 3px 8px;
  border: 1.5px dashed var(--border); border-radius: 6px;
  transition: border-color .15s, background .15s;
}
.mg-group-zone.has-groups { border-style: solid; border-color: var(--accent); background: var(--accent-dim); }
.mg-group-hint { font-size: 11.5px; color: var(--text-3); font-style: italic; }
.mg-group-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent); color: #fff; border-radius: 12px;
  padding: 2px 8px 2px 10px; font-size: 11.5px; font-weight: 600;
}
.mg-group-chip button {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0; opacity: .8;
}
.mg-group-chip button:hover { opacity: 1; }
.mg-topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.btn-export {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  color: #198754; background: #d1e7dd; border: 1.5px solid #a3cfbb;
  border-radius: 6px; cursor: pointer; transition: background .15s;
}
.btn-export:hover { background: #b8dac9; }
.btn-xl-download, .btn-xl-upload {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  border-radius: 6px; cursor: pointer; transition: background .15s;
  border: 1.5px solid; white-space: nowrap;
}
.btn-xl-download {
  color: #0369a1; background: #e0f2fe; border-color: #7dd3fc;
}
.btn-xl-download:hover { background: #bae6fd; }
.btn-xl-upload {
  color: #7c3aed; background: #ede9fe; border-color: #c4b5fd;
}
.btn-xl-upload:hover { background: #ddd6fe; }
:root[data-theme="dark"] .btn-xl-download { color:#38bdf8; background:#0c2d48; border-color:#0369a1; }
:root[data-theme="dark"] .btn-xl-download:hover { background:#0c3a5c; }
:root[data-theme="dark"] .btn-xl-upload { color:#a78bfa; background:#2e1065; border-color:#7c3aed; }
:root[data-theme="dark"] .btn-xl-upload:hover { background:#3b1278; }

/* ── Toast notification ──────────────────────────────────── */
.dp-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  z-index: 99999; padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 500;
  white-space: nowrap; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .25s;
  opacity: 0; pointer-events: none;
}
.dp-toast-show { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }
.dp-toast-info    { background:#1e3a5f; color:#93c5fd; }
.dp-toast-success { background:#14532d; color:#86efac; }
.dp-toast-error   { background:#7f1d1d; color:#fca5a5; }

.mg-search-wrap {
  position: relative; display: flex; align-items: center;
}
.mg-search-ico {
  position: absolute; left: 11px; color: var(--text-3); pointer-events: none; flex-shrink: 0;
}
.mg-search-input {
  padding: 6px 28px 6px 34px; font-size: 13px; width: 200px;
  border: 1px solid var(--border-2); border-radius: 7px;
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s, width .2s;
}
.mg-search-input::placeholder { color: var(--text-3); opacity: 1; }
.mg-search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); width: 260px; }
.mg-search-clear {
  position: absolute; right: 10px; background: none; border: none;
  cursor: pointer; color: var(--text-3); font-size: 15px; line-height: 1; padding: 0;
}
.mg-search-clear:hover { color: var(--text); }

.mg-wrap {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; overflow-x: auto;
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.mg-table {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
  table-layout: fixed;
}
.mg-table th {
  background: var(--surface); color: var(--text); font-size: 12px;
  font-weight: 600; letter-spacing: 0;
  padding: 6px 10px; text-align: left; border-bottom: 2px solid var(--border);
  white-space: nowrap; overflow: hidden; user-select: none; cursor: pointer;
  position: relative;
}
.mg-table th:hover { background: var(--surface-2); }
.th-check { cursor: default !important; padding: 6px 8px !important; }
.th-check:hover { background: var(--surface) !important; }
.col-resize-handle {
  position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 1;
}
.col-resize-handle:hover,
.col-resize-handle.resizing { background: var(--accent); opacity: .4; }
.mg-table.resizing-active { cursor: col-resize; user-select: none; }

/* column header inner layout */
.mg-col-header {
  display: flex; align-items: center; gap: 6px;
}
.mg-col-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.mg-col-filter-btn {
  flex-shrink: 0; background: none; border: none;
  padding: 2px 3px; cursor: pointer; font-size: 14px; font-weight: 400;
  color: var(--text-3); line-height: 1; transition: color .12s;
  opacity: 0.5;
}
.mg-col-filter-btn:hover { color: var(--text); opacity: 1; }
.mg-col-filter-active { color: var(--accent) !important; opacity: 1 !important; }

.mg-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 0; font-size: 12.5px;
}
.mg-table tbody tr:last-child td { border-bottom: none; }
.mg-table tbody tr:hover td { background: var(--surface-2); }
.mg-table tbody tr:hover .row-action-btn { opacity: 1; }
.row-action-btn.active { opacity: 1; }
.td-num { text-align: right; font-variant-numeric: tabular-nums; }
.td-check { width: 36px; text-align: center; padding: 5px 8px !important; }

/* row expand toggle (item UOM detail) */
.row-expand-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 5px; border: none;
  background: none; color: var(--text-3); cursor: pointer;
  transition: transform .15s, color .12s, background .12s;
}
.row-expand-btn:hover { background: var(--surface-2); color: var(--text-1); }
.row-expand-btn.expanded { transform: rotate(90deg); color: var(--accent); }
.item-uom-detail-row td {
  padding: 0 !important; border-bottom: 1px solid var(--border) !important;
  background: var(--surface-2);
}
.item-uom-detail-body { padding: 10px 16px 12px 44px; }
.iuom-detail-empty { font-size: 12px; color: var(--text-3); padding: 6px 0; }
.iuom-detail-empty a { color: var(--accent); }
.iuom-detail-table {
  width: 100%; max-width: 720px; border-collapse: collapse; font-size: 12px;
  background: var(--surface); border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
}
.iuom-detail-table th {
  text-align: left; padding: 6px 10px; font-weight: 600; font-size: 11px;
  color: var(--text-2); background: var(--surface-3); border-bottom: 1px solid var(--border);
}
.iuom-detail-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.iuom-detail-table tr:last-child td { border-bottom: none; }
.iuom-detail-table .td-num { font-variant-numeric: tabular-nums; }

/* group header row */
.mg-group-header td {
  background: var(--surface-2); font-size: 12px; font-weight: 700;
  color: var(--text-2); padding: 5px 12px; border-bottom: 1px solid var(--border);
  letter-spacing: .02em;
}
.mg-group-count { font-weight: 400; color: var(--text-3); margin-left: 4px; }

/* filter popup */
.filter-popup {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  display: flex; flex-direction: column; max-height: 320px; overflow: hidden;
}
.filter-popup-search {
  display: block; box-sizing: border-box;
  width: calc(100% - 16px); margin: 8px; padding: 5px 8px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--text); outline: none;
}
.filter-popup-search:focus { border-color: var(--accent); }
.filter-popup-list { overflow-y: auto; flex: 1; padding: 2px 0; }
.filter-popup-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; cursor: pointer; font-size: 12.5px;
  color: var(--text); user-select: none;
}
.filter-popup-item:hover { background: var(--accent-dim); }
.filter-popup-selall { font-weight: 600; }
.filter-popup-divider { height: 1px; background: var(--border); margin: 2px 0; }
.filter-popup-footer {
  display: flex; justify-content: flex-end; gap: 6px;
  padding: 8px 10px; border-top: 1px solid var(--border);
}

/* pagination */
.mg-pagination {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.4rem 0; margin-top: 0.4rem; font-size: 12px; color: var(--text-3);
}
.pg-controls { display: flex; align-items: center; gap: 4px; }
.pg-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 9px; cursor: pointer; font-size: 13px;
  color: var(--text-2); transition: background .12s;
}
.pg-btn:hover:not(:disabled) { background: var(--surface-2); }
.pg-btn:disabled { opacity: .35; cursor: default; }
.pg-label { padding: 0 8px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.grid-loading { padding: 2rem; text-align: center; color: var(--text-3); font-size: 13px; }

/* ── Planning results ─────────────────────────────────────── */
.route-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 14px 16px; margin-bottom: 14px;
}
.route-card-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.route-card-title { font-size: 15px; font-weight: 700; color: var(--text); }
.route-card-meta { font-size: 12px; color: var(--text-3); }
.route-stats { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 10px; }
.route-stat { min-width: 140px; }
.route-stat-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
.route-stat-value { font-size: 14px; font-weight: 600; color: var(--text); }
.util-bar {
  height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 4px; width: 140px;
}
.util-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.util-bar-fill.high { background: #e05a4e; }
.progress-modal-bar {
  height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden;
  width: 100%; margin: 10px 0 4px;
}
.progress-modal-bar .util-bar-fill { transition: width .25s ease; }
.progress-steps {
  list-style: none; margin: 4px 0 2px; padding: 0; width: 100%;
  display: flex; flex-direction: column; gap: 9px; text-align: left;
}
.progress-step {
  display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-3);
  transition: color .2s ease;
}
.progress-step-icon {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; box-sizing: border-box;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  border: 2px solid var(--border); color: transparent;
}
.progress-step.done .progress-step-icon {
  background: var(--success); border-color: var(--success); color: #fff;
}
.progress-step.done .progress-step-icon::after { content: '✓'; }
.progress-step.done { color: var(--text); }
.progress-step.active { color: var(--text); font-weight: 600; }
.progress-step.active .progress-step-icon { border-color: var(--accent); }
.progress-step.active .progress-step-icon::after {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: progress-pulse 1s ease-in-out infinite;
}
@keyframes progress-pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
.progress-step-detail { font-size: 11.5px; color: var(--text-3); font-weight: 400; margin-top: 2px; }
.progress-modal-foot {
  display: flex; justify-content: space-between; width: 100%;
  font-size: 12px; color: var(--text-3); font-weight: 600;
}
.route-view-toggle { display: flex; gap: 6px; margin: 12px 0 10px; }
.route-view-toggle-btn {
  padding: 5px 12px; border-radius: 7px; font-size: 12px; font-weight: 600;
  background: transparent; color: var(--text-3); border: 1px solid var(--border-2); cursor: pointer;
}
.route-view-toggle-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.route-summary-section { margin-bottom: 18px; }
.route-summary-section:last-child { margin-bottom: 0; }
.route-summary-head {
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px;
  margin-bottom: 6px; color: var(--text);
}
.route-summary-head span { font-weight: 400; color: var(--text-3); font-size: 12px; }
.cube-scene {
  perspective: 700px; display: flex; align-items: center; justify-content: center;
  padding: 34px 0 22px; min-height: 200px;
}
.cube { position: relative; transform-style: preserve-3d; animation: cube-spin 12s linear infinite; }
.cube-scene:hover .cube { animation-play-state: paused; }
.cube-face { position: absolute; box-sizing: border-box; border: 1px solid rgba(0, 0, 0, .35); }
@keyframes cube-spin {
  from { transform: rotateX(-18deg) rotateY(0deg); }
  to   { transform: rotateX(-18deg) rotateY(360deg); }
}
.progress-trucks-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; font-size: 12px; font-weight: 600; color: var(--text-3);
}
.progress-trucks {
  width: 100%; max-height: 170px; overflow-y: auto; margin-top: 6px;
  display: flex; flex-direction: column; gap: 6px;
}
.progress-truck-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 12px; text-align: left; animation: progress-truck-in .25s ease;
}
.progress-truck-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-weight: 600; color: var(--text); }
.progress-truck-orders { margin-left: auto; color: var(--text-3); font-weight: 600; }
@keyframes progress-truck-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.plan-bg-indicator {
  position: fixed; bottom: 20px; right: 20px; z-index: 400;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 10px 18px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg); cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text);
}
.plan-bg-indicator.done { border-color: var(--success-b); color: var(--success); }
.plan-bg-indicator.error { border-color: var(--danger-b); color: var(--danger); }
.plan-bg-spinner {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: plan-bg-spin .8s linear infinite;
}
.plan-bg-indicator.done .plan-bg-spinner, .plan-bg-indicator.error .plan-bg-spinner { display: none; }
@keyframes plan-bg-spin { to { transform: rotate(360deg); } }
.plan-unassigned-card {
  background: var(--surface); border: 1px solid #e0a94e; border-radius: var(--radius-lg);
  padding: 12px 16px; font-size: 13px;
}
.plan-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.plan-tab {
  padding: 10px 16px; background: none; border: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.plan-tab:hover { color: var(--text); }
.plan-tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.tab-badge {
  display: inline-block; background: #e05a4e; color: #fff; border-radius: 10px;
  padding: 1px 7px; font-size: 11px; font-weight: 700; margin-left: 6px;
}
.assign-row { display: flex; align-items: center; gap: 8px; }
.assign-row select { flex: 1; }
