
:root {
  color-scheme: light;

  --primary: #003876;
  --primary-2: #0056a6;
  --secondary: #198754;

  --warning: #a86400;
  --danger: #bd2c2c;

  --bg: #f4f7fb;
  --card: #ffffff;
  --soft: #f8fafc;
  --soft-2: #eef5fb;

  --border: #d9e2ec;
  --text: #1f2937;
  --muted: #667085;

  --table-head: #f2f6fb;
  --row-hover: #f7fbff;

  --shadow:
    0 6px 18px rgba(15, 23, 42, 0.06);

  --modal-overlay:
    rgba(3, 18, 35, 0.62);
}

html[data-theme="dark"] {
  color-scheme: dark;

  --primary: #78b7ff;
  --primary-2: #4d9df5;
  --secondary: #42c98a;

  --warning: #f2b84b;
  --danger: #ff7167;

  --bg: #08111f;
  --card: #111c2d;
  --soft: #172438;
  --soft-2: #1d2d43;

  --border: #2a3d55;
  --text: #e8eef7;
  --muted: #9caec4;

  --table-head: #17263a;
  --row-hover: #172a42;

  --shadow:
    0 8px 24px rgba(0, 0, 0, 0.28);

  --modal-overlay:
    rgba(0, 0, 0, 0.74);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Segoe UI",
    Tahoma,
    Geneva,
    Verdana,
    sans-serif;
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

button,
input,
select {
  font: inherit;
}

.app {
  max-width: 1760px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 24px;
  overflow-x: hidden;
}

.topbar,
.card,
.page-heading,
.toolbar-card,
.grid-wrapper {
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 22px;

  margin-bottom: 18px;
  padding: 22px 26px;
  border-radius: 18px;
}

.title h1 {
  margin: 0;
  color: var(--primary);
  font-size: 28px;
  letter-spacing: -0.03em;
}

.title p {
  max-width: 760px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.title-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.institution {
  min-width: 440px;
  color: var(--muted);
  text-align: right;
  font-size: 13px;
  line-height: 1.5;
}

.header-controls,
.nav-actions,
.heading-badges,
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.header-controls,
.nav-actions {
  justify-content: flex-end;
}

.header-controls {
  margin-top: 10px;
}

.nav-actions {
  margin-top: 10px;
}

.source-control {
  display: flex;
  align-items: center;
  gap: 7px;
}

.source-control span {
  font-weight: 700;
  color: var(--muted);
}

.source-control select {
  min-width: 170px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;

  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;

  background: var(--soft);
  color: var(--primary);

  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  font-weight: 750;

  transition:
    transform 0.12s ease,
    background-color 0.12s ease,
    border-color 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: var(--soft-2);
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--card);
}

html[data-theme="dark"] .btn.primary {
  color: #061322;
}

.theme-button {
  min-width: 92px;
}

.product-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 170px;
}

.product-cell strong {
  color: var(--text);
}

.product-id {
  font-size: 11px;
  font-weight: 700;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
  padding: 16px 4px 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.rule-draft-summary {
  margin-bottom: 14px;
  padding: 11px 13px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
}

.rule-editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.rule-editor-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule-editor-field.full {
  grid-column: 1 / -1;
}

.rule-editor-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rule-editor-field textarea {
  min-height: 92px;
  resize: vertical;
}

.rule-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.rule-modified {
  display: inline-block;
  margin-top: 5px;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;

  margin-bottom: 18px;
  padding: 18px;
  border-radius: 18px;
}

.page-heading h2 {
  margin: 0;
  color: var(--primary);
  font-size: 24px;
}

.page-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

.card,
.toolbar-card,
.grid-wrapper {
  padding: 18px;
  border-radius: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.kpi-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.kpi-value {
  color: var(--primary);
  font-size: 29px;
  font-weight: 850;
  line-height: 1.1;
}

.kpi-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
  margin-bottom: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin: 0;
  color: var(--primary);
  font-size: 20px;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;

  background: var(--primary-2);
  color: #ffffff;

  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
}

.badge.green {
  background: var(--secondary);
}

.badge.amber {
  background: var(--warning);
}

.badge.red {
  background: var(--danger);
}

.badge.gray {
  background: #64748b;
}

.badge.source-paiz {
  background: #1f6fbd;
}

.badge.source-colonia {
  background: #178b68;
}

.filters {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.filters.compact {
  align-items: end;
}

.mesa-filters {
  grid-template-columns:
    minmax(260px, 1.8fr)
    repeat(4, minmax(150px, 1fr));
}


.filters label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input,
select {
  width: 100%;
  padding: 10px 11px;

  border: 1px solid var(--border);
  border-radius: 10px;

  background: var(--soft);
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary-2);
  box-shadow:
    0 0 0 3px
    color-mix(
      in srgb,
      var(--primary-2) 20%,
      transparent
    );
}

.toolbar-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;

  margin-bottom: 18px;
}

