/* ==========================================================================
   Omnitech Central — Dashboard
   Sistema de diseño propio: sin frameworks, ~25KB vs los 2MB anteriores.
   ========================================================================== */

:root {
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 248px;
  --sidebar-w-min: 68px;
  --topbar-h: 60px;
  --transition: 160ms ease;

  /* Azules de marca Omnitech (extraídos del logo) */
  --brand: #007bc1;
  --brand-light: #10a4e3;
  --brand-dark: #134980;

  --indigo: #6366f1;
  --violet: #8b5cf6;
  --cyan: #22d3ee;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --pink: #ec4899;
  --teal: #14b8a6;
  --slate: #94a3b8;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-soft: #0e1628;
  --surface: #111c30;
  --surface-2: #16233c;
  --surface-3: #1c2c4a;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e7ecf6;
  --text-soft: #9aa7bd;
  --text-faint: #64748b;
  --accent: #10a4e3;
  --accent-strong: #007bc1;
  --accent-soft: rgba(16, 164, 227, 0.15);
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
  --chart-grid: rgba(148, 163, 184, 0.12);
  --scrollbar: rgba(148, 163, 184, 0.25);
  --map-stroke: #0b1220;
  --map-empty: #243755;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-soft: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eceff7;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --text-soft: #51607a;
  --text-faint: #8a96ad;
  --accent: #0072ba;
  --accent-strong: #006aae;
  --accent-soft: rgba(0, 123, 193, 0.1);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --chart-grid: rgba(15, 23, 42, 0.07);
  --scrollbar: rgba(15, 23, 42, 0.2);
  --map-stroke: #ffffff;
  --map-empty: #cdd7e6;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
   Layout
   ========================================================================== */

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: width var(--transition), transform var(--transition);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left var(--transition);
}

body.sidebar-min .sidebar { width: var(--sidebar-w-min); }
body.sidebar-min .main { margin-left: var(--sidebar-w-min); }
body.sidebar-min .brand-text,
body.sidebar-min .nav-label,
body.sidebar-min .sidebar-footer { display: none; }
body.sidebar-min .nav-item { justify-content: center; padding: 11px 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}

.brand img { width: 30px; height: 30px; object-fit: contain; }

.brand-text { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand-text span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-weight: 500;
  white-space: nowrap;
}

.nav-item i { font-size: 17px; width: 20px; text-align: center; }
.nav-item .nav-svg { width: 20px; height: 18px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .nav-ext { margin-left: auto; width: auto; font-size: 11px; opacity: 0.45; }
body.sidebar-min .nav-item .nav-ext { display: none; }

.nav-section {
  margin: 14px 12px 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}
body.sidebar-min .nav-section { visibility: hidden; margin: 8px 0 0; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; margin-right: auto; white-space: nowrap; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
  flex: none;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

.global-search { position: relative; width: min(340px, 32vw); }
.global-search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 14px; pointer-events: none; }
/* Mayor especificidad que la regla base de inputs para que el padding no se pise */
.global-search input[type="search"] { padding-left: 32px; }

.user-menu { position: relative; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
}
.user-chip:hover { border-color: var(--border-strong); }
.avatar {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-light));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  z-index: 60;
}
.menu-panel.open { display: block; }
.menu-panel a, .menu-panel button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel .danger { color: var(--red); }
.menu-panel form { margin: 0; }
.menu-panel button.confirm-armed { color: var(--amber); font-weight: 700; }
.menu-divider { height: 1px; margin: 5px 8px; background: var(--border); }

.content { padding: 22px; display: flex; flex-direction: column; gap: 18px; }

