:root {
  --yellow: #ffe600;
  --yellow-dark: #e6cf00;
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #222222;
  --muted: #666666;
  --line: #dddddd;
  --blue: #3483fa;
  --red: #d1242f;
  --orange: #f59f00;
  --green: #00a650;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  --soft-red: #fdecec;
  --soft-orange: #fff4e0;
  --soft-green: #e9f8ef;
  --soft-blue: #eaf2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.35;
}

.mobile-only {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 24px;
  background: var(--yellow);
  border-bottom: 1px solid var(--yellow-dark);
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.1;
}

.topbar p {
  color: #333333;
}

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

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.sidebar,
.panel,
.metric,
.store-card,
.quality-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  height: fit-content;
  padding: 16px;
  position: sticky;
  top: 16px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
}

.content {
  min-width: 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab,
.button {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 9px 14px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.button.primary,
.button.small.primary {
  background: var(--blue);
  color: #ffffff;
}

.tab.active {
  border-color: var(--blue);
  color: var(--blue);
}

.button.ghost {
  border-color: rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.65);
}

.button.small {
  padding: 6px 10px;
  font-size: 12px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-align: left;
}

.link-button:hover {
  text-decoration: underline;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.kpi-group {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
}

.kpi-group h3 {
  margin-bottom: 4px;
  color: #333333;
  font-size: 15px;
}

.kpi-group-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 2px 18px;
}

.kpi-group .metric {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  padding: 2px 0;
}

.kpi-group .metric .value {
  margin-top: 2px;
  font-size: 30px;
  line-height: 1.05;
}

.metric {
  padding: 16px;
}

.metric .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric .value {
  margin-top: 8px;
  font-size: 32px;
  font-weight: 700;
}

.grid.two {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.8fr);
  gap: 12px;
}

.panel {
  padding: 14px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid #eeeeee;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #fafafa;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eeeeee;
  color: #333333;
  font-size: 12px;
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  border: 1px solid #d7d7d7;
  border-radius: 999px;
  background: #ffffff;
  color: #333333;
  cursor: pointer;
  font-weight: 700;
  padding: 7px 12px;
}

.chip.active {
  border-color: var(--blue);
  background: #eaf2ff;
  color: var(--blue);
}

.priority-Alta {
  color: var(--red);
  font-weight: 700;
}

.priority-Media {
  color: var(--orange);
  font-weight: 700;
}

.priority-Baja {
  color: var(--green);
  font-weight: 700;
}

.list {
  display: grid;
  gap: 10px;
}

.list-row {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #eeeeee;
  font: inherit;
  text-align: left;
}

.list-row.clickable {
  cursor: pointer;
}

.list-row.clickable:hover {
  background: #f7f7f7;
}

.semaphore {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.semaphore::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
}

.semaphore.green::before {
  background: var(--green);
}

.semaphore.yellow::before {
  background: var(--orange);
}

.semaphore.red::before {
  background: var(--red);
}

.store-grid,
.quality-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.store-card,
.quality-card {
  padding: 16px;
}

.store-card-clickable {
  cursor: pointer;
}

.store-card-clickable:hover {
  border-color: var(--blue);
}

.store-card .meta,
.quality-card .meta,
.muted {
  color: var(--muted);
}

.store-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 16px;
}

.route-box {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding: 10px;
  background: #fffbe6;
  border: 1px solid #f2df76;
  border-radius: 4px;
  color: #333333;
  font-size: 13px;
  line-height: 1.35;
}

.store-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  padding: 8px;
  background: #f7f7f7;
  border-radius: 4px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat b {
  display: block;
  margin-top: 4px;
}

