:root {
  --ink-900: #142028;
  --ink-700: #47585f;
  --ink-500: #6d7d83;
  --paper: #eef1ef;
  --card: #ffffff;
  --line: #d7dedb;
  --accent: #2f6f8f;
  --accent-ink: #1f4f66;
  --accent-soft: #e2eef2;
  --amber: #a4700f;
  --amber-bg: #f7ecd7;
  --amber-line: #e6cb98;
  --green: #2c7a52;
  --green-bg: #e2f1e7;
  --green-line: #b9dcc5;
  --red: #b3402f;
  --red-bg: #f8e5e1;
  --red-line: #eec2b7;
  --shadow: 0 1px 2px rgba(20, 32, 40, 0.06), 0 6px 20px -8px rgba(20, 32, 40, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink-900: #e9eef0;
    --ink-700: #b7c4c8;
    --ink-500: #8fa0a5;
    --paper: #101a20;
    --card: #17242b;
    --line: #2b3a41;
    --accent: #6fb6d4;
    --accent-ink: #9ccfe6;
    --accent-soft: #1c333d;
    --amber: #e0ac52;
    --amber-bg: #34291a;
    --amber-line: #5c4726;
    --green: #6fc796;
    --green-bg: #17301f;
    --green-line: #2c4d37;
    --red: #e39284;
    --red-bg: #35201c;
    --red-line: #5c352d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 26px -10px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --ink-900: #e9eef0;
  --ink-700: #b7c4c8;
  --ink-500: #8fa0a5;
  --paper: #101a20;
  --card: #17242b;
  --line: #2b3a41;
  --accent: #6fb6d4;
  --accent-ink: #9ccfe6;
  --accent-soft: #1c333d;
  --amber: #e0ac52;
  --amber-bg: #34291a;
  --amber-line: #5c4726;
  --green: #6fc796;
  --green-bg: #17301f;
  --green-line: #2c4d37;
  --red: #e39284;
  --red-bg: #35201c;
  --red-line: #5c352d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 26px -10px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-900);
  font-family: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace; font-variant-numeric: tabular-nums; }

a { color: var(--accent); }

/* ---------- Encabezado / navegación ---------- */
header.app {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.marca { display: flex; align-items: center; gap: 10px; }
.marca .sello {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 0.95rem;
  flex: none;
}
.marca .nombre { font-weight: 600; font-size: 1.02rem; letter-spacing: -0.01em; }
.marca .sub { font-size: 0.76rem; color: var(--ink-500); margin-top: 1px; }

nav.tabs { display: flex; gap: 4px; }
nav.tabs a {
  font-family: inherit; font-size: 0.88rem; font-weight: 500;
  background: none; border: none; color: var(--ink-700);
  padding: 8px 14px; border-radius: 7px; cursor: pointer;
  display: inline-block;
}
nav.tabs a:hover { background: var(--accent-soft); }
nav.tabs a.activo { background: var(--accent); color: #fff; }

.usuario { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--ink-700); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--amber-bg); color: var(--amber);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 600; border: 1px solid var(--amber-line);
  flex: none;
}
.usuario .salir {
  font-family: inherit; font-size: 0.8rem; font-weight: 500;
  background: transparent; color: var(--ink-500); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 6px; cursor: pointer;
}
.usuario .salir:hover { border-color: var(--ink-500); color: var(--ink-900); }

main, .contenedor { max-width: 940px; margin: 0 auto; padding: 30px 24px 80px; }

.encabezado-vista { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 4px; flex-wrap: wrap; }
.encabezado-vista h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
.encabezado-vista .conteo { font-size: 0.85rem; color: var(--ink-500); }
.lead { color: var(--ink-700); font-size: 0.92rem; margin: 6px 0 26px; max-width: 62ch; }

h1 { font-size: 1.5rem; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }

/* ---------- Botones y formularios ---------- */
button, .btn {
  font-family: inherit; font-size: 0.86rem; font-weight: 600;
  background: var(--accent); color: #fff; border: none;
  padding: 9px 16px; border-radius: 7px; cursor: pointer;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-ink); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primario, .btn.primario { background: var(--accent); color: #fff; }

button.secundario, .btn.secundario, button.fantasma, .btn.fantasma {
  background: transparent; color: var(--ink-700); border: 1px solid var(--line); font-weight: 500; font-size: 0.83rem;
  padding: 8px 13px;
}
button.secundario:hover, .btn.secundario:hover, button.fantasma:hover, .btn.fantasma:hover {
  border-color: var(--ink-500); color: var(--ink-900); background: transparent;
}

button.peligro, .btn.peligro { background: var(--red); }
button.peligro:hover { background: var(--red); opacity: 0.88; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

label { display: block; font-size: 0.74rem; color: var(--ink-500); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: 0.03em; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="file"], textarea, select {
  width: 100%;
  font-family: inherit;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.92rem;
  background: var(--paper);
  color: var(--ink-900);
}
input[type="number"], input[type="date"] { font-family: "IBM Plex Mono", monospace; }

textarea { resize: vertical; min-height: 70px; }

.fila { display: flex; gap: 10px; }
.fila > * { flex: 1; }

.carga-item-row { border: 1px solid var(--line); border-radius: 9px; padding: 12px; margin-bottom: 10px; background: var(--paper); }
.carga-item-row .fila { margin-bottom: 6px; }
.carga-item-row .fila:last-child { margin-bottom: 0; }

.error { color: var(--red); font-size: 0.86rem; margin-top: 8px; }
.ok { color: var(--green); font-size: 0.86rem; margin-top: 8px; }
.muted { color: var(--ink-500); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge.pendiente { background: var(--amber-bg); color: var(--amber); }
.badge.dividida { background: var(--green-bg); color: var(--green); }
.badge.bot { background: var(--accent-soft); color: var(--accent-ink); }
.badge.manual { background: var(--paper); color: var(--ink-500); border: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 0.87rem; }
th { color: var(--ink-500); font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.monto, td.mono { font-family: "IBM Plex Mono", monospace; }

/* ---------- Tarjetas genéricas (login, setup, config) ---------- */
.centro-pantalla {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.card-login { width: 100%; max-width: 380px; }

/* ---------- Ticket de carga (tarjeta con guarda perforada) ---------- */
.ticket {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.ticket .resumen {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 18px; cursor: pointer;
}
.ticket .resumen:hover { background: var(--accent-soft); }
.ticket .numero {
  flex: none; width: 62px; text-align: center;
  font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; color: var(--ink-500);
}
.ticket .numero b { display: block; font-size: 1.05rem; color: var(--ink-900); font-weight: 600; }
.ticket .cuerpo { flex: 1; min-width: 0; }
.ticket .tipos { font-weight: 500; font-size: 0.95rem; }
.ticket .meta { font-size: 0.8rem; color: var(--ink-500); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.ticket .meta .pdf { color: var(--accent); }
.ticket .monto { flex: none; text-align: right; font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 1rem; }
.ticket .monto small { display: block; font-family: "IBM Plex Sans", sans-serif; font-weight: 400; font-size: 0.72rem; color: var(--ink-500); margin-top: 2px; }

.sello-estado {
  flex: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 4px; border: 1.5px solid;
  transform: rotate(-3deg);
}
.sello-estado.pendiente { color: var(--amber); border-color: var(--amber-line); background: var(--amber-bg); }
.sello-estado.dividida { color: var(--green); border-color: var(--green-line); background: var(--green-bg); transform: rotate(-2deg); }

.perforado {
  height: 0; border-top: 2px dashed var(--line); margin: 0 18px;
  position: relative;
}
.perforado::before, .perforado::after {
  content: ""; position: absolute; top: -7px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--paper); border: 1px solid var(--line);
}
.perforado::before { left: -25px; }
.perforado::after { right: -25px; }

.detalle { padding: 18px; }

.origen-linea { font-size: 0.8rem; color: var(--ink-500); margin-bottom: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.origen-linea .etiqueta {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-ink);
}

.detalle-extra { margin-bottom: 14px; }
.detalle-extra summary {
  cursor: pointer; font-size: 0.82rem; color: var(--accent-ink); font-weight: 500;
  list-style: none;
}
.detalle-extra summary::-webkit-details-marker { display: none; }
.detalle-extra summary::before { content: "\25B8  "; }
.detalle-extra[open] summary::before { content: "\25BE  "; }
.detalle-extra pre {
  font-size: 0.8rem; color: var(--ink-700); background: var(--paper); border: 1px solid var(--line);
  border-radius: 7px; padding: 10px 12px; margin: 8px 0 0; white-space: pre-wrap;
}

.item-carga { border: 1px solid var(--line); border-radius: 9px; padding: 14px 16px; margin-bottom: 12px; }
.item-carga .fila-item { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.item-carga .fila-item .tipo { font-weight: 600; }
.item-carga .fila-item .tipo .cajas { font-weight: 400; font-size: 0.8rem; color: var(--ink-500); }
.item-carga .fila-item .precio { font-family: "IBM Plex Mono", monospace; font-size: 0.88rem; color: var(--ink-700); }
.item-carga .campos-item { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 10px; }
.item-carga .campos-item label { margin-top: 0; }
.item-carga .quitar-item { text-align: right; margin-bottom: 10px; }

.division { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.division label { display: block; font-size: 0.74rem; color: var(--ink-500); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.division .caja-input {
  display: flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--paper);
}
.division .caja-input input {
  border: none; background: transparent; font-family: "IBM Plex Mono", monospace; font-size: 0.95rem;
  padding: 8px 4px 8px 10px; width: 100%; color: var(--ink-900); min-width: 0;
}
.division .caja-input input:focus { outline: none; }
.division .caja-input .unidad { font-size: 0.76rem; color: var(--ink-500); padding-right: 10px; white-space: nowrap; }

.estado-item { margin-top: 10px; font-size: 0.82rem; display: flex; align-items: center; gap: 7px; }
.estado-item .punto { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.estado-item.ok { color: var(--green); }
.estado-item.ok .punto { background: var(--green); }
.estado-item.falta { color: var(--amber); }
.estado-item.falta .punto { background: var(--amber); }
.estado-item.sobra { color: var(--red); }
.estado-item.sobra .punto { background: var(--red); }

/* ---------- Historial ---------- */
.filtro-fechas { display: flex; align-items: flex-end; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 20px; box-shadow: var(--shadow); flex-wrap: wrap; }
.filtro-fechas .campo { flex: 0 0 auto; }
.filtro-fechas label { margin-top: 0; }

.vacio { text-align: center; padding: 50px 20px; color: var(--ink-500); font-size: 0.9rem; }

footer.pie { text-align: center; font-size: 0.76rem; color: var(--ink-500); padding: 26px 0 6px; }

[hidden] { display: none !important; }

/* ---------- Saldos / deudas ---------- */
.grilla-saldos, .grid-saldos { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 26px; }
.tile-saldo {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.tile-saldo::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--line);
}
.tile-saldo.debe::before { background: var(--red); }
.tile-saldo.al-dia::before { background: var(--green); }
.tile-saldo .cabecera-tile { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.tile-saldo .nombre-socio { font-weight: 600; font-size: 1.02rem; }
.tile-saldo .estado-deuda {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 5px;
}
.tile-saldo .estado-deuda.debe, .tile-saldo .badge.pendiente { color: var(--red); background: var(--red-bg); }
.tile-saldo .estado-deuda.al-dia, .tile-saldo .badge.dividida { color: var(--green); background: var(--green-bg); }
.tile-saldo .monto-deuda { font-family: "IBM Plex Mono", monospace; font-size: 1.7rem; font-weight: 600; margin-bottom: 2px; }
.tile-saldo .detalle-deuda { font-size: 0.76rem; color: var(--ink-500); margin-bottom: 0; }

.panel-pago {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 22px; box-shadow: var(--shadow);
}
.panel-pago h2 { font-size: 0.95rem; margin: 0 0 12px; }
.fila-pago { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.fila-pago .campo { flex: 1; min-width: 130px; }
.fila-pago .campo.chico { flex: 0 0 150px; }
.fila-pago label { margin-top: 0; }

table.pagos td.monto { font-family: "IBM Plex Mono", monospace; font-weight: 500; }
table.pagos .quitar { background: none; border: none; color: var(--ink-500); cursor: pointer; font-size: 0.8rem; padding: 0; }
table.pagos .quitar:hover { color: var(--red); background: none; }

/* ---------- Modal (cargar manualmente) ---------- */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(20, 32, 40, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 20px;
}
.modal {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 22px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
}

.qr-box { text-align: center; padding: 20px; }
.qr-box img { max-width: 260px; border: 1px solid var(--line); border-radius: 8px; }

@media (max-width: 620px) {
  header.app { flex-wrap: wrap; }
  nav.tabs { order: 3; width: 100%; }
}
