/* ============================================================================
   SINOPTIC TRACKER · METROPOL CHILE UI v2
   Archivo completo renovado para dashboard operativo DTP / P.O.
   ============================================================================ */

:root {
  --m-navy-950: #061a38;
  --m-navy-900: #0a2550;
  --m-navy-850: #0e3266;
  --m-blue-700: #0b57a4;
  --m-blue-600: #145da8;
  --m-blue-500: #2563eb;
  --m-blue-100: #e8f1fb;
  --m-red-700: #bd1815;
  --m-red-600: #e1251b;
  --m-red-500: #ef3430;
  --m-red-100: #ffe8e7;
  --m-green-700: #047857;
  --m-green-600: #16a34a;
  --m-green-100: #dcfce7;
  --m-yellow-700: #a16207;
  --m-yellow-500: #f59e0b;
  --m-yellow-100: #fef3c7;
  --m-orange-500: #fb923c;
  --m-bg: #f4f7fb;
  --m-surface: #ffffff;
  --m-surface-2: #f8fafc;
  --m-surface-3: #eef4fb;
  --m-border: #d9e1ec;
  --m-border-2: #c7d3e3;
  --m-text: #1c2a39;
  --m-muted: #5b6b7c;
  --m-muted-2: #73839a;
  --m-shadow-soft: 0 10px 28px rgba(9, 30, 66, 0.08);
  --m-shadow-card: 0 14px 36px rgba(9, 30, 66, 0.12);
  --m-shadow-modal: 0 28px 70px rgba(6, 26, 56, 0.24);
  --m-radius-sm: 10px;
  --m-radius: 14px;
  --m-radius-lg: 18px;
  --m-radius-xl: 24px;
  --dtp-row-h: 44px;
  --dtp-z-drawer: 500;
  --dtp-z-modal: 900;
}

* { box-sizing: border-box; }

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

html { scroll-behavior: smooth; }

body.metropol-ui,
body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, rgba(20, 93, 168, 0.14) 0, transparent 32%),
    radial-gradient(circle at 92% 10%, rgba(225, 37, 27, 0.08) 0, transparent 26%),
    linear-gradient(180deg, #f8fbff 0%, var(--m-bg) 44%, #edf2f7 100%);
  color: var(--m-text);
  font-family: "Segoe UI", "Inter", "Roboto", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.is-modal-open,
body.is-drawer-open { overflow: hidden; }

button,
input,
select,
textarea { font: inherit; }

button {
  border: 0;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease, opacity 160ms ease;
}

button:disabled { opacity: .58; cursor: not-allowed; transform: none !important; }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .18);
  border-color: var(--m-blue-600) !important;
}

/* ============================================================================
   LAYOUT GENERAL
   ============================================================================ */

.dashboard {
  width: min(100%, 1920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 18px 22px;
}

.dashboard-header {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  margin-bottom: 18px;
  color: #fff;
  border-radius: var(--m-radius-lg);
  background:
    linear-gradient(135deg, rgba(10, 37, 80, .98) 0%, rgba(14, 50, 102, .98) 52%, rgba(11, 87, 164, .98) 100%),
    radial-gradient(circle at 95% 0%, rgba(255,255,255,.18), transparent 32%);
  box-shadow: var(--m-shadow-card);
  position: sticky;
  top: 10px;
  z-index: 100;
  overflow: hidden;
}

.dashboard-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, transparent 0 55%, rgba(255,255,255,.08) 55% 70%, transparent 70%),
    radial-gradient(circle at 2% 50%, rgba(225, 37, 27, .24), transparent 26%);
  pointer-events: none;
}

.dashboard-header-left,
.dashboard-header-right { position: relative; z-index: 1; }
.dashboard-header-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.dashboard-header-right { text-align: right; font-size: 12px; color: rgba(255,255,255,.88); display: grid; gap: 4px; }

.brand-logo {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #fff;
  box-shadow: 0 10px 26px rgba(0,0,0,.18), inset 0 0 0 1px rgba(10, 37, 80, .08);
  overflow: hidden;
}
.brand-logo img { width: 82%; height: 82%; object-fit: contain; }

