:root {
  --color-navy: #1C4E73;
  --color-navy-dark: #143a56;
  --color-red-marca: #D6362B;
  --color-dorado: #F4B400;
  --color-bg-page: #f9f9f7;
  --color-bg-card: #ffffff;
  --color-text: #1C4E73;
  --color-text-muted: #52514e;
  --color-border: #e1e0d9;

  --color-estado-bueno: #0ca30c;
  --color-estado-alerta: #fab219;
  --color-estado-serio: #ec835a;
  --color-estado-critico: #d03b3b;
  --color-estado-neutro: #898781;

  --radius: 8px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --font-system: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-system);
  margin: 0;
  background: var(--color-bg-page);
  color: #1a1a1a;
  line-height: 1.5;
}

.error {
  color: var(--color-estado-critico);
}

/* Header */

.app-header {
  background: var(--color-navy);
  color: #ffffff;
  padding: 0.75rem 1.5rem;
}

.app-header .wordmark {
  font-size: 1.4rem;
  font-weight: 700;
  color: #ffffff;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 {
  color: var(--color-navy);
  margin-top: 0;
}

h2 {
  color: var(--color-navy);
}

/* Login */

.login-card {
  max-width: 360px;
  margin: 3rem auto;
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 2rem;
}

.login-card label {
  display: block;
  text-align: left;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

/* Buttons & inputs */

button, .btn {
  background: var(--color-navy);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
}

button:hover, .btn:hover {
  background: var(--color-navy-dark);
}

input[type="number"], input[type="text"], input[type="password"] {
  padding: 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
}

/* Stat tiles */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem;
  text-align: center;
}

.stat-tile .valor {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--color-navy);
}

.stat-tile .etiqueta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Rubro cards + progress bars */

.rubro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.rubro-card {
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem;
}

.rubro-card h3 {
  margin: 0 0 0.5rem;
  color: var(--color-navy);
  font-size: 1.05rem;
}

.cifras {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.progress-bar {
  background: var(--color-border);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.progress-bar-fill.estado-bueno { background: var(--color-estado-bueno); }
.progress-bar-fill.estado-alerta { background: var(--color-estado-alerta); }
.progress-bar-fill.estado-serio { background: var(--color-estado-serio); }
.progress-bar-fill.estado-critico { background: var(--color-estado-critico); }

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  margin-top: 0.35rem;
}

.badge.estado-bueno { background: var(--color-estado-bueno); color: #1a1a1a; }
.badge.estado-neutro { background: var(--color-estado-neutro); }

/* Conteo por rango */

.rango-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.rango-tile {
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
  color: #ffffff;
}

.rango-tile .cantidad {
  font-size: 1.5rem;
  font-weight: 700;
  display: block;
}

.rango-tile.estado-bueno { background: var(--color-estado-bueno); color: #1a1a1a; }
.rango-tile.estado-alerta { background: var(--color-estado-alerta); color: #1a1a1a; }
.rango-tile.estado-serio { background: var(--color-estado-serio); color: #1a1a1a; }
.rango-tile.estado-critico { background: var(--color-estado-critico); }

/* Vendedor grid (dashboard gerencia) */

.vendedor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.vendedor-card {
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem;
  text-decoration: none;
  color: var(--color-navy);
  font-weight: 600;
  display: block;
}

.vendedor-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Configurador cards */

.config-card {
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem;
  margin-bottom: 1rem;
}

.config-card h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.config-card ul {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
}

.config-card li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--color-border);
}

.config-card form {
  display: inline-block;
}

/* Tables (cuotas/bonificaciones matrix) */

.table-wrapper {
  overflow-x: auto;
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  margin-bottom: 1.5rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
}

th, td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

thead th {
  background: var(--color-navy);
  color: #ffffff;
  position: sticky;
  top: 0;
}

tbody tr:nth-child(even) {
  background: var(--color-bg-page);
}

/* Mensajes de estado vacio */

.mensaje-vacio {
  color: var(--color-text-muted);
  font-style: italic;
  padding: 1rem 0;
}

/* Mobile */

@media (max-width: 600px) {
  main {
    padding: 1rem;
  }

  .app-header {
    padding: 0.75rem 1rem;
  }
}

.nav-mes {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.nav-mes a {
  color: var(--color-navy);
  text-decoration: none;
}

.nav-mes a:hover {
  color: var(--color-red-marca);
}

.celda-consolidada {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  font-weight: 600;
}

.celda-consolidada.estado-bueno { background: var(--color-estado-bueno); color: #1a1a1a; }
.celda-consolidada.estado-alerta { background: var(--color-estado-alerta); color: #1a1a1a; }
.celda-consolidada.estado-serio { background: var(--color-estado-serio); color: #1a1a1a; }
.celda-consolidada.estado-critico { background: var(--color-estado-critico); }

/* Sidebar (gerencia) */

.app-shell {
  display: flex;
  align-items: flex-start;
}

.app-shell > main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
}

.sidebar-toggle-checkbox {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.sidebar-toggle-boton {
  display: none;
}

.sidebar-gerencia {
  width: 220px;
  flex-shrink: 0;
  background: var(--color-bg-card);
  box-shadow: var(--shadow-card);
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

.sidebar-gerencia nav {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.sidebar-seccion {
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin: 1.25rem 0 0.25rem;
  padding: 0 1rem;
}

.sidebar-link {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--color-navy);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.sidebar-link:hover {
  color: var(--color-red-marca);
}

.sidebar-link-activo {
  background: var(--color-navy);
  color: #ffffff;
}

.sidebar-link-activo:hover {
  color: #ffffff;
}

.sidebar-grupo summary {
  cursor: pointer;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-navy);
  list-style: none;
}

.sidebar-grupo summary::-webkit-details-marker {
  display: none;
}

.sidebar-grupo summary::after {
  content: " \25BE";
}

.sidebar-grupo[open] summary::after {
  content: " \25B4";
}

.sidebar-grupo .sidebar-link {
  padding-left: 2rem;
}

.sidebar-salir {
  margin: 1rem 1rem 0;
}

.sidebar-salir button {
  width: 100%;
}

@media (max-width: 600px) {
  .sidebar-toggle-boton {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 101;
    background: var(--color-navy);
    color: #ffffff;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    padding: 0.75rem 1rem;
    cursor: pointer;
  }

  .sidebar-toggle-checkbox:focus-visible ~ .sidebar-toggle-boton {
    outline: 2px solid var(--color-dorado);
  }

  .sidebar-gerencia {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    min-height: 100vh;
  }

  .sidebar-toggle-checkbox:checked ~ .sidebar-gerencia {
    transform: translateX(0);
  }

  .app-shell > main {
    max-width: 100%;
  }
}