/* ==========================================================================
   Componentes base
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}
.card-title i { color: var(--accent); }
.card-sub { margin: 0 0 14px; font-size: 12px; color: var(--text-faint); }
.card-link { margin-left: auto; font-size: 12px; font-weight: 600; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { color: var(--accent); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

input[type="text"], input[type="search"], input[type="date"], input[type="number"],
input[type="password"], input[type="email"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-faint); }

label.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-soft);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }

.badge.st-created   { background: rgba(59, 130, 246, .14); color: #60a5fa; }
.badge.st-received  { background: rgba(34, 211, 238, .14); color: #22d3ee; }
.badge.st-transferred { background: rgba(139, 92, 246, .15); color: #a78bfa; }
.badge.st-processed { background: rgba(245, 158, 11, .15); color: #fbbf24; }
.badge.st-delivered { background: rgba(34, 197, 94, .15); color: #4ade80; }
.badge.st-pickup    { background: rgba(20, 184, 166, .15); color: #2dd4bf; }
.badge.st-delegated { background: rgba(236, 72, 153, .14); color: #f472b6; }
.badge.st-deleted, .badge.st-canceled { background: rgba(239, 68, 68, .14); color: #f87171; }
.badge.st-archived  { background: rgba(148, 163, 184, .14); color: #94a3b8; }
.badge.st-postsale  { background: rgba(217, 119, 6, .16); color: #fbbf24; }

[data-theme="light"] .badge.st-created   { color: #1d4ed8; }
[data-theme="light"] .badge.st-received  { color: #0e7490; }
[data-theme="light"] .badge.st-transferred { color: #6d28d9; }
[data-theme="light"] .badge.st-processed { color: #b45309; }
[data-theme="light"] .badge.st-delivered { color: #15803d; }
[data-theme="light"] .badge.st-pickup    { color: #0f766e; }
[data-theme="light"] .badge.st-delegated { color: #be185d; }
[data-theme="light"] .badge.st-deleted, [data-theme="light"] .badge.st-canceled { color: #b91c1c; }
[data-theme="light"] .badge.st-archived  { color: #475569; }
[data-theme="light"] .badge.st-postsale  { color: #b45309; }

.badge.courier { background: var(--surface-3); color: var(--text-soft); }

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13px;
  font-weight: 500;
}
.alert-error { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .3); color: #f87171; }
.alert-success { background: rgba(34, 197, 94, .1); border-color: rgba(34, 197, 94, .3); color: #4ade80; }
.alert-info { background: rgba(59, 130, 246, .1); border-color: rgba(59, 130, 246, .3); color: #60a5fa; }
[data-theme="light"] .alert-error { color: #b91c1c; }
[data-theme="light"] .alert-success { color: #15803d; }
[data-theme="light"] .alert-info { color: #1d4ed8; }

/* ==========================================================================
   Filtros
   ========================================================================== */

.filterbar { display: flex; flex-direction: column; gap: 12px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-field { display: flex; flex-direction: column; min-width: 130px; flex: 1 1 150px; max-width: 230px; }
.filter-field.grow { max-width: none; flex: 2 1 240px; }
.filter-actions { display: flex; gap: 8px; align-items: flex-end; }

.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset-btn {
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font);
  transition: var(--transition);
}
.preset-btn:hover, .preset-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* Popover para guardar la vista actual */
.save-view { position: relative; }
.save-view-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 70;
  width: min(300px, calc(100vw - 28px));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 15px;
}
.save-view-pop .pop-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}
.save-view-pop .pop-title i { color: var(--accent); }
.save-view-pop p { margin: 0 0 10px; font-size: 12px; color: var(--text-faint); }