.header-title { min-width: 0; display: grid; gap: 2px; }
.header-brand-kicker {
  color: rgba(255,255,255,.78);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.header-app-name { font-size: 22px; font-weight: 850; letter-spacing: .01em; }
.header-subtitle { color: rgba(255,255,255,.82); font-size: 12px; font-weight: 500; }
.header-terminal b,
.header-date b { color: #fff; font-weight: 800; }

.dtp-monitor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.panel {
  position: relative;
  border: 1px solid rgba(217, 225, 236, .95);
  border-radius: var(--m-radius-lg);
  background: rgba(255,255,255,.92);
  box-shadow: var(--m-shadow-soft);
  overflow: hidden;
}
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--m-red-600), var(--m-blue-700) 35%, transparent 100%);
  opacity: .95;
}
.panel-title {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  color: var(--m-navy-900);
  font-size: 14px;
  font-weight: 850;
  letter-spacing: .01em;
}
.panel-title .icon { font-size: 15px; }
.panel-title::after {
  content: "";
  height: 2px;
  flex: 1;
  margin-left: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--m-blue-700), rgba(11,87,164,0));
}
.panel-subtitle {
  color: var(--m-navy-850);
  font-weight: 700;
  font-size: 12px;
}

/* ============================================================================
   BOTONES
   ============================================================================ */

.btn-primary,
#btn-aplicar-filtros {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--m-red-600), var(--m-red-700));
  box-shadow: 0 8px 18px rgba(225, 37, 27, .22);
  font-weight: 850;
}
.btn-primary:hover,
#btn-aplicar-filtros:hover { transform: translateY(-1px); box-shadow: 0 12px 24px rgba(225, 37, 27, .28); }

.btn-outline,
#btn-ir-actual {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--m-navy-900);
  background: #fff;
  border: 1px solid var(--m-border-2);
  box-shadow: 0 6px 16px rgba(9,30,66,.06);
  font-weight: 800;
}
.btn-outline:hover,
#btn-ir-actual:hover { border-color: var(--m-blue-700); color: var(--m-blue-700); transform: translateY(-1px); }

.btn-ghost,
#btn-editar-po,
#btn-descargar-dia {
  min-height: 37px;
  width: 100%;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--m-navy-900);
  background: linear-gradient(180deg, #fff, #f7fbff);
  border: 1px solid var(--m-border-2);
  box-shadow: 0 6px 16px rgba(9,30,66,.05);
  font-weight: 750;
}
.btn-ghost:hover,
#btn-editar-po:hover,
#btn-descargar-dia:hover { background: var(--m-blue-100); border-color: rgba(11,87,164,.35); transform: translateY(-1px); }