.threshold-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
  gap: 14px;
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.detail-hero {
  position: sticky;
  top: 86px;
  z-index: 25;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.status-review {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid #f2c94c;
  border-radius: 999px;
  background: #fff7d6;
  color: #7a4b00;
  font-size: 12px;
  font-weight: 700;
}

.hours-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eeeeee;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.hours-status.low {
  background: var(--soft-red);
  color: var(--red);
}

.hours-status.medium {
  background: var(--soft-orange);
  color: #8a5700;
}

.hours-status.high {
  background: var(--soft-green);
  color: var(--green);
}

.hours-diagnosis {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid #aaaaaa;
  border-radius: 8px;
  background: var(--card);
}

.hours-diagnosis.low {
  border-left-color: var(--red);
}

.hours-diagnosis.medium {
  border-left-color: var(--orange);
}

.hours-diagnosis.high {
  border-left-color: var(--green);
}

.hours-diagnosis strong {
  display: block;
  margin-top: 8px;
  font-size: 16px;
}

.hours-diagnosis p {
  margin: 4px 0 0;
  color: var(--muted);
}

.metric .value .hours-status {
  margin-left: 6px;
  vertical-align: middle;
}

.hours-kpi-summary {
  margin-top: 10px;
  padding: 9px 10px;
  border-left: 4px solid #aaaaaa;
  border-radius: 6px;
  background: #f7f7f7;
}

.hours-kpi-summary.low {
  border-left-color: var(--red);
  background: var(--soft-red);
}

.hours-kpi-summary.medium {
  border-left-color: var(--orange);
  background: var(--soft-orange);
}

.hours-kpi-summary.high {
  border-left-color: var(--green);
  background: var(--soft-green);
}

.hours-kpi-summary strong,
.hours-kpi-summary span {
  display: block;
}

.hours-kpi-summary strong {
  font-size: 13px;
}

.hours-kpi-summary span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.detail-hero h2 {
  margin-top: 6px;
  font-size: 24px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
}

.score-box {
  display: grid;
  place-items: center;
  min-height: 82px;
  border-radius: 10px;
  background: #fffbe6;
  border: 1px solid #f2df76;
}

.score-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.score-box strong {
  font-size: 34px;
}

.back-link {
  font-size: 13px;
}

.detail-kpis,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.detail-grid.compact {
  grid-template-columns: repeat(3, minmax(140px, 1fr));
}

.detail-kpi,
.detail-wide {
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-kpi span,
.detail-wide span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-kpi strong,
.detail-wide strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.empty-state-card {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 420px;
  padding: 32px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  text-align: center;
}

.empty-state-card p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--blue);
  font-size: 34px;
  font-weight: 700;
}

.empty-selector {
  width: min(420px, 100%);
  text-align: left;
}

.checklist-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--soft-blue);
  border: 1px solid #cfe0ff;
  border-radius: 8px;
}

.checklist-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.route-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
}

.amba-map-shell {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid #eeeeee;
  font-weight: 700;
}

.map-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.amba-map {
  position: relative;
  height: 430px;
  overflow: hidden;
  background: #eaf2f8;
}

.map-canvas {
  position: absolute;
  inset: 0;
  transform: scale(var(--map-zoom));
  transform-origin: center;
  transition: transform 0.18s ease;
  border-radius: 0;
  border: 0;
  background:
    radial-gradient(circle at 43% 48%, rgba(255,255,255,0.95) 0 10%, rgba(236,244,251,0.95) 11% 24%, rgba(217,233,246,0.95) 25% 46%, rgba(197,220,238,0.95) 47% 100%),
    linear-gradient(135deg, rgba(52, 131, 250, 0.14), transparent 40%);
}

.map-river {
  position: absolute;
  right: -60px;
  top: -60px;
  width: 210px;
  height: 560px;
  transform: rotate(14deg);
  background: rgba(52, 131, 250, 0.22);
  border-left: 1px solid rgba(52, 131, 250, 0.25);
}

.map-label {
  position: absolute;
  z-index: 2;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: #384454;
  font-size: 12px;
  font-weight: 700;
}

.map-label.capital { left: 42%; top: 45%; }
.map-label.north { left: 29%; top: 23%; }
.map-label.west { left: 22%; top: 52%; }
.map-label.south { left: 48%; top: 72%; }

.map-road {
  position: absolute;
  z-index: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 0 0 1px rgba(110, 130, 150, 0.18);
}

.gral-paz { width: 250px; left: 31%; top: 49%; transform: rotate(82deg); }
.panamericana { width: 270px; left: 22%; top: 31%; transform: rotate(-34deg); }
.acceso-oeste { width: 300px; left: 18%; top: 54%; transform: rotate(6deg); }
.autopista-sur { width: 260px; left: 42%; top: 65%; transform: rotate(32deg); }

.map-pin {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.2);
}

.map-pin small {
  position: absolute;
  top: 35px;
  max-width: 92px;
  color: #222222;
  font-size: 10px;
  text-shadow: 0 1px 0 #ffffff;
  white-space: nowrap;
}

.map-pin.critical {
  background: var(--red);
}

.map-pin.warning {
  background: var(--orange);
}

.map-pin.ok {
  background: var(--green);
}

.route-side {
  max-height: 490px;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.route-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 405px;
  overflow: auto;
  padding-right: 4px;
}

.route-row {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid #eeeeee;
  border-radius: 8px;
  background: #fafafa;
  cursor: pointer;
  text-align: left;
}

.route-row:hover {
  border-color: var(--blue);
  background: var(--soft-blue);
}

.route-row span,
.route-row em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.small-select {
  width: auto;
  min-width: 160px;
}

.detail-wide {
  grid-column: 1 / -1;
}

.first-look {
  margin-bottom: 12px;
}

.insight-list {
  margin: 0;
  padding-left: 20px;
}

.insight-list li {
  margin: 8px 0;
}

