:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --sidebar: #12233e;
  --sidebar-hover: #1b3358;
  --sidebar-active: #0f7a5f;
  --accent: #0f7a5f;
  --accent-soft: #e3f3ee;
  --text: #1c2430;
  --text-muted: #6b7686;
  --border: #e3e6ec;
  --danger: #c0392b;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-data: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 68px;
}

[data-theme="dark"] {
  --bg: #0e131c;
  --panel: #171e2b;
  --sidebar: #0a1220;
  --sidebar-hover: #16253d;
  --sidebar-active: #12946f;
  --accent: #16a883;
  --accent-soft: #103b30;
  --text: #e7ecf5;
  --text-muted: #8a96ab;
  --border: #263042;
  --danger: #e5766a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  transition: background 0.15s, color 0.15s;
}

button {
  font-family: inherit;
}

/* ---------- LOGIN ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--sidebar) 0%, #0a1626 100%);
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 10px;
  padding: 36px 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.login-brand .mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-family: var(--font-data);
  flex-shrink: 0;
}

.login-brand span {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
}

.login-card h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  font-size: 14px;
  outline: none;
  background: var(--panel);
  color: var(--text);
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s;
}

.btn-primary:hover {
  filter: brightness(0.92);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.login-error {
  background: #fdecea;
  color: var(--danger);
  font-size: 13px;
  padding: 9px 11px;
  border-radius: 6px;
  margin-bottom: 14px;
  display: none;
}

[data-theme="dark"] .login-error {
  background: #2c1614;
}

/* ---------- APP SHELL ---------- */
.app-shell {
  display: none;
  min-height: 100vh;
  grid-template-columns: var(--sidebar-w) 1fr;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.visible {
  display: grid;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: #dfe6f0;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: padding 0.18s ease;
}

.sidebar-collapsed .sidebar {
  padding: 16px 8px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 18px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar-brand .mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: var(--font-data);
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  min-width: 0;
  overflow: hidden;
}

.sidebar-brand-text div:first-child {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.sidebar-brand .ruc {
  font-size: 11px;
  color: #9fb0c7;
  font-family: var(--font-data);
  white-space: nowrap;
}

.collapse-btn {
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: #cfd9e8;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.collapse-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .nav-section-label,
.sidebar-collapsed .nav-item span.label,
.sidebar-collapsed .user-chip,
.sidebar-collapsed .logout-btn span.label {
  display: none;
}

.sidebar-collapsed .sidebar-top {
  justify-content: center;
}

.sidebar-collapsed .sidebar-brand {
  justify-content: center;
}

.sidebar-collapsed .nav-item {
  justify-content: center;
}

.sidebar-collapsed .logout-btn {
  padding: 8px 0;
}

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7f8fa8;
  padding: 10px 10px 6px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: #cfd9e8;
  margin-bottom: 2px;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--sidebar-hover);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.nav-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-chip {
  font-size: 12.5px;
  color: #9fb0c7;
  padding: 8px 10px;
  overflow: hidden;
}

.user-chip strong {
  color: #e8edf5;
  display: block;
  font-size: 13px;
  white-space: nowrap;
}

.theme-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cfd9e8;
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  margin-bottom: 6px;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
}

.logout-btn {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cfd9e8;
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- MOBILE TOP BAR ---------- */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--sidebar);
  color: #fff;
  padding: 12px 14px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.mobile-topbar button {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  font-size: 16px;
  cursor: pointer;
}

.sidebar-overlay-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 39;
}

/* ---------- MAIN CONTENT ---------- */
.main {
  padding: 28px 34px;
  overflow-y: auto;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 8px;
}

.page-header h2 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
}

.page-header .eyebrow {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.filters-row {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filters-row .field {
  margin-bottom: 0;
  min-width: 220px;
  flex: 1 1 220px;
}

.filters-row .btn-primary {
  width: auto;
  padding: 10px 22px;
  margin-top: 0;
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
}

.stat-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1 1 180px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-family: var(--font-data);
  font-size: 26px;
  font-weight: 700;
  margin-top: 6px;
  color: var(--accent);
  word-break: break-word;
}

/* ---------- Grafico de barras (CSS puro, sin dependencias externas) ---------- */
.bars-chart-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.bars-chart {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 200px;
  min-width: max-content;
  padding: 10px 4px 0;
}

.bar-col {
  flex: 0 0 auto;
  width: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  cursor: default;
}

.bar-col .bar {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.2s ease;
}

.bar-col.is-peak .bar {
  background: #dd8f2e;
}

.bar-col .bar-label {
  font-size: 9.5px;
  color: var(--text-muted);
  margin-top: 5px;
  font-family: var(--font-data);
}

.bars-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  flex-wrap: wrap;
}

.bars-legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}

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

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td.num, th.num {
  text-align: right;
  font-family: var(--font-data);
}

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

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge.admin {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.user {
  background: var(--border);
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 28, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 10px;
  padding: 22px 24px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h3 {
  margin: 0 0 16px;
  font-size: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn-secondary {
  flex: 1;
  padding: 10px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
}

.checkbox-list {
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 8px;
}

.icon-btn.danger {
  color: var(--danger);
}

/* ---------- RESPONSIVE / MOBILE ---------- */
@media (max-width: 860px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    max-width: 82vw;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    padding: 16px 14px;
  }

  .app-shell.mobile-nav-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.mobile-nav-open .sidebar-overlay-backdrop {
    display: block;
  }

  .sidebar-collapsed .sidebar-brand-text,
  .sidebar-collapsed .nav-section-label,
  .sidebar-collapsed .nav-item span.label,
  .sidebar-collapsed .user-chip {
    display: block;
  }

  .collapse-btn {
    display: none;
  }

  .main {
    padding: 18px 16px 40px;
  }

  .page-header h2 {
    font-size: 18px;
  }

  .filters-row {
    flex-direction: column;
    align-items: stretch;
  }

  .filters-row .field {
    min-width: 0;
  }

  .filters-row .btn-primary {
    width: 100%;
  }

  .stat-row {
    flex-direction: column;
  }
}