.btn-chip,
.acciones-superior button {
  min-height: 27px;
  padding: 0 11px;
  border-radius: 999px;
  color: var(--m-navy-900);
  background: #eef4fb;
  border: 1px solid #d7e2ef;
  font-size: 12px;
  font-weight: 800;
}
.btn-chip:hover,
.acciones-superior button:hover { color: #fff; background: var(--m-blue-700); border-color: var(--m-blue-700); transform: translateY(-1px); }
.btn-chip-current,
#btn-franja-actual { color: #fff; background: var(--m-navy-850); border-color: var(--m-navy-850); }

.btn-secondary,
.modal-footer button {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  color: #fff;
  background: var(--m-blue-700);
  box-shadow: 0 8px 18px rgba(11, 87, 164, .18);
  font-weight: 850;
}
.btn-secondary:hover,
.modal-footer button:hover { background: var(--m-navy-850); transform: translateY(-1px); }

/* ============================================================================
   DRAWER DE FILTROS
   ============================================================================ */

.filter-toggle {
  position: fixed;
  left: 0;
  top: 50%;
  z-index: 420;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 86px;
  padding: 10px 6px;
  border-radius: 0 14px 14px 0;
  writing-mode: vertical-rl;
  color: var(--m-navy-900);
  background: rgba(255,255,255,.96);
  border: 1px solid var(--m-border);
  border-left: 0;
  box-shadow: 0 10px 24px rgba(9,30,66,.13);
  font-size: 12px;
  font-weight: 900;
}
.filter-toggle:hover { color: #fff; background: var(--m-navy-850); }
.filter-toggle.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.filter-toggle-icon { writing-mode: horizontal-tb; font-size: 14px; }

.filters-drawer {
  position: fixed;
  inset: 0;
  z-index: var(--dtp-z-drawer);
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}
.filters-drawer.is-open { opacity: 1; pointer-events: auto; }
.filters-drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 30, 66, .20);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.filters-drawer-panel {
  position: absolute;
  top: 18px;
  right: 20px;
  width: min(390px, calc(100vw - 32px));
  max-height: calc(100vh - 36px);
  transform: translateX(24px) scale(.985);
  transition: transform 180ms ease;
}
.filters-drawer.is-open .filters-drawer-panel { transform: translateX(0) scale(1); }
.filters-drawer .panel-filtros {
  padding: 18px;
  border: 1px solid rgba(199, 211, 227, .95);
  border-radius: 20px;
  background: rgba(255,255,255,.97);
  box-shadow: var(--m-shadow-modal);
}
.filters-drawer .panel-title {
  padding: 0 36px 12px 0;
  margin: 0;
  align-items: flex-start;
  flex-wrap: wrap;
}
.filters-drawer .panel-title::after { display: none; }
.filters-drawer .panel-subtitle { display: block; flex: 1 0 100%; padding-left: 24px; color: var(--m-navy-900); }
.filters-drawer-close {
  position: absolute;
  top: 10px;
  right: 11px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: var(--m-muted);
  background: #fff;
  border: 1px solid transparent;
  font-size: 21px;
  line-height: 1;
}
.filters-drawer-close:hover { color: var(--m-red-600); background: var(--m-red-100); border-color: rgba(225,37,27,.2); }
.filters-block { display: grid; gap: 10px; }
.filter-row { display: grid; gap: 5px; }
.filter-row label {
  color: var(--m-muted);
  font-size: 12px;
  font-weight: 750;
}
.filter-row input,
.filter-row select,
.modal input,
.modal select,
.modal textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  color: var(--m-text);
  background: #fff;
  border: 1px solid var(--m-border-2);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(9,30,66,.03);
}
.filter-row input:hover,
.filter-row select:hover { border-color: rgba(11,87,164,.42); }
.filter-row-actions { grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 3px; }

/* ============================================================================
   PANEL DE FRANJA Y TABLA PRINCIPAL
   ============================================================================ */

.panel-resumen { padding-bottom: 12px; }
.acciones-superior {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  padding: 0 16px 8px;
}
.franja-header { padding: 4px 16px 12px; text-align: center; }
.franja-header-titulo {
  color: var(--m-navy-900);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: .02em;
}
.table-responsive,
.tabla-cumplimiento-wrapper,
.indicadores-patios-wrapper,
.detalle-servicio-table-wrapper {
  width: calc(100% - 24px);
  margin: 0 12px;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid var(--m-border);
  background: #fff;
}
.cumplimiento-table,
.indicadores-patios-table,
.detalle-servicio-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--m-text);
}
.cumplimiento-table thead th,
.indicadores-patios-table thead th,
.detalle-servicio-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, #f5f8ff, #edf3fd);
  color: var(--m-navy-900);
  font-weight: 900;
  font-size: 12px;
  text-align: center;
  padding: 13px 10px;
  border-bottom: 1px solid var(--m-border);
}
.cumplimiento-table th,
.cumplimiento-table td,
.detalle-servicio-table th,
.detalle-servicio-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #eef2f7;
  text-align: center;
  vertical-align: middle;
}
.cumplimiento-table tbody td { height: var(--dtp-row-h); font-weight: 650; }
.cumplimiento-table th:nth-child(1),
.cumplimiento-table td:nth-child(1) { width: 42%; text-align: left; }
.cumplimiento-table th:nth-child(2),
.cumplimiento-table td:nth-child(2) { width: 22%; }
.cumplimiento-table th:nth-child(3),
.cumplimiento-table td:nth-child(3) { width: 18%; }
.cumplimiento-table th:nth-child(4),
.cumplimiento-table td:nth-child(4) { width: 18%; }
.cumplimiento-table tbody tr { transition: filter 120ms ease, transform 120ms ease; }
.cumplimiento-table tbody tr:hover td { filter: brightness(.985); }
.cumplimiento-table tbody tr[data-ts] { cursor: pointer; }
.cumplimiento-servicio { font-weight: 850 !important; color: var(--m-navy-900); }

