/*
 * Estilo inspirado en Audax Proyectos: plano (sin esquinas redondeadas ni sombras), DM Sans 400/500/600,
 * tinta #0B1B33, fondo gris #F5F6F7 con superficies blancas, bordes #E2E6EC y azul de marca #0171FF.
 */
:root {
  --bg: #f5f6f7;
  --card: #ffffff;
  --text: #0b1b33;
  --muted: #5b6b82;
  --line: #e2e6ec;
  --input: #808d9c;
  --brand: #0171ff;
  --primary: #0068eb;
  --primary-hover: #005fd6;
  --primary-text: #005fd6;
  --primary-fg: #ffffff;
  --ok: #1e9c6b;
  --warn: #e39a2d;
  --bad: #b43a36;
  --track: #eef1f5;
  --hl: #e6f0ff;
  --thead: #e9ecef;
  --ok-bg: #e9f5f0;
  --ok-fg: #1e7a4c;
  --bad-bg: #fdeceb;
  --bad-fg: #b43a36;
  --brand-gradient:
    radial-gradient(56% 52% at 28% 47%, rgb(34 34 34) 0%, rgb(34 34 34 / 0) 100%),
    radial-gradient(118% 90% at 96% 109%, rgb(0 189 206) 0%, rgb(13 34 133 / 0) 100%),
    radial-gradient(184% 81% at 74% 91%, rgb(3 33 174) 0%, rgb(0 37 206 / 0) 100%),
    radial-gradient(89% 47% at 13% 124%, rgb(186 218 255) 1%, rgb(52 44 103 / 0) 100%),
    radial-gradient(90% 51% at 11% 93%, rgb(77 53 137) 0%, rgb(77 53 137 / 0) 100%),
    #001b39;
  --brand-veil: linear-gradient(to top, rgb(0 27 57 / .75) 0%, rgb(0 27 57 / 0) 100%);
  color-scheme: light;
}
/* Tema oscuro: automático según el sistema, salvo que el usuario elija claro; o forzado con data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1526;
    --card: #121c30;
    --text: #f5f6f7;
    --muted: rgb(255 255 255 / .7);
    --line: rgb(255 255 255 / .14);
    --input: rgb(255 255 255 / .4);
    --primary-text: #519aff;
    --ok: #5cc98e;
    --warn: #f2b84b;
    --bad: #f2837b;
    --track: rgb(255 255 255 / .08);
    --hl: rgb(1 113 255 / .18);
    --thead: #1a2538;
    --ok-bg: #0a3a43;
    --ok-fg: #5cc98e;
    --bad-bg: #36283d;
    --bad-fg: #f2837b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1526;
  --card: #121c30;
  --text: #f5f6f7;
  --muted: rgb(255 255 255 / .7);
  --line: rgb(255 255 255 / .14);
  --input: rgb(255 255 255 / .4);
  --primary-text: #519aff;
  --ok: #5cc98e;
  --warn: #f2b84b;
  --bad: #f2837b;
  --track: rgb(255 255 255 / .08);
  --hl: rgb(1 113 255 / .18);
  --thead: #1a2538;
  --ok-bg: #0a3a43;
  --ok-fg: #5cc98e;
  --bad-bg: #36283d;
  --bad-fg: #f2837b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.55 "DM Sans", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgb(1 113 255 / .6); color: #0b1b33; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 1.75rem; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; }
b, strong { font-weight: 600; }
p { margin: .25rem 0; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 780px; }
main.wrap { padding-top: 28px; padding-bottom: 56px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.inline { display: inline; margin: 0; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .08em; }
.eyebrow { font-size: .72rem; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

/* Cabecera */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; justify-content: space-between; align-items: center; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand::before { content: ""; width: 10px; height: 10px; background: var(--brand); }
.topbar-in .right { display: flex; align-items: center; gap: 18px; }
.pub-top { display: flex; justify-content: flex-end; padding-top: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 20px;
}
.card.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 4px 0 20px; flex-wrap: wrap; }
.head.sub { margin-top: 32px; align-items: center; }
.back { display: inline-block; margin-bottom: 10px; font-size: .85rem; font-weight: 500; }
.note { background: var(--hl); border-left: 3px solid var(--brand); padding: 8px 12px; font-size: .88rem; }

