/* Pantallas pensadas para el móvil: una columna, botones grandes y formularios cortos. */
:root { --pico-font-size: 106.25%; }

/* Colores propios del tema claro y del oscuro. El oscuro se aplica si el usuario lo elige
   (data-theme="dark") o si sigue al sistema y este está en oscuro, igual que Pico. */
:root {
  --menu-text: #1f2937; --menu-hover: #e5e7eb; --accent: #1d4ed8;
  --warn-bg: #fef3c7; --warn-fg: #78350f; --bad-bg: #fee2e2; --bad-fg: #7f1d1d;
  --ok-bg: #dcfce7; --ok-fg: #14532d; --info-bg: #e0f2fe; --info-fg: #0c4a6e;
  --badge-warn-bg: #fde68a; --badge-bad-bg: #fecaca; --badge-ok-bg: #bbf7d0;
  --hint-ok: #15803d; --hint-bad: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --menu-text: #e5e7eb; --menu-hover: #263040; --accent: #60a5fa;
  --warn-bg: #3a2a07; --warn-fg: #fde68a; --bad-bg: #3f1414; --bad-fg: #fecaca;
  --ok-bg: #0f2e1b; --ok-fg: #bbf7d0; --info-bg: #0b2a40; --info-fg: #bae6fd;
  --badge-warn-bg: #4d3809; --badge-bad-bg: #551b1b; --badge-ok-bg: #14432a;
  --hint-ok: #4ade80; --hint-bad: #f87171;
  }
}
:root[data-theme="dark"] {
  --menu-text: #e5e7eb; --menu-hover: #263040; --accent: #60a5fa;
  --warn-bg: #3a2a07; --warn-fg: #fde68a; --bad-bg: #3f1414; --bad-fg: #fecaca;
  --ok-bg: #0f2e1b; --ok-fg: #bbf7d0; --info-bg: #0b2a40; --info-fg: #bae6fd;
  --badge-warn-bg: #4d3809; --badge-bad-bg: #551b1b; --badge-ok-bg: #14432a;
  --hint-ok: #4ade80; --hint-bad: #f87171;
}
body { background: var(--pico-background-color); }

/* Interfaz de aplicación: el texto no se selecciona al tocarlo (Chrome abriría la búsqueda
   contextual de Google), sin menú de toque largo ni destello al pulsar. El zoom con dos dedos
   se mantiene (el viewport no lo bloquea). */
