:root {
  --bg: #0b0c0f;
  --bg-alt: #121419;
  --card: #171a21;
  --card-border: #262a34;
  --text: #eef0f4;
  --text-dim: #9099ab;
  --text-faint: #5e6678;
  --accent: #ff6a00;
  --accent-soft: rgba(255, 106, 0, .12);
  --blue: #3b82f6;
  --green: #2fbf71;
  --amber: #ffb020;
  --red: #ff4d4f;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-width: 1180px;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- Shell ---------------- */
.app-shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: var(--bg-alt);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 18px;
}
.brand-icon { font-size: 26px; }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand small { color: var(--text-dim); font-size: 12px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item i { width: 18px; text-align: center; }
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-faint);
  padding: 10px 8px 0;
  border-top: 1px solid var(--card-border);
}
.sidebar-footer i { color: var(--green); }

/* ---------------- Topbar ---------------- */
.main-area { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  padding: 22px 32px;
  border-bottom: 1px solid var(--card-border);
  background: var(--bg-alt);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title h1 { margin: 0; font-size: 20px; font-weight: 700; }
.topbar-title p { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }

.filters-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-ranges {
  display: flex;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.qr-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
}
.qr-btn.active { background: var(--accent); color: #fff; }
.qr-btn:hover:not(.active) { color: var(--text); }

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
}
.filter-field input,
.filter-field select {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  min-width: 130px;
}
.filter-field input:focus,
.filter-field select:focus { outline: none; border-color: var(--accent); }

.apply-btn, .refresh-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.apply-btn { background: var(--accent); color: #fff; }
.apply-btn:hover { filter: brightness(1.1); }
.refresh-btn { background: var(--card); color: var(--text-dim); border: 1px solid var(--card-border); padding: 9px 12px; }
.refresh-btn:hover { color: var(--text); }

/* ---------------- Content ---------------- */
.content { padding: 28px 32px 60px; }

/* ---------------- KPI Cards ---------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 26px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.kpi-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}
.kpi-blue { background: rgba(59,130,246,.14); color: var(--blue); }
.kpi-green { background: rgba(47,191,113,.14); color: var(--green); }
.kpi-amber { background: rgba(255,176,32,.14); color: var(--amber); }
.kpi-red { background: rgba(255,77,79,.14); color: var(--red); }

.kpi-body { display: flex; flex-direction: column; min-width: 0; }
.kpi-value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ---------------- Charts ---------------- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 26px;
}
.chart-wide { grid-column: 1 / -1; }

.chart-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
}
.chart-head { margin-bottom: 14px; }
.chart-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.chart-head i { color: var(--accent); }

/* ---------------- Table ---------------- */
.table-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
}
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.table-head h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.table-head i { color: var(--accent); }

.table-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.table-search i { color: var(--text-faint); font-size: 12px; }
.table-search input {
  background: transparent; border: none; color: var(--text);
  font-size: 13px; outline: none; width: 220px;
}

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--card-border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--bg-alt); }
.table-empty { text-align: center; color: var(--text-faint); padding: 30px !important; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-ok { background: rgba(47,191,113,.14); color: var(--green); }
.badge-alert { background: rgba(255,77,79,.14); color: var(--red); }

.progress-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.progress-track { flex: 1; height: 6px; border-radius: 4px; background: var(--bg-alt); overflow: hidden; }
.progress-fill-table { height: 100%; background: var(--accent); }

.audit-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.audit-btn:hover { background: var(--accent); color: #fff; }

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-dim);
}
.page-btn {
  background: var(--bg-alt);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  display: flex; align-items: center; gap: 6px;
}
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn:hover:not(:disabled) { border-color: var(--accent); }

/* ---------------- Modal de Auditoría ---------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }

.modal-panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  width: min(1000px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--card-border);
}
.modal-head h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.modal-head i { color: var(--accent); }
.modal-close {
  background: var(--bg-alt);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  width: 32px; height: 32px;
  border-radius: 8px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 22px; overflow-y: auto; }
.audit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.audit-grid h4 { margin: 0 0 12px; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .03em; }

.audit-text {
  background: var(--bg-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 480px;
  overflow-y: auto;
  font-family: 'SFMono-Regular', Consolas, monospace;
}

.audit-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
}
.audit-photo-card {
  background: var(--bg-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.audit-photo-card img { width: 100%; height: 120px; object-fit: cover; display: block; }
.audit-photo-note { padding: 8px 10px; font-size: 11.5px; color: var(--text-dim); }
.audit-gallery-empty { color: var(--text-faint); font-size: 13px; padding: 10px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