.toolbar-card p {
  margin: 5px 0 0;
}

.grid-wrapper {
  overflow: auto;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;

  background: var(--table-head);
  color: var(--primary);

  white-space: nowrap;
  font-size: 12px;
}

tr:hover td {
  background: var(--row-hover);
}

code {
  display: inline-block;
  max-width: 360px;
  overflow-wrap: anywhere;

  padding: 3px 6px;
  border-radius: 6px;

  background: var(--soft);
  color: var(--text);
}

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

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;

  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;

  background: var(--soft);
}

.narrative {
  color: var(--text);
  line-height: 1.65;
}

.muted,
.footnote {
  color: var(--muted);
}

.footnote {
  font-size: 12px;
}

.product-cell {
  min-width: 270px;
}

.product-cell strong {
  color: var(--primary);
}

.price-stack {
  white-space: nowrap;
}

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

.detail-button {
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 99;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 20px;
  background: var(--modal-overlay);
}

.modal.hidden {
  display: none;
}

.modal-box {
  position: relative;

  width: min(1040px, 100%);
  max-height: 90vh;
  overflow: auto;

  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 20px;

  background: var(--card);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.42);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;

  width: 36px;
  height: 36px;

  border: 1px solid var(--border);
  border-radius: 999px;

  background: var(--soft);
  color: var(--text);

  cursor: pointer;
  font-size: 22px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;

  margin-top: 18px;
}

.detail-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
}

.detail-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.quality-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

.methodology-note {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 14px 22px;
}

.methodology-note > .muted {
  grid-column: 1 / -1;
  margin: 0;
}

.methodology-note h2 {
  margin: 0 0 6px;
}

.methodology-note p {
  margin: 0;
}

.methodology-badge {
  align-self: start;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--soft-2);
  color: var(--primary-2);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.progress-filters {
  grid-template-columns:
    minmax(220px, 2fr)
    repeat(5, minmax(145px, 1fr));
}

@media (max-width: 900px) {
  .methodology-note {
    grid-template-columns: 1fr;
  }

  .methodology-note > .muted {
    grid-column: auto;
  }

  .methodology-badge {
    justify-self: start;
  }
}


.table-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  width: max-content;
  min-width: 100%;
}

.rules-table-scroll {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.rules-table-scroll code {
  min-width: 170px;
  max-width: 260px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rules-table-scroll td:first-child,
.rules-table-scroll th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--card);
}

.rules-table-scroll th:first-child {
  z-index: 5;
  background: var(--table-head);
}

.prices-filters {
  grid-template-columns:
    minmax(220px, 2fr)
    repeat(5, minmax(145px, 1fr));
}


.rules-filters {
  display: grid;
  grid-template-columns: minmax(300px, 2fr) minmax(220px, 1fr);
  align-items: end;
  margin: 14px 0;
}

.rules-count-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
}

.product-evidence {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  gap: 18px;
  align-items: start;
  margin-top: 16px;
}

.product-evidence img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
}

.audit-box {
  border-left: 4px solid var(--danger);
}

@media (max-width: 760px) {
  .rules-filters,
  .product-evidence {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1320px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .mesa-filters {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .app {
    padding: 14px;
  }

  .topbar,
  .page-heading,
  .toolbar-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .institution {
    min-width: 0;
    text-align: left;
  }

  .header-controls,
  .nav-actions {
    justify-content: flex-start;
  }


  .site-footer {
    flex-direction: column;
  }

  .rule-editor-grid {
    grid-template-columns: 1fr;
  }

  .main-grid,
  .detail-grid,
  .progress-filters,
  .mesa-filters,
  .prices-filters {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