.row-rojo td,
.row-rojo { background: #fde2e1 !important; color: #8b1a16; }
.row-amarillo td,
.row-amarillo { background: #fff3c4 !important; color: #7c4a03; }
.row-verde td,
.row-verde { background: #d9f8e4 !important; color: #075f42; }

.sentido-badge,
.badge-sentido,
.cumplimiento-table .sentido {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 19px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #fff;
  color: var(--m-navy-900);
  border: 1px solid #dbe5f1;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.resumen-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 11px 12px 0;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--m-text);
  background: #fff;
  border: 1px solid var(--m-border);
  box-shadow: 0 4px 12px rgba(9,30,66,.04);
  font-weight: 650;
}
.badge-leyenda { color: var(--m-muted); }
.cuadro { display: inline-block; width: 13px; height: 9px; border-radius: 3px; margin-left: 3px; }
.cuadro.rojo { background: #fecaca; }
.cuadro.amarillo { background: #fde68a; }
.cuadro.verde { background: #bbf7d0; }

/* ============================================================================
   GRÁFICOS
   ============================================================================ */

.panel-graficos {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
  background: transparent;
  box-shadow: none;
  border: 0;
  overflow: visible;
}
.panel-graficos::before { display: none; }
.panel-grafico {
  min-height: 320px;
  padding: 16px;
}
.panel-grafico-titulo {
  color: var(--m-navy-900);
  font-size: 15px;
  font-weight: 900;
  margin-bottom: 10px;
}
.panel-grafico canvas { width: 100% !important; max-height: 270px; }

/* ============================================================================
   INDICADORES KPI
   ============================================================================ */

.panel-indicadores-resumen { padding-bottom: 14px; }
.indicadores-resumen-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 0 12px;
}
.indicador-card {
  min-height: 118px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 16px 16px 16px 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, #fff, #f8fbff);
  border: 1px solid var(--m-border);
  box-shadow: 0 10px 24px rgba(9,30,66,.06);
  position: relative;
  overflow: hidden;
}
.indicador-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--m-blue-700);
}
.indicador-card::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(11,87,164,.08);
}
.indicador-card-title { color: var(--m-navy-900); font-size: 12px; font-weight: 950; letter-spacing: .04em; z-index: 1; }
.indicador-card-pct { color: var(--m-navy-950); font-size: 28px; line-height: 1; font-weight: 950; z-index: 1; }
.indicador-card-meta { color: var(--m-muted); font-size: 12px; font-weight: 800; z-index: 1; }
.indicador-card-desc { color: var(--m-muted); font-size: 11px; z-index: 1; }
.indicador-good::before { background: var(--m-green-600); }
.indicador-good::after { background: rgba(22,163,74,.10); }
.indicador-mid::before { background: var(--m-yellow-500); }
.indicador-mid::after { background: rgba(245,158,11,.12); }
.indicador-bad::before { background: var(--m-red-600); }
.indicador-bad::after { background: rgba(225,37,27,.10); }
.indicador-null::before,
.indicador-empty::before { background: var(--m-muted-2); }
.indicador-empty { grid-column: 1 / -1; min-height: 76px; color: var(--m-muted); }

/* ============================================================================
   HEATMAP POR PATIO
   ============================================================================ */

.panel-indicadores-patios { padding-bottom: 14px; }
.indicadores-patios-wrapper { max-height: 430px; }
.indicadores-patios-table { min-width: 1180px; }
.indicadores-patios-table thead th {
  color: #fff;
  background: linear-gradient(180deg, var(--m-navy-850), var(--m-navy-900));
  border-right: 1px solid rgba(255,255,255,.12);
  white-space: nowrap;
}
.indicadores-patios-table th,
.indicadores-patios-table td {
  padding: 9px 8px;
  border-right: 1px solid rgba(255,255,255,.35);
  border-bottom: 1px solid #e6edf5;
  text-align: center;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 850;
}
.indicadores-row-name {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 160px;
  color: var(--m-navy-900);
  text-align: left !important;
  background: linear-gradient(180deg, #fff, #f5f8fc);
  border-right: 1px solid var(--m-border) !important;
}
.indicator-cell { color: #fff; }
.indicator-cell-verde { background: linear-gradient(180deg, #22c55e, #16a34a); }
.indicator-cell-amarillo { background: linear-gradient(180deg, #fbbf24, #f59e0b); color: #3b2a04; }
.indicator-cell-rojo { background: linear-gradient(180deg, #ef4444, #dc2626); }
.indicator-cell-empty { background: #101827; color: #e5e7eb; }
.indicadores-empty { color: var(--m-muted); text-align: center; padding: 18px !important; background: #fff; }

/* ============================================================================
   MODAL DETALLE DE BUSES
   ============================================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--dtp-z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal.is-open { display: flex; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 30, 66, .24);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  background: #fff;
  border: 1px solid rgba(199, 211, 227, .92);
  box-shadow: var(--m-shadow-modal);
  overflow: hidden;
  animation: modalIn 170ms ease both;
}
.modal-dialog-wide { width: min(940px, 100%); }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  color: #fff;
  background:
    radial-gradient(circle at 90% 0%, rgba(225, 37, 27, .34), transparent 36%),
    linear-gradient(135deg, var(--m-navy-900), var(--m-blue-700));
}
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 950; letter-spacing: .01em; }
.modal-subtitle { margin-top: 3px; color: rgba(255,255,255,.84); font-size: 12px; font-weight: 650; }
.modal-close {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.20);
  font-size: 24px;
  line-height: 1;
}
.modal-close:hover { background: rgba(225,37,27,.85); }
.modal-body {
  padding: 16px 18px;
  overflow: auto;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--m-border);
  background: #f8fbff;
}
.detalle-servicio-empty {
  min-height: 76px;
  display: grid;
  place-items: center;
  color: var(--m-muted);
  background: #f8fbff;
  border: 1px dashed var(--m-border-2);
  border-radius: 14px;
}
.detalle-servicio-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.detalle-summary-card {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--m-border);
  background: linear-gradient(180deg, #fff, #f7fbff);
}
.detalle-summary-label { color: var(--m-muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.detalle-summary-value { margin-top: 4px; color: var(--m-navy-900); font-size: 17px; font-weight: 950; }
.detalle-servicio-table-wrapper { width: 100%; margin: 0; max-height: 420px; }
.detalle-servicio-table thead th { text-align: left; }
.detalle-servicio-table td { text-align: left; font-size: 12px; }
.detalle-servicio-table tbody tr:hover td { background: #f8fbff; }

/* ============================================================================
   UTILIDADES / LEGACY
   ============================================================================ */

.dashboard-main,
.main-left,
.main-center-top,
.main-center-bottom,
.main-right { min-width: 0; }
.hidden { display: none !important; }
.text-muted { color: var(--m-muted); }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Scrollbars suaves */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #c7d3e3; border-radius: 999px; border: 2px solid #f8fbff; }
*::-webkit-scrollbar-track { background: #f8fbff; }

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

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

@media (max-width: 760px) {
  .dashboard { padding: 10px; }
  .dashboard-header { position: relative; top: auto; align-items: flex-start; flex-direction: column; border-radius: 16px; }
  .dashboard-header-right { align-items: flex-start; text-align: left; }
  .header-app-name { font-size: 20px; }
  .brand-logo { width: 50px; height: 50px; flex-basis: 50px; }
  .panel-title { padding: 13px 12px 8px; flex-wrap: wrap; }
  .panel-title::after { flex-basis: 100%; margin-left: 0; }
  .acciones-superior { padding-left: 12px; padding-right: 12px; }
  .table-responsive,
  .tabla-cumplimiento-wrapper,
  .indicadores-patios-wrapper { width: calc(100% - 16px); margin-left: 8px; margin-right: 8px; }
  .cumplimiento-table { min-width: 620px; }
  .panel-graficos { padding: 8px 0; }
  .panel-grafico { min-height: 280px; }
  .indicadores-resumen-grid { grid-template-columns: 1fr; padding: 0 8px; }
  .detalle-servicio-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal { padding: 10px; align-items: flex-end; }
  .modal-dialog { max-height: 90vh; border-radius: 18px 18px 0 0; }
  .filter-row-actions { grid-template-columns: 1fr; }
  .filters-drawer-panel { top: auto; right: 0; bottom: 0; width: 100%; max-height: 92vh; transform: translateY(22px); }
  .filters-drawer.is-open .filters-drawer-panel { transform: translateY(0); }
  .filters-drawer .panel-filtros { border-radius: 20px 20px 0 0; }
}

@media (max-width: 420px) {
  .detalle-servicio-summary { grid-template-columns: 1fr; }
  .franja-header-titulo { font-size: 14px; }
}

/* ============================================================================
   V4 RESPONSIVE METROPOL — móviles / tablets sin alterar desktop
   Breakpoints orientados a iPhone, Samsung, Huawei, Xiaomi y tablets.
   ============================================================================ */

@media (hover: none) and (pointer: coarse) {
  .btn,
  .btn-primary,
  .btn-outline,
  .btn-ghost,
  .btn-chip,
  button,
  select,
  input {
    min-height: 44px;
  }
  .cumplimiento-table tbody tr,
  .tabla-indicadores-patio td {
    cursor: pointer;
  }
}

@media (max-width: 1280px) {
  .dashboard {
    padding: 14px;
  }
  .dashboard-header {
    margin-bottom: 14px;
  }
  .panel-principal,
  .panel-grafico,
  .indicadores-franja-panel,
  .indicadores-patios-panel {
    border-radius: 18px;
  }
}

@media (min-width: 761px) and (max-width: 1180px) {
  .dashboard-header {
    min-height: 82px;
    padding: 18px 22px;
  }
  .dashboard-header::after {
    opacity: .72;
  }
  .header-app-name {
    font-size: 23px;
  }
  .header-subtitle,
  .dashboard-header-right {
    font-size: 12px;
  }
  .filters-drawer-panel {
    width: min(430px, 46vw);
  }
  .cumplimiento-table {
    min-width: 780px;
  }
  .panel-grafico {
    min-height: 330px;
  }
  .indicadores-patios-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tabla-indicadores-patio {
    min-width: 1120px;
  }
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body.metropol-ui {
    background:
      radial-gradient(circle at top left, rgba(14, 50, 102, .08), transparent 320px),
      linear-gradient(180deg, #f3f7fc 0%, #eef4fa 100%);
  }

  .dashboard {
    width: 100%;
    padding: 10px 9px 16px;
  }

  .dashboard-header {
    min-height: auto;
    gap: 12px;
    padding: 16px 16px;
    margin-bottom: 12px;
    border-radius: 18px;
    overflow: hidden;
  }

  .dashboard-header::before {
    width: 5px;
  }

  .dashboard-header::after {
    right: -22%;
    width: 78%;
    opacity: .42;
  }

  .dashboard-header-left {
    width: 100%;
    min-width: 0;
    align-items: center;
  }

  .brand-logo {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
  }

  .header-kicker {
    font-size: 9px;
    letter-spacing: .08em;
    line-height: 1.2;
  }

  .header-app-name {
    font-size: clamp(19px, 6vw, 24px);
    line-height: 1.05;
  }

  .header-subtitle {
    font-size: 11px;
    line-height: 1.25;
  }

  .dashboard-header-right {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,.18);
    font-size: 11px;
    text-align: left;
  }

  .panel-principal {
    border-radius: 18px;
    margin-bottom: 12px;
  }

  .panel-title {
    gap: 7px;
    padding: 12px 12px 8px;
    font-size: 12px;
    line-height: 1.35;
  }

  .panel-title::after {
    height: 2px;
  }

  .acciones-superior {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 12px 10px;
  }

  .acciones-superior .btn-chip,
  .acciones-superior button,
  .acciones-superior a {
    width: 100%;
    justify-content: center;
    white-space: nowrap;
    padding: 0 10px;
    font-size: 11px;
  }

  .acciones-superior .btn-chip:nth-child(2) {
    grid-column: span 2;
    order: -1;
  }

  .franja-header-titulo {
    padding: 14px 10px 10px;
    font-size: clamp(14px, 4.6vw, 17px);
    line-height: 1.2;
  }

  .tabla-cumplimiento-wrapper,
  .table-responsive,
  .indicadores-patios-wrapper {
    width: calc(100% - 14px);
    margin-left: 7px;
    margin-right: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px;
  }

  .tabla-cumplimiento-wrapper::after,
  .indicadores-patios-wrapper::after {
    content: 'Desliza horizontalmente';
    position: sticky;
    left: 0;
    display: block;
    padding: 7px 10px;
    color: #5b6b7c;
    background: #f8fbff;
    border-top: 1px solid #d9e1ec;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
  }

  .cumplimiento-table {
    min-width: 680px;
    font-size: 12px;
  }

  .cumplimiento-table th,
  .cumplimiento-table td {
    padding: 13px 12px;
  }

  .cumplimiento-table th:first-child,
  .cumplimiento-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    box-shadow: 8px 0 14px rgba(9,30,66,.08);
  }

  .cumplimiento-table th:first-child {
    background: #edf3fb;
    z-index: 4;
  }

  .cumplimiento-table tr.cump-ok td:first-child { background: #d9f7e5; }
  .cumplimiento-table tr.cump-mid td:first-child { background: #fff3c4; }
  .cumplimiento-table tr.cump-low td:first-child { background: #fde1e1; }

  .chips-resumen {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding: 8px 8px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .chips-resumen .chip,
  .chips-resumen .badge,
  .leyenda-chip {
    flex: 0 0 auto;
  }

  .panel-graficos {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 2px 0 12px;
  }

  .panel-grafico {
    min-height: 310px;
    border-radius: 18px;
  }

  .panel-grafico canvas {
    max-height: 250px !important;
  }

  .indicadores-franja-panel,
  .indicadores-patios-panel {
    border-radius: 18px;
    margin-bottom: 12px;
  }

  .indicadores-resumen-grid {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    padding: 0 8px 12px;
  }

  .indicador-card {
    min-height: 112px;
    padding: 14px 12px;
    border-radius: 15px;
  }

  .indicador-card .indicador-value,
  .indicador-value {
    font-size: clamp(24px, 8vw, 34px);
  }

  .indicador-card .indicador-title,
  .indicador-title {
    font-size: 11px;
  }

  .indicador-card .indicador-detail,
  .indicador-detail {
    font-size: 10px;
    line-height: 1.25;
  }

  .tabla-indicadores-patio {
    min-width: 1180px;
    font-size: 11px;
  }

  .tabla-indicadores-patio th,
  .tabla-indicadores-patio td {
    padding: 10px 9px;
  }

  .tabla-indicadores-patio th:first-child,
  .tabla-indicadores-patio td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #f8fbff;
    box-shadow: 8px 0 14px rgba(9,30,66,.10);
  }

  .tabla-indicadores-patio th:first-child {
    background: var(--m-navy-900);
    z-index: 5;
  }

  .filters-tab {
    top: auto;
    left: 8px;
    bottom: 18px;
    height: 46px;
    min-width: 46px;
    padding: 0 13px;
    border-radius: 999px;
    writing-mode: horizontal-tb;
    transform: none;
    box-shadow: 0 12px 28px rgba(9,30,66,.26);
    z-index: 60;
  }

  .filters-tab span,
  .filters-tab .label {
    writing-mode: horizontal-tb;
    transform: none;
  }

  .filters-drawer {
    align-items: flex-end;
  }

  .filters-drawer-panel {
    width: 100%;
    max-width: none;
    max-height: min(88dvh, 740px);
    top: auto;
    bottom: 0;
    right: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(100%);
  }

  .filters-drawer.is-open .filters-drawer-panel {
    transform: translateY(0);
  }

  .filters-drawer .panel-filtros {
    max-height: min(88dvh, 740px);
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .filter-header,
  .panel-filtros-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(12px);
  }

  .filter-grid,
  .filters-grid {
    gap: 10px;
  }

  .filter-grid label,
  .filters-grid label,
  .filter-label {
    font-size: 11px;
  }

  .filter-grid input,
  .filter-grid select,
  .filters-grid input,
  .filters-grid select {
    height: 45px;
    font-size: 13px;
    border-radius: 12px;
  }

  .filter-row-actions,
  .filter-actions {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(255,255,255,.76), #fff 28%);
  }

  .filter-row-actions .btn-primary,
  .filter-row-actions .btn-outline,
  .filter-row-actions .btn-ghost,
  .filter-actions .btn-primary,
  .filter-actions .btn-outline,
  .filter-actions .btn-ghost {
    width: 100%;
  }

  .modal {
    padding: 8px;
    align-items: flex-end;
  }

  .modal-dialog {
    width: 100%;
    max-width: none;
    max-height: min(88dvh, 740px);
    border-radius: 22px 22px 0 0;
    overflow: hidden;
  }

  .modal-header,
  .detalle-modal-header {
    padding: 16px 18px;
  }

  .modal-title,
  .detalle-modal-title {
    font-size: 17px;
  }

  .modal-subtitle,
  .detalle-modal-subtitle {
    font-size: 11px;
    word-break: break-word;
  }

  .modal-body,
  .detalle-modal-body {
    max-height: calc(min(88dvh, 740px) - 146px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px;
  }

  .detalle-servicio-summary {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .detalle-summary-card {
    padding: 11px 12px;
    border-radius: 13px;
  }

  .detalle-summary-label {
    font-size: 9.5px;
  }

  .detalle-summary-value {
    font-size: 14px;
    line-height: 1.2;
  }

  .detalle-servicio-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px;
  }

  .detalle-servicio-table {
    min-width: 720px;
  }

  .modal-footer,
  .detalle-modal-footer {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }

  .modal-footer .btn-primary,
  .modal-footer .btn-outline,
  .detalle-modal-footer .btn-primary,
  .detalle-modal-footer .btn-outline {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .dashboard {
    padding-left: 7px;
    padding-right: 7px;
  }

  .dashboard-header {
    padding: 14px;
  }

  .dashboard-header-left {
    gap: 10px;
  }

  .brand-logo {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .header-subtitle {
    max-width: 260px;
  }

  .dashboard-header-right {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .acciones-superior {
    grid-template-columns: 1fr;
  }

  .acciones-superior .btn-chip:nth-child(2) {
    grid-column: auto;
  }

  .cumplimiento-table {
    min-width: 640px;
  }

  .cumplimiento-table th,
  .cumplimiento-table td {
    padding: 12px 10px;
  }

  .indicadores-resumen-grid {
    grid-template-columns: 1fr;
  }

  .panel-grafico {
    min-height: 290px;
  }

  .panel-grafico canvas {
    max-height: 230px !important;
  }

  .detalle-servicio-summary {
    grid-template-columns: 1fr;
  }

  .modal-body,
  .detalle-modal-body {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 380px) {
  .header-app-name {
    font-size: 19px;
  }
  .header-subtitle,
  .dashboard-header-right {
    font-size: 10.5px;
  }
  .panel-title {
    font-size: 11px;
  }
  .franja-header-titulo {
    font-size: 14px;
  }
  .cumplimiento-table {
    min-width: 610px;
  }
  .tabla-indicadores-patio {
    min-width: 1080px;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 960px) {
  .dashboard-header {
    position: relative;
    min-height: auto;
    padding: 10px 14px;
  }
  .brand-logo {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }
  .header-app-name {
    font-size: 18px;
  }
  .header-subtitle,
  .header-kicker,
  .dashboard-header-right {
    font-size: 10px;
  }
  .filters-drawer-panel,
  .filters-drawer .panel-filtros,
  .modal-dialog {
    max-height: 94dvh;
  }
  .modal-body,
  .detalle-modal-body {
    max-height: calc(94dvh - 132px);
  }
}

/* V7 - sobreoferta: se visualiza sin afectar el cumplimiento, que queda limitado a 100%. */
.detalle-servicio-table tr.detalle-row-over td {
  background: rgba(245, 158, 11, 0.10);
}

.detalle-servicio-table tr.detalle-row-over td:last-child {
  color: #92400e;
  font-weight: 800;
}
