/* =========================================================
   base.css — tokens, reset y componentes comunes (tienda y panel)
   Orden: tokens · reset · tipografía · layout · botones · formularios · tarjetas · tablas ·
          insignias · avisos · diálogos · pestañas · utilidades
   Paleta boutique: baya (marca) + caramelo (acento) sobre marfil. Contraste AA verificado
   con scripts/contraste.py (tema claro y oscuro).
   ========================================================= */

:root {
    --bg: #fbf8f6;
    --surface: #ffffff;
    --surface-2: #f4eeea;
    --text: #2b2326;
    --muted: #6b5d63;
    --border: #e9dfda;
    --border-control: #9b8c92;
    --accent: #8a3a5c;
    --accent-hover: #722f4c;
    --accent-soft: #f6e8ee;
    --on-accent: #ffffff;
    --gold: #8a6420;
    --gold-soft: #f8efdf;
    --ok: #1f6b43;
    --ok-soft: #e4f3ea;
    --warn: #8a5300;
    --warn-soft: #fbefd9;
    --bad: #b3261e;
    --bad-soft: #fbe7e5;
    --on-bad: #ffffff;
    --info: #1d5a8c;
    --info-soft: #e5eff8;
    --serie-1: #8a3a5c;
    --serie-2: #c58b3a;
    --serie-3: #2f6f8f;
    --serie-4: #6b8f3a;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(43, 35, 38, .06), 0 4px 16px rgba(43, 35, 38, .06);
    --shadow-lg: 0 10px 40px rgba(43, 35, 38, .18);
    --tactil: 44px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-tema="claro"]) {
        --bg: #161113;
        --surface: #201a1d;
        --surface-2: #2a2226;
        --text: #f3ecee;
        --muted: #bcaeb4;
        --border: #3a3035;
        --border-control: #8c7d83;
        --accent: #e693b6;
        --accent-hover: #f0a9c6;
        --accent-soft: #3a2230;
        --on-accent: #22111a;
        --gold: #e0b56e;
        --gold-soft: #3a2e1c;
        --ok: #7fd3a2;
        --ok-soft: #173426;
        --warn: #f0b860;
        --warn-soft: #3b2c14;
        --bad: #ff9a8f;
        --bad-soft: #43201d;
        --on-bad: #2a0d0b;
        --info: #8cc3f0;
        --info-soft: #182c3d;
        --serie-1: #e693b6;
        --serie-2: #e0b56e;
        --serie-3: #8cc3f0;
        --serie-4: #a9d18a;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
        color-scheme: dark;
    }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
    font-family: var(--font); font-size: 15px; line-height: 1.5;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