.insight-list.large li {
  padding: 10px;
  background: #fafafa;
  border: 1px solid #eeeeee;
  border-radius: 4px;
}

.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.subtab {
  border: 1px solid #d7d7d7;
  border-radius: 999px;
  background: #ffffff;
  cursor: pointer;
  font-weight: 700;
  padding: 7px 12px;
}

.subtab.active {
  border-color: var(--blue);
  background: #eaf2ff;
  color: var(--blue);
}

.checklist {
  display: grid;
  gap: 10px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px;
  background: #fafafa;
  border: 1px solid #eeeeee;
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  text-transform: none;
}

.check-item input {
  width: auto;
  height: auto;
  margin-top: 2px;
}

.check-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .shell,
  .grid.two,
  .route-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .kpi-grid,
  .detail-kpis,
  .detail-grid,
  .store-grid,
  .quality-grid,
  .threshold-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  body {
    font-size: 13px;
    padding-bottom: 68px;
  }

  .mobile-only {
    display: inline-flex;
  }

  .topbar {
    min-height: 58px;
    padding: 8px 12px;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .topbar > div:first-child {
    flex: 0 1 auto;
    min-width: 0;
  }

  .topbar p,
  #generatedAt,
  #resetThresholds {
    display: none;
  }

  .topbar-actions {
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    margin-left: auto;
  }

  #mobileFiltersToggle {
    position: fixed;
    z-index: 50;
    top: 8px;
    right: 10px;
    min-height: 42px;
    margin: 0;
    border-color: rgba(0, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.55);
  }

  .shell {
    display: block;
    padding: 10px 8px 16px;
  }

  .sidebar {
    display: none;
    position: fixed;
    z-index: 38;
    top: 64px;
    right: 8px;
    left: 8px;
    max-height: calc(100vh - 142px);
    overflow-y: auto;
    padding: 14px;
    border-color: #c9c9c9;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
  }

  .sidebar.mobile-open {
    display: block;
  }

  .sidebar label {
    margin-bottom: 10px;
  }

  .sidebar input,
  .sidebar select {
    height: 44px;
    font-size: 16px;
  }

  .tabs {
    position: fixed;
    z-index: 45;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    margin: 0;
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
    overflow-x: auto;
    background: #ffffff;
    border-top: 1px solid var(--line);
    box-shadow: 0 -5px 16px rgba(0, 0, 0, 0.1);
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar,
  .subtabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 44px;
    margin: 0;
    padding: 8px 11px;
    white-space: nowrap;
  }

  .panel {
    padding: 12px;
  }

  .panel-head {
    align-items: flex-start;
    gap: 8px;
  }

  .panel-head h2 {
    font-size: 17px;
  }

  .kpi-grid,
  .store-grid,
  .quality-grid,
  .threshold-grid {
    grid-template-columns: 1fr;
  }

  .kpi-group-grid,
  .detail-kpis,
  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-group-grid > *,
  .detail-kpis > *,
  .detail-grid > * {
    min-width: 0;
  }

  .kpi-group {
    padding: 12px;
  }

  .metric {
    min-height: 74px;
    padding: 9px;
  }

  .metric .label {
    font-size: 10px;
  }

  .metric .value,
  .kpi-group .metric .value {
    max-width: 100%;
    font-size: 21px;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }

  .metric .value .hours-status {
    display: flex;
    width: fit-content;
    margin: 5px 0 0;
  }

  .hours-kpi-summary {
    margin-top: 8px;
  }

  .detail-hero {
    position: static;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px;
  }

  .detail-hero > div:first-child {
    grid-column: 1 / -1;
  }

  .detail-hero h2 {
    font-size: 20px;
  }

  .detail-kpi,
  .detail-wide {
    padding: 10px;
  }

  .detail-kpi strong,
  .detail-wide strong {
    font-size: 19px;
  }

  .subtabs {
    flex-wrap: nowrap;
    margin: 0 -4px 12px;
    padding: 0 4px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .subtab {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }

  .table-wrap {
    margin: 0 -12px;
    padding: 0 12px;
  }

  table {
    min-width: 620px;
    font-size: 12px;
  }

  th,
  td {
    padding: 8px;
  }

  th:first-child,
  td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #ffffff;
    box-shadow: 1px 0 0 var(--line);
  }

  th:first-child {
    z-index: 3;
    background: #f7f7f7;
  }

  .button,
  .chip,
  .route-row {
    min-height: 44px;
  }

  .checklist-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .checklist-toolbar .panel-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .checklist-toolbar .button {
    width: 100%;
  }

  .route-layout {
    gap: 10px;
  }

  .amba-map-shell,
  .route-side {
    min-height: 0;
  }

  .route-list {
    max-height: 280px;
  }
}