html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input, textarea, [contenteditable], .seleccionable { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
a, button, [role="button"], summary, label { touch-action: manipulation; }
main.container { max-width: 40rem; padding: 0.75rem 1rem 1.5rem; }

/* Barra superior siempre visible */
.app-header { position: sticky; top: 0; z-index: 20; background: var(--pico-background-color); border-bottom: 1px solid var(--pico-muted-border-color); padding-top: env(safe-area-inset-top); }
.app-header nav { max-width: 40rem; padding: 0 1rem; }
.app-header nav ul { margin: 0; }
.app-header nav li { padding: 0.5rem 0.25rem; }
.brand { font-weight: 700; text-decoration: none; }
.demo-badge { font-size: 0.75rem; font-weight: 700; padding: 0.1rem 0.4rem; }
.app-header nav ul:first-child { align-items: center; }
.menu-button { display: flex; margin: 0 0.25rem 0 -0.5rem; padding: 0.45rem; background: none; border: none; color: var(--pico-primary); }
.menu-button svg { display: block; }
.app-header nav ul.header-user { min-width: 0; margin-right: -0.25rem; }
.header-user li { font-size: 0.85rem; color: var(--pico-muted-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Menú ☰: panel a la izquierda con toda la altura (el <dialog> de Pico es el fondo) */
dialog.app-menu { justify-content: flex-start; align-items: stretch; padding: 0; border: none; }
.menu-panel { display: flex; flex-direction: column; width: min(20rem, 85vw); height: 100%; overflow-y: auto; background: var(--pico-background-color); padding: calc(0.75rem + env(safe-area-inset-top)) 0 calc(1rem + env(safe-area-inset-bottom)); box-shadow: 0 0 1.5rem rgba(0, 0, 0, 0.25); }
.menu-panel nav { flex: 1 0 auto; }
.menu-panel nav, .menu-panel ul { display: block; }
.menu-panel ul { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.menu-panel li { display: block; list-style: none; padding: 0; margin: 0; }
.menu-group { margin: 0.75rem 1.25rem 0.25rem; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--pico-muted-color); }
.menu-panel .menu-item { display: block; width: 100%; margin: 0; padding: 0.85rem 1.25rem; font-size: 1.1rem; font-weight: 400; text-decoration: none; color: var(--menu-text); text-align: left; border-radius: 0; }
.menu-panel .menu-item:active, .menu-panel .menu-item:hover { background: var(--menu-hover); }
.menu-footer { border-top: 1px solid var(--pico-muted-border-color); padding-top: 0.5rem; }
.menu-footer form { margin: 0; }
.menu-panel .menu-action { border: none; background: none; box-shadow: none; }
.menu-user { margin: 0.5rem 1.25rem; line-height: 1.3; }
.menu-version { margin: 0.75rem 1.25rem 0; font-size: 0.75rem; color: var(--pico-muted-color); }

/* Versión de la aplicación, discreta al pie: para saber qué versión tiene cada móvil */
.app-shell main { padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
.app-version { text-align: center; font-size: 0.75rem; color: var(--pico-muted-color); margin-top: -4rem; padding-bottom: 1rem; }

h1 { font-size: 1.5rem; margin-bottom: 0.75rem; }
h2 { font-size: 1.25rem; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--pico-muted-color); }
.error-box { border-left: 4px solid #b91c1c; }
.warning { background: var(--warn-bg); color: var(--warn-fg); padding: 0.75rem 1rem; border-radius: 0.4rem; }
.danger { background: var(--bad-bg); color: var(--bad-fg); padding: 0.75rem 1rem; border-radius: 0.4rem; }
.ok-box { background: var(--ok-bg); color: var(--ok-fg); padding: 0.75rem 1rem; border-radius: 0.4rem; }

/* Botones grandes */
.big-buttons { display: grid; gap: 0.75rem; margin: 1rem 0; }
.big-buttons a[role="button"], .big-buttons button { width: 100%; padding: 1.1rem; font-size: 1.15rem; margin: 0; }
.button-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.button-row > * { flex: 1 1 auto; margin: 0; }
button.small, a.small[role="button"] { padding: 0.3rem 0.7rem; font-size: 0.85rem; margin: 0; width: auto; }

/* Listas con miniatura */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0; margin: 0; border-bottom: 1px solid var(--pico-muted-border-color); list-style: none; }
.thumb { flex: 0 0 4rem; width: 4rem; height: 4rem; object-fit: cover; border-radius: 0.4rem; background: var(--pico-muted-border-color); }
.item-info { flex: 1 1 auto; min-width: 0; line-height: 1.3; }
.item-info small { display: block; color: var(--pico-muted-color); }
.item-side { flex: 0 0 auto; text-align: right; }
.price { font-weight: 700; white-space: nowrap; }
.code { font-family: ui-monospace, monospace; letter-spacing: 0.05em; }
.badge { display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.4rem; border-radius: 0.3rem; background: var(--pico-muted-border-color); }
.badge-warn { background: var(--badge-warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--badge-bad-bg); color: var(--bad-fg); }
.badge-ok { background: var(--badge-ok-bg); color: var(--ok-fg); }

/* Avisos temporales (snackbars), abajo */
/* Indicador de carga global: capa semitransparente que bloquea los toques mientras se espera */
.loading { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.35); touch-action: none; }
.loading[hidden] { display: none; }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; padding: 1.25rem 1.75rem; border-radius: 0.75rem; background: var(--pico-background-color); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); max-width: 80vw; text-align: center; }
.loading-text { margin: 0; font-weight: 600; }
.spinner { width: 2.5rem; height: 2.5rem; border: 0.3rem solid var(--pico-muted-border-color); border-top-color: var(--pico-primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

#snackbars { position: fixed; left: 1rem; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; max-width: 30rem; }
.snackbar { padding: 0.8rem 1rem; border-radius: 0.4rem; background: #1f2937; color: #f9fafb; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); cursor: pointer; animation: snackbar-in 0.25s ease-out; transition: opacity 0.3s, transform 0.3s; }
.snackbar-success { background: #166534; }
.snackbar-error { background: #991b1b; }
.snackbar-hide { opacity: 0; transform: translateY(1rem); }
.snackbar-persistent { cursor: default; }
.snackbar-persistent p { margin: 0.4rem 0 0; color: inherit; }
.snackbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.7rem; }
.snackbar-actions button { margin: 0; padding: 0.45rem 0.9rem; font-size: 0.95rem; width: auto; }
@keyframes snackbar-in { from { opacity: 0; transform: translateY(1rem); } to { opacity: 1; transform: none; } }

/* Uso exclusivo como PWA instalada: fuera de ella solo se ve la pantalla de instalación */
html:not(.pwa-standalone) .app-shell { display: none; }
html.pwa-standalone .install-gate { display: none; }
.install-gate { max-width: 32rem; padding: 2rem 1.25rem; text-align: left; }
.install-gate img { border-radius: 1.2rem; margin-bottom: 1rem; }
.install-gate button { width: 100%; padding: 1rem; font-size: 1.15rem; }
.install-steps li { margin-bottom: 0.6rem; }
.ios-icon { width: 1.4em; height: 1.4em; vertical-align: -0.3em; color: var(--accent); }
.copy-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.copy-row input { flex: 1 1 14rem; margin: 0; }
.copy-row button { flex: 0 0 auto; width: auto; margin: 0; }

/* Entrar */
.code-input { font-size: 1.6rem; letter-spacing: 0.3em; text-align: center; font-family: ui-monospace, monospace; }
.demo-help ul { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.demo-help li { list-style: none; margin-bottom: 0.4rem; }
.email-preview { border-left: 4px solid var(--accent); }
.email-preview pre { white-space: pre-wrap; font-size: 0.9rem; }
.use-code { width: 100%; margin-bottom: 0.75rem; font-variant-numeric: tabular-nums; }
.email-preview dl { margin: 0; }
.email-preview dt { font-weight: 600; }
.email-preview dd { margin: 0 0 0.3rem; }
.offline { margin-top: 2rem; }

/* Formularios */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 22rem) { .grid-2 { grid-template-columns: 1fr; } }
label.check { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
label.check input { margin: 0; }
a.wide[role="button"] { width: 100%; margin-bottom: 1rem; }
form.inline { margin: 0; }
.photo-preview { max-height: 14rem; border-radius: 0.5rem; margin: -0.5rem 0 1rem; }
.regime-hint { margin-top: -0.5rem; font-size: 0.85rem; }
.hint-ok { color: var(--hint-ok); }
.hint-bad { color: var(--hint-bad); }
.barcode-hint { min-height: 1.3rem; margin: -0.6rem 0 0.8rem; }
.new-party { margin-top: 1.5rem; }
.new-party summary[role="button"] { width: 100%; }
.small-text { font-size: 0.85rem; }
.hash { font-size: 0.75rem; overflow-wrap: anywhere; }
.signed-box { border-left: 4px solid #15803d; }
.email-form { margin: 0; }
.sign-summary { font-size: 0.9rem; }

/* Código de barras con botón de cámara */
.barcode-field { display: flex; gap: 0.5rem; }
.barcode-field input { flex: 1 1 auto; margin-bottom: 0.75rem; font-size: 1.3rem; }
.barcode-field button { flex: 0 0 auto; width: auto; margin: 0 0 0.75rem; }

/* Lector con la cámara */
dialog.scanner article { padding: 0.75rem; width: min(30rem, 96vw); max-width: none; position: relative; }
dialog.scanner video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #000; border-radius: 0.4rem; display: block; }
.scanner-frame { position: absolute; left: 12%; right: 12%; top: calc(0.75rem + 18%); height: 22%; border: 3px solid rgba(255, 255, 255, 0.85); border-radius: 0.4rem; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.0); pointer-events: none; }
.scanner-status { margin: 0.6rem 0; min-height: 2.6rem; }
.scanner-cancel { width: 100%; margin: 0; }

/* Firma */
.signature-pad { position: relative; border: 2px dashed var(--pico-muted-border-color); border-radius: 0.5rem; background: #fff; margin-bottom: 0.75rem; }
.signature-pad canvas { display: block; width: 100%; height: 13rem; touch-action: none; cursor: crosshair; }
.signature-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9ca3af; pointer-events: none; font-size: 1.1rem; }

/* Ficha del artículo */
.article-photo { width: 100%; max-height: 22rem; object-fit: contain; border-radius: 0.5rem; background: var(--pico-muted-border-color); }
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.9rem; }
dl.facts dt { font-weight: 600; }
dl.facts dd { margin: 0; }
.filters-row { display: flex; gap: 0.5rem; }
.filters-row > * { margin: 0; }
.filters-row input { flex: 1 1 auto; }
.filters-row select { flex: 0 0 9rem; }
.big-price { font-size: 1.6rem; margin: 0.5rem 0; }

/* Venta */
#scan-form { margin: 0; }
.check-card { text-align: center; border: 2px solid var(--accent); }
.check-photo { width: 100%; max-height: 55vh; object-fit: contain; border-radius: 0.5rem; background: #000; }
.check-title { font-size: 1.6rem; margin: 0.6rem 0 0.2rem; }
.check-price { font-size: 2.4rem; font-weight: 800; margin: 0; }
.regime-choice { text-align: left; }
.free-line-form { text-align: left; }
/* Con la ficha de un artículo o la línea libre abierta, no se ven el código ni la búsqueda */
body:has(#check .check-card) :is(#scan-form, #search-form, #search-results) { display: none; }
.option-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: var(--pico-spacing); }
.option-row > .segmented { flex: 1; min-width: 0; margin-bottom: 0; }
.option-label { flex: 0 0 5.3rem; }
.option-empty { line-height: 2.75rem; }

/* Grupo de radios como botones segmentados: los radios siguen siendo reales (teclado y
   formulario), ocultos a la vista; la etiqueta es el botón. Las opciones que no caben pasan a la
   fila siguiente y cada fila se reparte el ancho. */
.segmented { display: flex; flex-wrap: wrap; border: 1px solid var(--pico-form-element-border-color);
  border-radius: var(--pico-border-radius); overflow: hidden; margin-bottom: var(--pico-spacing); }
.segmented > label { flex: 1 1 auto; display: flex; margin: 0; position: relative; cursor: pointer; }
.segmented > label > input { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0;
  border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.segmented > label > span { flex: 1; display: flex; align-items: center; justify-content: center;
  text-align: center; min-height: 2.75rem; padding: 0.45rem 0.6rem; line-height: 1.25;
  background: var(--pico-form-element-background-color); color: var(--pico-color);
  box-shadow: -1px 0 0 var(--pico-form-element-border-color), 0 -1px 0 var(--pico-form-element-border-color); }
.segmented > label:hover > input:not(:checked):not(:disabled) + span { background: var(--menu-hover); }
.segmented > label > input:checked + span { background: var(--pico-primary-background);
  color: var(--pico-primary-inverse); font-weight: 600; }
.segmented > label > input:focus-visible + span { outline: 2px solid var(--pico-primary-focus, var(--pico-primary));
  outline-offset: -4px; }
.segmented > label > input:disabled + span { opacity: 0.45; cursor: not-allowed; }
.line-regime { margin: 0.25rem 0 0; padding: 0.2rem 0.5rem; height: auto; font-size: 0.9rem; width: auto; }
.total { font-size: 1.6rem; font-weight: 800; text-align: right; margin: 0.75rem 0; }
.pending-actions { margin-top: 0.6rem; }
.recent { margin-top: 1.5rem; }
dialog.terminal article { width: min(26rem, 94vw); }
.terminal-amount { font-size: 2.2rem; font-weight: 800; text-align: center; font-family: ui-monospace, monospace; }

/* Depósitos y portada */
.settlement header { display: flex; justify-content: space-between; gap: 0.5rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { list-style: none; margin-bottom: 0.5rem; }
.alert-link { display: block; margin-bottom: 0.6rem; text-decoration: none; }
.info-box { background: var(--info-bg); color: var(--info-fg); padding: 0.75rem 1rem; border-radius: 0.4rem; }
main h1 { margin-top: 0.4rem; }
h3 { font-size: 1.05rem; margin-top: 1rem; }
.settlement header { align-items: flex-start; }
.settlement header small { display: block; font-weight: normal; }

/* Ajustes */
.settings-section { border: 1px solid var(--pico-muted-border-color); border-radius: 0.5rem; padding: 0.6rem 0.9rem; margin-bottom: 0.9rem; }
.settings-section > summary { font-weight: 700; font-size: 1.1rem; }
.settings-section form { margin: 0; }
.settings-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.settings-list li { list-style: none; display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 0.4rem; padding: 0.35rem 0; border-bottom: 1px solid var(--pico-muted-border-color); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.settings-row { display: flex; flex-wrap: nowrap; gap: 0.4rem; align-items: center; }
.inline-form { display: flex; gap: 0.4rem; align-items: center; flex: 1 1 auto; min-width: 0; }
.inline-form input, .inline-form select { margin: 0; flex: 1 1 auto; min-width: 0; padding: 0.35rem 0.6rem; height: auto; }
.settings-section button.small { padding: 0.3rem 0.55rem; }
.inline-form button { margin: 0; flex: 0 0 auto; width: auto; }
.type-card { padding: 0.6rem; margin: 0.6rem 0; }
.subtypes { padding-left: 0.8rem; }
.settings-form label { margin-bottom: 0.6rem; }
.inactive input { text-decoration: line-through; color: var(--pico-muted-color); }
.connection .badge { white-space: nowrap; }
.renew-item { padding: 0.6rem 0.8rem; margin: 0.5rem 0; } .renew-item p { margin-bottom: 0.3rem; }
.lot { padding: 0.6rem 0.8rem; }
article.lot > header { margin: 0 0 0.4rem; padding: 0; background: none; border: 0; }
.stock-filters { margin: 0.4rem 0 0.8rem; } .stock-filters label { margin-bottom: 0.4rem; } #stock-filters { margin-bottom: 0; }
.renew-item .segmented { margin-bottom: 0.5rem; } .renew-item.returned { opacity: 0.75; }
.price-edit { flex-basis: 100%; margin: 0.2rem 0 0; }
.price-edit summary { font-size: 0.9rem; }
.price-edit form { margin: 0.3rem 0; }
#cart .item-list li { flex-wrap: wrap; }
#cart .item-info { flex: 1 1 0; min-width: 0; }
.price-changes { padding: 0.6rem 0.8rem; font-size: 0.95rem; }
#cart .item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
.free-thumb { display: inline-flex; align-items: center; justify-content: center; font-size: 0.8rem; color: var(--pico-muted-color); }
.invoice-kind { margin: 0.4rem 0 0.8rem; } .invoice-kind p { margin-bottom: 0.3rem; }
#invoice-filters .grid-2 > label { min-width: 0; } #invoice-filters input[type=date] { width: 100%; min-width: 0; }
.liq-item { display: flex; gap: 0.6rem; align-items: center; flex: 1 1 auto; min-width: 0; margin: 0; }
#payout-filters .grid-2 > label { min-width: 0; } #payout-filters input[type=date] { width: 100%; min-width: 0; }

/* Informes */
.report-tabs { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin-bottom: 1rem; }
.report-tabs a[aria-current="page"] { font-weight: 700; text-decoration: none; }
.table-scroll { overflow-x: auto; margin-bottom: 1.5rem; }
table.report { font-size: 0.85rem; margin-bottom: 0; }
table.report th, table.report td { white-space: nowrap; padding: 0.35rem 0.5rem; }
table.report .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-2 > label { min-width: 0; }
.grid-2 input[type=date] { width: 100%; min-width: 0; }
#scan-form .barcode-field { gap: 0.4rem; }
#scan-form .barcode-field input { min-width: 0; letter-spacing: 0.05em; font-size: 1.15rem; padding-inline: 0.6rem; }
#scan-form .barcode-field button { padding-inline: 0.7rem; }
.menu-panel nav ul:first-of-type, .menu-panel nav ul:last-of-type { margin-left: 0; margin-right: 0; }
dialog.app-menu, dialog.app-menu:focus, .menu-panel:focus { outline: none; }
.menu-panel .menu-item:focus:not(:focus-visible) { outline: none; box-shadow: none; }
