:root {
  --bg: #f5f3ef;
  --panel: #ffffff;
  --ink: #1d2a2e;
  --muted: #66757a;
  --line: #e4e0d8;
  --accent: #1f6f78;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0f1;
  --ok: #2e7d4f;
  --ok-soft: #e4f3ea;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --bad: #c0392b;
  --bad-soft: #fbe5e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* Layout */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--ink); color: #dfe7e8; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav .marca { font-weight: 700; color: #fff; padding: 4px 10px 14px; font-size: 16px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a.activo { background: var(--accent); color: #fff; }
.nav .sep { height: 1px; background: rgba(255,255,255,.12); margin: 8px 6px; }
.nav .pie { margin-top: auto; padding: 10px; font-size: 13px; color: #9fb0b3; }
.nav .pie button { margin-top: 6px; }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; background: var(--bad); color: #fff; }
.badge.amarillo { background: var(--warn); }
main { padding: 22px 26px 60px; max-width: 1280px; width: 100%; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 14px 0 8px; }
.sub { color: var(--muted); font-size: 13px; }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila.entre { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.espacio { height: 12px; }

/* Controles */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 9px 14px; border-radius: 9px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; justify-content: center; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: #c9c3b8; }
.btn.primario { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primario:hover { filter: brightness(1.07); }
.btn.peligro { color: var(--bad); border-color: #efc2bc; }
.btn.verde { background: #25a35a; color: #fff; border-color: #25a35a; }
.btn.grande { padding: 14px 18px; font-size: 17px; font-weight: 600; width: 100%; }
.btn.chico { padding: 5px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sel { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
input[type=text], input[type=number], input[type=search], input[type=password], input[type=date], input[type=tel], select, textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 9px 11px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.campo { margin-bottom: 12px; }
.campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 12px; }
.escanear { font-size: 18px; padding: 14px 16px !important; }
.chk { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; margin: 6px 0; }

/* Tablas */
.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clic { cursor: pointer; }
td.prod { min-width: 220px; }
input.cant { width: 84px !important; text-align: right; }
tr.clic:hover td { background: #faf8f4; }
tr.cancelada td { color: var(--muted); text-decoration: line-through; }

/* Etiquetas */
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eee; color: #555; white-space: nowrap; }
.ticket-linea .tag, td .tag.largo { white-space: normal; }
.tag.rojo { background: var(--bad-soft); color: var(--bad); }
.tag.amarillo { background: var(--warn-soft); color: var(--warn); }
.tag.verde { background: var(--ok-soft); color: var(--ok); }
.tag.azul { background: var(--accent-soft); color: var(--accent); }

/* Ticket */
.ticket-linea { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.ticket-linea .nombre { font-weight: 600; }
.ticket-linea .controles { display: flex; align-items: center; gap: 6px; }
.ticket-linea .controles input { width: 64px; text-align: center; padding: 5px; }
.total { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.vacio { color: var(--muted); text-align: center; padding: 28px 10px; }
.aviso { padding: 10px 12px; border-radius: 9px; background: var(--warn-soft); color: #7a4f10; font-size: 14px; margin: 8px 0; }
.aviso.rojo { background: var(--bad-soft); color: var(--bad); }
.aviso.azul { background: var(--accent-soft); color: var(--accent); }
.metodos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.resultados { border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; max-height: 340px; overflow-y: auto; background: #fff; }
.resultado { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.resultado:last-child { border-bottom: 0; }
.resultado:hover, .resultado.foco { background: var(--accent-soft); }
.paciente-sel { display: flex; justify-content: space-between; align-items: center; background: var(--accent-soft); padding: 10px 12px; border-radius: 9px; }

/* Tarjetas KPI */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .valor { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .etiqueta { color: var(--muted); font-size: 13px; }

/* Modal */
.modal-fondo { position: fixed; inset: 0; background: rgba(20,28,30,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 640px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.ancho { max-width: 960px; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-cab h2 { margin: 0; }
.cerrar { border: 0; background: none; font-size: 26px; cursor: pointer; line-height: 1; color: var(--muted); }
.pestanas { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.pestanas button { border: 0; background: none; padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.pestanas button.activa { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Toast */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: #fff; padding: 11px 15px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* Login */
.login { max-width: 380px; margin: 9vh auto; }
.login .usuarios { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.pin { font-size: 26px; letter-spacing: 8px; text-align: center; }

/* Escáner */
.visor { position: relative; width: 100%; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.visor video { width: 100%; height: 100%; object-fit: cover; display: block; }
.visor .guia { position: absolute; left: 5%; right: 5%; top: 25%; bottom: 25%; border: 2px solid rgba(255,255,255,.85); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.visor .guia::after { content: ""; position: absolute; left: 4%; right: 4%; top: 50%; height: 2px; background: #ff3b30; box-shadow: 0 0 6px #ff3b30; }
.visor-msg { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 12px; background: rgba(0,0,0,.55); color: #fff; font-size: 14px; text-align: center; }
.visor-controles { margin: 8px 0; }
.visor-controles select { width: auto; flex: 1; }
.escaneo-ultimo { font-size: 18px; font-weight: 600; text-align: center; padding: 12px; }
.qr { display: flex; justify-content: center; padding: 10px; }
.qr img { width: 220px; height: 220px; }

/* Móvil */
.menu-movil { display: none; }
@media (max-width: 1080px) and (min-width: 901px) {
  .grid2 { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 30% 0 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; height: 100vh; }
  .nav.abierto { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  .menu-movil { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 40; }
  .menu-movil button { background: none; border: 0; color: #fff; font-size: 24px; }
  main { padding: 16px 16px 60px; }
  .grid2 { grid-template-columns: 1fr; }
  .modal-fondo { padding: 10px; }
  .total { font-size: 26px; }
}
@media print {
  .nav, .menu-movil, .no-imprimir, #toasts { display: none !important; }
  .app { display: block; }
  .modal-fondo { position: static; background: none; padding: 0; }
  .modal { box-shadow: none; }
}