/* ---------- Tipografía ---------- */
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.display { font-family: var(--font-display); font-weight: 600; letter-spacing: .01em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.center { text-align: center; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tachado { text-decoration: line-through; color: var(--muted); }
.empty { padding: 24px 12px; text-align: center; }

/* ---------- Layout ---------- */
.stack > * + * { margin-top: 14px; }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila-entre { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.crece { flex: 1 1 auto; min-width: 0; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tactil); padding: 8px 18px; border-radius: 999px; border: 1px solid transparent;
    background: var(--surface-2); color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer;
    transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--border); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-ghost { background: transparent; border-color: var(--border-control); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--bad); color: var(--on-bad); }
.btn-danger:hover { background: var(--bad); color: var(--on-bad); filter: brightness(.92); }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: .88rem; }
.btn-lg { min-height: 52px; padding: 10px 26px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-icono { width: var(--tactil); padding: 0; border-radius: 50%; }
.btn-link { background: none; border: 0; padding: 6px 4px; color: var(--accent); cursor: pointer; text-decoration: underline; min-height: 36px; }

/* ---------- Formularios ---------- */
.form { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span, .field-label { font-size: .86rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .input {
    width: 100%; min-height: var(--tactil); padding: 9px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-control); background: var(--surface); color: var(--text);
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field small { color: var(--muted); font-size: .8rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.field .field-error { color: var(--bad); font-weight: 600; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; min-height: 32px; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.trampa { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
input[type="color"] { padding: 3px; min-height: var(--tactil); width: 56px; }
input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-titulo { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-titulo h2, .card-titulo h3 { margin: 0; }

/* ---------- Tablas ---------- */
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabla { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabla th, .tabla td { padding: 10px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tabla th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface); position: sticky; top: 0; }
.tabla tr.clic { cursor: pointer; }
.tabla tr.clic:hover td { background: var(--surface-2); }
.tabla td.num, .tabla th.num { text-align: right; }
.tabla tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.miniatura { width: 44px; height: 44px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); flex: none; }

/* ---------- Insignias ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
    font-size: .76rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-marca { background: var(--accent-soft); color: var(--accent); }
.badge-oro { background: var(--gold-soft); color: var(--gold); }
.estado-pendiente { background: var(--warn-soft); color: var(--warn); }
.estado-confirmado, .estado-preparando { background: var(--info-soft); color: var(--info); }
.estado-enviado { background: var(--gold-soft); color: var(--gold); }
.estado-entregado { background: var(--ok-soft); color: var(--ok); }
.estado-apartado { background: var(--accent-soft); color: var(--accent); }
.estado-cancelado { background: var(--bad-soft); color: var(--bad); }
.pago-pagado { background: var(--ok-soft); color: var(--ok); }
.pago-parcial { background: var(--warn-soft); color: var(--warn); }
.pago-pendiente { background: var(--surface-2); color: var(--muted); }

/* ---------- Avisos ---------- */
.avisos { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 900; width: min(520px, calc(100vw - 24px)); }
.alert {
    position: relative; display: grid; gap: 2px; padding: 12px 40px 12px 14px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--info); box-shadow: var(--shadow-lg);
}
.alert-success { border-left-color: var(--ok); }
.alert-error { border-left-color: var(--bad); }
.alert-warn { border-left-color: var(--warn); }
.alert-titulo { font-weight: 700; }
.alert-detalle { font-size: .88rem; color: var(--muted); }
.alert-list { margin: 4px 0 0; padding-left: 18px; font-size: .88rem; }
.alert-close { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; border: 0; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
.alert-acciones { display: flex; gap: 8px; margin-top: 6px; }
.nota { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: .9rem; }
.nota-warn { background: var(--warn-soft); color: var(--warn); }
.nota-ok { background: var(--ok-soft); color: var(--ok); }
.nota-info { background: var(--info-soft); color: var(--info); }

/* ---------- Diálogos (en celular suben desde abajo) ---------- */
dialog.modal {
    width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 0;
    border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal-ancho { width: min(860px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(20, 12, 16, .55); }
.modal-cabeza { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-cabeza h2 { margin: 0; font-size: 1.15rem; }
.modal-cuerpo { padding: 18px; }
.modal-pie { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); flex-wrap: wrap; }
.cerrar { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); font-size: 1.3rem; cursor: pointer; color: var(--text); }
@media (max-width: 640px) {
    dialog.modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom, 0px); }
}
/* iPhone: 100vh incluye la barra de Safari; dvh es lo que de verdad se ve (si no lo entiende, queda vh) */
dialog.modal { max-height: calc(100dvh - 32px); }
@media (max-width: 640px) { dialog.modal { max-height: 92dvh; } }

/* ---------- Pestañas y chips ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: thin; }
.tab, .chip {
    flex: none; min-height: 38px; padding: 6px 16px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.tab[aria-selected="true"], .chip.activo, .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip-n { margin-left: 6px; opacity: .8; font-size: .8em; }

/* ---------- Paginación ---------- */
.paginacion { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 16px; }

/* ---------- Muestra de color ---------- */
.muestra { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border-control); background: var(--color, transparent); display: inline-block; flex: none; }

/* ---------- Carga ---------- */
.cargando { opacity: .6; pointer-events: none; }
.esqueleto { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: brillo 1.2s infinite; border-radius: var(--radius-sm); }
@keyframes brillo { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Impresión ---------- */
@media print {
    .no-print, .avisos, .pwa-aviso { display: none !important; }
    body { background: #fff; color: #000; }
}

/* ---------- Accesibilidad ---------- */
.saltar { position: absolute; left: 8px; top: -60px; z-index: 1000; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent); }
.saltar:focus { top: 8px; }
.h2 { font-size: 1.25rem; }
.h3 { font-size: 1.05rem; }