/* Botones y formularios */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: .88rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; list-style: none; text-decoration: none !important;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { border-color: var(--input); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.link { background: none; border: 0; padding: 0; font: inherit; font-weight: 500; color: var(--primary-text); cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }

label { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; font-weight: 500; color: var(--text); }
label .muted { font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, textarea, select {
  font: inherit; font-size: .9rem; color: var(--text); background: var(--card);
  border: 1px solid var(--input); border-radius: 0; padding: 0 10px; height: 38px; width: 100%;
}
textarea { padding: 8px 10px; height: auto; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.prefix { display: flex; align-items: stretch; }
.prefix > span { display: flex; align-items: center; padding: 0 8px; border: 1px solid var(--input); border-right: 0; background: var(--track); color: var(--muted); font-size: .78rem; font-weight: 400; white-space: nowrap; }
.prefix > input { min-width: 0; }

details.pop { position: relative; }
details.pop > summary { list-style: none; }
details.pop > .card {
  position: absolute; z-index: 10; top: calc(100% + 4px); left: 0;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 12px 32px rgb(11 27 51 / .14);
}
details.pop.right > .card, .head > details.pop > .card { left: auto; right: 0; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.menu .inline { margin-right: 6px; }

.flash { margin-top: 16px; padding: 10px 14px; border-left: 3px solid var(--ok); background: var(--ok-bg); color: var(--ok-fg); font-weight: 500; }
.flash.error { border-left-color: var(--bad); background: var(--bad-bg); color: var(--bad-fg); }

.tag { font-size: .68rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; padding: 3px 7px; background: var(--track); color: var(--muted); vertical-align: middle; }
.tag.green { background: var(--ok-bg); color: var(--ok-fg); }

/* Selector de tema */
.tema { display: inline-flex; border: 1px solid var(--line); }
.tema button { border: 0; background: none; color: var(--muted); font: inherit; font-size: .75rem; font-weight: 500; padding: 4px 10px; cursor: pointer; }
.tema button + button { border-left: 1px solid var(--line); }
.tema button[aria-pressed="true"] { background: var(--text); color: var(--card); }

/* Barra de progreso */
.bar { height: 8px; background: var(--track); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--brand); }
.bar.warn span { background: var(--warn); }
.bar.over span { background: var(--bad); }

/* Listado de clientes */
.list { display: grid; border: 1px solid var(--line); background: var(--card); }
.list .row { border: 0; border-bottom: 1px solid var(--line); }
.list .row:last-child { border-bottom: 0; }
.row { display: grid; grid-template-columns: 1.3fr 1.6fr .8fr; gap: 20px; align-items: center; color: var(--text); text-decoration: none !important; }
.row:hover { background: var(--hl); }
.row.inactive { opacity: .55; }
.row-main { display: flex; flex-direction: column; gap: 2px; }
.row-main strong { font-weight: 600; font-size: .95rem; }
.row-bar { display: flex; flex-direction: column; gap: 7px; }
.row-num { display: flex; flex-direction: column; align-items: flex-end; }
.big { font-size: 1.35rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.neg .big, .neg { color: var(--bad); }

/* Enlace del cliente */
.linkbox { display: grid; gap: 10px; margin-bottom: 8px; }
.linkrow { display: flex; gap: 8px; flex-wrap: wrap; }
.linkrow input { flex: 1 1 280px; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; background: var(--bg); border-color: var(--line); }

/* Bolsas */
.tabs { display: flex; overflow-x: auto; margin-bottom: -1px; position: relative; z-index: 1; }
.tabs a {
  display: flex; flex-direction: column; padding: 10px 16px; border: 1px solid var(--line); border-right-width: 0;
  background: var(--bg); color: var(--muted); white-space: nowrap; font-weight: 500; text-decoration: none !important;
}
.tabs a:last-child { border-right-width: 1px; }
.tabs a.on { background: var(--card); color: var(--text); border-bottom-color: var(--card); box-shadow: inset 0 2px 0 var(--brand); }
.bolsa { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; margin-bottom: 16px; }
.bolsa-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
/* Las líneas entre cifras salen del hueco de 1px sobre el fondo de color de línea */
.stats { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stats > div { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; background: var(--card); }
.stats > div.hl { background: linear-gradient(var(--hl), var(--hl)), var(--card); }
.stats .small { font-size: .7rem; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; }

.imputar {
  display: grid; grid-template-columns: 150px 1fr 80px 80px auto; gap: 12px; align-items: end;
  padding: 16px; background: var(--bg); border: 1px solid var(--line);
}
.imputar > *, .form-grid > * { min-width: 0; }
.imputar.editing { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
.f-btn { display: flex; gap: 6px; }

/* Dictado */
.dictar { position: relative; }
.dictar textarea { padding-right: 44px; resize: none; min-height: 38px; max-height: 220px; field-sizing: content; display: block; }
.mic {
  position: absolute; right: 5px; bottom: 5px; width: 28px; height: 28px;
  border: 0; background: var(--track); color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.mic:hover { background: var(--hl); color: var(--primary-text); }
.mic svg { width: 15px; height: 15px; }
.mic.on { background: var(--bad); color: #fff; animation: latido 1.2s infinite; }
@keyframes latido { 50% { box-shadow: 0 0 0 5px rgb(180 58 54 / .25); } }

/* Capturas */
.f-adj { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.f-adj input[type=file] { display: none; }
.f-adj .hint { font-size: .8rem; color: var(--muted); }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.thumbs a, .thumbs label.thumb { position: relative; display: block; }
.thumbs img { width: 68px; height: 48px; object-fit: cover; border: 1px solid var(--line); display: block; }
.thumbs a:hover img { border-color: var(--brand); }
.thumbs label.thumb { flex-direction: column; align-items: center; gap: 3px; font-size: .72rem; font-weight: 400; cursor: pointer; }
.thumbs label.thumb input { width: auto; height: auto; }
.f-adj .thumbs { margin-top: 0; }

/* Tablas */
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; border: 1px solid var(--line); }
.tabla th { text-align: left; background: var(--thead); color: var(--muted); font-size: .72rem; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; }
.tabla th, .tabla td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla tbody tr:hover td { background: color-mix(in oklab, var(--hl) 50%, transparent); }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.tabla tr.sel td { background: var(--hl); }
.acts { text-align: right; }
.acts > * + * { margin-left: 12px; }
.bolsa details > summary { margin-bottom: 10px; }
.empty-line { text-align: center; padding: 10px; }

.dangerzone { margin-top: 44px; padding-top: 16px; border-top: 1px solid var(--line); text-align: right; font-size: .85rem; }

/* Pantallas de acceso (admin y PIN del cliente) */
.auth { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.auth-brand {
  background: var(--brand-veil), var(--brand-gradient);
  color: #fff; padding: 40px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-brand .brand { color: #fff; }
.auth-brand h2 { font-size: 2rem; font-weight: 500; letter-spacing: -.02em; line-height: 1.2; max-width: 14em; }
.auth-brand h2 span { color: #8cbbff; }
.auth-brand p { color: rgb(255 255 255 / .85); max-width: 28em; }
.auth-form { display: flex; flex-direction: column; justify-content: center; padding: 40px; background: var(--card); }
.auth-form .tema { align-self: flex-end; margin-bottom: auto; }
.auth-form form { width: 100%; max-width: 380px; margin: 0 auto auto; display: grid; gap: 16px; }
.auth-form .btn { height: 40px; }
input.pin { font-size: 1.4rem; letter-spacing: .5em; text-align: center; height: 50px; }

.pub-head { margin-bottom: 20px; display: grid; gap: 4px; }
h2.sub { margin: 32px 0 12px; }
.foot { margin-top: 32px; }

@media (max-width: 720px) {
  .row { grid-template-columns: 1fr auto; }
  .row-bar { grid-column: 1 / -1; grid-row: 2; }
  .imputar { grid-template-columns: 1fr 1fr; }
  .f-desc, .f-btn { grid-column: 1 / -1; }
  .f-fecha { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .stats { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
  .stats > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .big { font-size: 1.2rem; }
  .tabla th:first-child, .tabla td:first-child { width: 1%; }
  .tabla th, .tabla td { padding: 8px 6px; }
  .acts > * { display: block; }
  .acts > * + * { margin: 4px 0 0; }
  .auth { grid-template-columns: 1fr; min-height: auto; }
  .auth-brand { padding: 24px 20px; gap: 28px; }
  .auth-brand h2 { font-size: 1.5rem; }
  .auth-form { padding: 24px 20px 48px; }
  .auth-form .tema { margin-bottom: 24px; }
  .topbar-in .right { gap: 12px; }
  .tema button { padding: 4px 7px; }
}
