/* ==================================================
   1. Variables y temas
   ================================================== */
:root {
  --bg: #e8ebee;
  --surface: #fff;
  --ink: #17212b;
  --muted: #5b6773;
  --line: #cfd5db;
  --brand: #12355b;
  --accent: #e8792b;
  --brand-ink: #fff;
  --ok: #2e7d4f;
  --low: #b26a00;
  --out: #b3261e;
  --use: #1f5fa8;
  --okbg: #e2f1e8;
  --lowbg: #fbeccf;
  --outbg: #f8dedb;
  --usebg: #dce9f8;
  box-sizing: border-box;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10161d;
    --surface: #19212a;
    --ink: #e6ebf0;
    --muted: #98a4b0;
    --line: #2c3743;
    --brand: #1d4a7e;
    --accent: #f29a54;
    --brand-ink: #fff;
    --ok: #6fcf97;
    --low: #f2b34d;
    --out: #ff8a80;
    --use: #8ab8ef;
    --okbg: #17301f;
    --lowbg: #3a2c10;
    --outbg: #3d1c19;
    --usebg: #17283d;
  }
}
:root[data-theme="dark"] {
  --bg: #10161d;
  --surface: #19212a;
  --ink: #e6ebf0;
  --muted: #98a4b0;
  --line: #2c3743;
  --brand: #1d4a7e;
  --accent: #f29a54;
  --brand-ink: #fff;
  --ok: #6fcf97;
  --low: #f2b34d;
  --out: #ff8a80;
  --use: #8ab8ef;
  --okbg: #17301f;
  --lowbg: #3a2c10;
  --outbg: #3d1c19;
  --usebg: #17283d;
}
* {
  box-sizing: border-box;
}

/* ==================================================
   2. Base del documento
   ================================================== */
html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.5 Barlow,
    system-ui,
    sans-serif;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  background: var(--brand);
  z-index: 30;
}
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand);
  color: var(--brand-ink);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
}
.top h1 {
  font:
    700 1.6rem/1 "Barlow Condensed",
    Impact,
    sans-serif;
  margin: 0;
}
.top small {
  opacity: 0.8;
  display: block;
  font-size: 0.8rem;
}

/* ==================================================
   3. Controles e interacciones
   ================================================== */
button,
input,
select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  min-height: 44px;
}
button {
  cursor: pointer;
}
.burger {
  background: transparent;
  color: var(--brand-ink);
  border: 1px solid rgba(255, 255, 255, 0.4);
  width: 44px;
  padding: 0;
  font-size: 1.4rem;
}
.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: var(--brand);
  font-weight: 600;
}
:focus-visible {
  outline: 3px solid var(--use);
  outline-offset: 2px;
}

/* ==================================================
   4. Encabezado y navegación
   ================================================== */
nav {
  position: fixed;
  z-index: 25;
  top: 0;
  bottom: 0;
  left: 0;
  width: 260px;
  max-width: 82vw;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 12px;
  transform: translateX(-105%);
  transition: transform 0.2s;
}
nav.open {
  transform: none;
}
nav h2 {
  font:
    700 1.4rem/1 "Barlow Condensed",
    Impact,
    sans-serif;
  margin: 8px 8px 12px;
}
nav a {
  display: block;
  padding: 12px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}
nav a.on {
  background: var(--brand);
  color: var(--brand-ink);
}
#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 22;
  display: none;
}
#scrim.show {
  display: block;
}

/* ==================================================
   5. Contenido principal y títulos
   ================================================== */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 40px);
}
a {
  color: var(--use);
}
h2.t {
  font:
    700 2rem/1.1 "Barlow Condensed",
    Impact,
    sans-serif;
  margin: 0 0 4px;
}
.sub {
  color: var(--muted);
  margin: 0 0 16px;
}

/* ==================================================
   6. Resúmenes estadísticos y tarjetas
   ================================================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}
.stat b {
  display: block;
  font:
    700 1.9rem/1 "Barlow Condensed",
    Impact,
    sans-serif;
}
.stat span,
.m {
  color: var(--muted);
  font-size: 0.9rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 16px;
}
.card h3 {
  font:
    600 1.3rem/1.2 "Barlow Condensed",
    Impact,
    sans-serif;
  margin: 0 0 8px;
}

/* ==================================================
   7. Barras de herramientas
   ================================================== */
.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.bar input {
  flex: 1 1 200px;
}
.tb {
  overflow-x: auto;
}

/* ==================================================
   8. Tablas
   ================================================== */
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
tr:last-child td {
  border-bottom: 0;
}
.n {
  font-variant-numeric: tabular-nums;
}

/* ==================================================
   9. Etiquetas de estado
   ================================================== */
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.ok {
  background: var(--okbg);
  color: var(--ok);
}
.low {
  background: var(--lowbg);
  color: var(--low);
}
.out {
  background: var(--outbg);
  color: var(--out);
}
.use {
  background: var(--usebg);
  color: var(--use);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.li:last-child {
  border: 0;
}

/* ==================================================
   10. Formularios y estados vacíos
   ================================================== */
.empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
}
form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
}
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ==================================================
   11. Acciones y estilos especiales
   ================================================== */
@media (min-width: 900px) {
  .burger {
    display: none;
  }
  nav {
    transform: none;
    top: 64px;
    z-index: 10;
    width: 240px;
    padding-top: 12px;
  }
  main {
    margin: 0 auto 0 240px;
    max-width: 1080px;
    padding: 24px 32px 40px;
  }
  .top {
    padding-left: 20px;
  }
  .top h1 {
    font-size: 1.9rem;
  }
}
.top {
  border-bottom: 3px solid var(--accent);
}
nav a.on {
  box-shadow: inset 4px 0 var(--accent);
}
nav {
  overflow-y: auto;
}
.cl {
  cursor: pointer;
}
.cl:hover {
  background: var(--bg);
}
.acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.danger {
  color: var(--out);
  border-color: var(--out);
}
.primary.danger {
  background: var(--out);
  color: #fff;
}
@media (min-width: 900px) {
  nav {
    top: 67px;
  }
}
/* Perfil en la esquina superior derecha */
.perfil {
  margin-left: auto;
  position: relative;
}
.perfil-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--brand-ink);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 99px;
  padding: 4px 14px 4px 4px;
  min-height: 40px;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: none;
}
.perfil-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 270px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 40;
}
.cuenta {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 6px;
}
button.cuenta:hover {
  background: var(--bg);
}
@media (max-width: 600px) {
  .perfil-btn .pn {
    display: none; /* en celular solo se ve el círculo con la inicial */
  }
}