/* Vistas guardadas (combinaciones de filtros con nombre) */
.saved-views { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.saved-views .label { font-size: 11.5px; font-weight: 600; color: var(--text-faint); }
.view-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px 4px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.view-chip:hover { border-color: var(--accent); }
.view-chip i { font-size: 13px; border-radius: 50%; padding: 1px; }
.view-chip i:hover { background: var(--accent); color: #fff; }

details.more-filters { border-top: 1px dashed var(--border); padding-top: 10px; }
details.more-filters summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
details.more-filters summary::-webkit-details-marker { display: none; }
details.more-filters summary:hover { color: var(--accent); }
details.more-filters[open] summary i { transform: rotate(180deg); }
details.more-filters .filter-row { margin-top: 12px; }

/* Multiselect dropdown */
.mselect { position: relative; }
.mselect select { display: none; }
.mselect-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.mselect-btn .placeholder { color: var(--text-faint); }
.mselect-btn:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mselect-count {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 8px;
}
.mselect-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 70;
  width: max(100%, 230px);
  max-height: 290px;
  overflow: hidden auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
}
.mselect.open .mselect-panel { display: block; }
.mselect-search { position: sticky; top: 0; background: var(--surface); padding: 2px 2px 8px; }
.mselect-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.mselect-option:hover { background: var(--surface-2); }
.mselect-option input { width: auto; accent-color: var(--accent-strong); }

/* ==========================================================================
   KPIs
   ========================================================================== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.kpi {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--kpi-color, var(--accent));
}
.kpi-head { display: flex; align-items: center; gap: 8px; color: var(--text-soft); font-size: 12px; font-weight: 600; }
.kpi-head i { color: var(--kpi-color, var(--accent)); font-size: 15px; }
.kpi-value { margin-top: 7px; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-foot { margin-top: 5px; font-size: 11.5px; color: var(--text-faint); min-height: 16px; }
.kpi-foot .up { color: var(--green); font-weight: 600; }
.kpi-foot .down { color: var(--red); font-weight: 600; }

/* ==========================================================================
   Grillas de gráficos
   ========================================================================== */

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.chart-card { display: flex; flex-direction: column; min-height: 300px; }
.chart-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.chart-wrap { position: relative; flex: 1; min-height: 230px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 13px;
  flex-direction: column;
  gap: 6px;
}
.chart-empty i { font-size: 26px; opacity: .6; }
.chart-wrap.empty .chart-empty { display: flex; }
.chart-wrap.empty canvas { display: none; }

.chart-dl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  flex: none;
}
.chart-dl:hover { color: var(--accent); background: var(--accent-soft); }

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  margin-left: auto;
}
.seg button {
  border: 0;
  background: none;
  color: var(--text-soft);
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 999px;
  cursor: pointer;
}
.seg button.active { background: var(--accent-strong); color: #fff; }

/* Mapa de Chile */
.map-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 20px; align-items: start; }
.map-stage {
  position: relative;
  height: 580px;
  display: flex;
  justify-content: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
}
#chile-map { height: 100%; max-width: 100%; }
#chile-map path.region {
  stroke: var(--map-stroke);
  stroke-width: 1;
  cursor: pointer;
  transition: opacity var(--transition);
}
#chile-map path.region:hover { stroke: var(--accent); stroke-width: 1.5; }
#chile-map.has-selection path.region:not(.selected) { opacity: 0.3; }
#chile-map path.region.selected { stroke: var(--accent); stroke-width: 1.6; }
.map-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 30;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 7px 11px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
}
.map-tooltip b { display: block; font-size: 12.5px; }
.map-detail {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 10px;
}
.map-detail-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 11px; }
.map-detail-head .title { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 700; }
.map-detail-head .title i { color: var(--accent); }
.map-detail .mini-stat { background: var(--surface-3); }
.map-detail .value.good { color: var(--green); }
.map-detail .value.warn { color: var(--amber); }
.map-detail .value.bad { color: var(--red); }
.badge.zone-good { background: rgba(34, 197, 94, .15); color: #4ade80; }
.badge.zone-warn { background: rgba(245, 158, 11, .15); color: #fbbf24; }
.badge.zone-bad { background: rgba(239, 68, 68, .15); color: #f87171; }
[data-theme="light"] .badge.zone-good { color: #15803d; }
[data-theme="light"] .badge.zone-warn { color: #b45309; }
[data-theme="light"] .badge.zone-bad { color: #b91c1c; }

.map-kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.map-kv td { padding: 3px 0; }
.map-kv td:first-child { color: var(--text-faint); }
.map-kv td:last-child { text-align: right; font-weight: 600; }

.map-rows { display: flex; flex-direction: column; gap: 3px; max-height: 320px; overflow-y: auto; }
.map-row.active { background: var(--accent-soft); }
.map-row.active .name { color: var(--accent); font-weight: 600; }
.map-row {
  display: grid;
  grid-template-columns: minmax(95px, 170px) minmax(40px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
}
.map-row:hover { background: var(--surface-2); }
.map-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); }
.map-row .bar { height: 8px; border-radius: 4px; background: var(--surface-3); position: relative; overflow: hidden; }
.map-row .bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 4px; }
.map-row .val { font-weight: 700; white-space: nowrap; font-size: 12px; }
.map-legend { display: flex; align-items: center; gap: 9px; margin-top: 12px; font-size: 11px; color: var(--text-faint); }
.map-legend .scale { flex: 1; height: 8px; border-radius: 4px; }
@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; }
  .map-stage { height: 400px; }
}

/* Historial de modificaciones (detalle de pedido) */
.changelog { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.changelog > li { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 13px; }
.changelog-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.changelog-head .when { font-size: 11.5px; color: var(--text-faint); }
.changelog-lines { margin: 7px 0 0; padding-left: 18px; font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.changelog-raw { margin-top: 7px; }
.changelog-raw summary {
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-faint);
  list-style: none;
  user-select: none;
}
.changelog-raw summary::-webkit-details-marker { display: none; }
.changelog-raw summary:hover { color: var(--accent); }
.changelog-raw pre {
  margin: 7px 0 0;
  padding: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  line-height: 1.5;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Listas de métricas (warehouse, SLA couriers) */
.stat-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.stat-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.stat-list .name { color: var(--text-soft); display: flex; align-items: center; gap: 8px; }
.stat-list .val { font-weight: 700; }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 12px; }
.mini-stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.mini-stat .label { font-size: 11px; color: var(--text-faint); font-weight: 600; }
.mini-stat .value { font-size: 18px; font-weight: 800; margin-top: 2px; }

.hint { border-bottom: 1px dotted var(--text-faint); cursor: help; }

/* ==========================================================================
   Tablas
   ========================================================================== */

.table-card { padding: 0; overflow: hidden; }
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.table-toolbar .meta { font-size: 12.5px; color: var(--text-soft); }
.table-toolbar .meta b { color: var(--text); }
.table-toolbar .spacer { margin-left: auto; }

.table-scroll { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  padding: 10px 14px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.data th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
table.data th a:hover { color: var(--accent); text-decoration: none; }
table.data td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
table.data tbody tr { cursor: pointer; transition: background var(--transition); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
table.data .soft { color: var(--text-soft); }
table.data .truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

.empty-state { padding: 48px 20px; text-align: center; color: var(--text-faint); }
.empty-state i { font-size: 34px; display: block; margin-bottom: 10px; opacity: .5; }

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 13px 18px;
}
.pagination .info { font-size: 12.5px; color: var(--text-soft); margin-right: auto; }
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12.5px;
  font-weight: 600;
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.page-btn.current { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.page-btn.disabled { opacity: .4; pointer-events: none; }

/* ==========================================================================
   Detalle de pedido
   ========================================================================== */

.detail-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.detail-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.detail-head .actions { margin-left: auto; display: flex; gap: 8px; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--text-faint); font-weight: 500; }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border-strong);
}
.timeline li { position: relative; padding: 0 0 18px 30px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .dot {
  position: absolute;
  left: 0;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
}
.timeline li.delivered .dot { border-color: var(--green); }
.timeline li.problem .dot { border-color: var(--red); }
.timeline .when { font-size: 11.5px; color: var(--text-faint); }
.timeline .what { font-weight: 600; font-size: 13px; }

/* ==========================================================================
   Reportes
   ========================================================================== */

.reports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.report-card { display: flex; flex-direction: column; gap: 12px; }
.report-head { display: flex; gap: 12px; align-items: flex-start; }
.report-icon {
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 18px;
}
.report-head h3 { margin: 0; font-size: 14px; font-weight: 700; }
.report-head p { margin: 3px 0 0; font-size: 12px; color: var(--text-faint); }
.report-form { display: flex; flex-direction: column; gap: 9px; margin-top: auto; }
.report-form .row { display: flex; gap: 8px; }
.report-form .row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-soft); }
.check input { width: auto; accent-color: var(--accent-strong); }

/* ==========================================================================
   Login
   ========================================================================== */

.auth-body { display: flex; min-height: 100vh; }
/* Panel de marca: azul marino Omnitech fijo, en ambos temas, para
   diferenciarlo claramente de la mitad del formulario */
.auth-brand {
  flex: 1.1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 60px;
  background:
    radial-gradient(1000px 500px at -10% -10%, rgba(16, 164, 227, .38), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(0, 123, 193, .45), transparent 62%),
    #0a2540;
}
.auth-brand .logo { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
/* El logo tiene trazos azul oscuro: va sobre un chip claro para destacar del navy */
.auth-brand .logo img {
  width: 38px;
  height: 38px;
  padding: 9px;
  background: #f0f6fc;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(2, 12, 27, 0.35);
}
.auth-brand .brand-text { color: #eef6fd; }
.auth-brand .brand-text span { color: #10a4e3; }
.auth-brand h1 {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0 0 12px;
  line-height: 1.15;
  color: #eef6fd;
}
.auth-brand h1 span { color: #10a4e3; }
.auth-brand p { color: rgba(238, 246, 253, 0.72); font-size: 15px; max-width: 420px; margin: 0; }

.auth-panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 390px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h2 { margin: 0 0 2px; font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.auth-card .hint { color: var(--text-faint); font-size: 13px; margin: 0 0 8px; }
.auth-card .btn-primary { padding: 11px; font-size: 14px; }

@media (max-width: 860px) {
  .auth-brand { display: none; }
}

/* ==========================================================================
   Skeletons / utilidades
   ========================================================================== */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: 6px;
  color: transparent !important;
  min-height: 1em;
  pointer-events: none;
  user-select: none;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

.muted { color: var(--text-faint); }
.flex { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.mt-0 { margin-top: 0; }
.w-100 { width: 100%; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: translateX(0); width: var(--sidebar-w); }
  body.sidebar-open .sidebar .brand-text,
  body.sidebar-open .sidebar .nav-label { display: block; }
  .main { margin-left: 0 !important; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .global-search { display: none; }
  .content { padding: 14px; }
  .kv { grid-template-columns: 110px 1fr; }
}

@media print {
  .sidebar, .topbar, .filterbar, .pagination, .filter-actions { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; }
}
