/* ---------------------------------------------------------------------------
   Sistema de Bingo — hoja de estilos principal.

   Todo el color se define con variables: los componentes nunca traen valores
   fijos, de modo que el tema claro y el oscuro comparten una única estructura.
   Contraste verificado para AA en texto y controles.
--------------------------------------------------------------------------- */

:root {
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-soft: #dbeafe;
    --accent: #f59e0b;
    --success: #15803d;
    --success-soft: #dcfce7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --warning: #b45309;
    --warning-soft: #fef3c7;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef2f9;
    --border: #d5dced;
    --text: #101828;
    --text-muted: #5a6478;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);

    --radius: 12px;
    --radius-sm: 8px;
    --space: 16px;
    --header-height: 60px;
    --sidebar-width: 248px;
    --sidebar-collapsed: 68px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-numeric: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

:root[data-theme="dark"],
:root[data-theme="system"] {
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="system"] {
        color-scheme: dark;
    }
}

:root[data-theme="dark"],
:root[data-theme="system"][data-resolved="dark"] {
    color-scheme: dark;
    --brand: #60a5fa;
    --brand-strong: #93c5fd;
    --brand-soft: #1e3a5f;
    --success: #4ade80;
    --success-soft: #14351f;
    --danger: #f87171;
    --danger-soft: #3b1414;
    --warning: #fbbf24;
    --warning-soft: #3a2a08;

    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1b2537;
    --border: #2b3648;
    --text: #e8edf7;
    --text-muted: #9aa6bd;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
    margin: 0 0 .5em;
    line-height: 1.25;
    font-weight: 650;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

a {
    color: var(--brand);
    text-underline-offset: 2px;
}

p { margin: 0 0 1em; }

:focus-visible {
    outline: 3px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -999px;
    top: 8px;
    z-index: 100;
    background: var(--surface);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.skip-link:focus {
    left: 8px;
}

/* --------------------------------------------------------------- Estructura */

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width .18s ease;
}

.app-shell.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed);
}

.app-shell.sidebar-collapsed .sidebar__label,
.app-shell.sidebar-collapsed .sidebar__name {
    display: none;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--header-height);
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
}

.sidebar__logo {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
    flex-shrink: 0;
}

.sidebar__name {
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__toggle {
    margin-left: auto;
    background: none;
    border: 0;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
}

.sidebar__nav {
    overflow-y: auto;
    padding: 10px 0 24px;
    flex: 1;
}

.sidebar__nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: .95rem;
    border-left: 3px solid transparent;
}

.sidebar__link:hover {
    background: var(--surface-2);
}

.sidebar__link.active {
    background: var(--brand-soft);
    border-left-color: var(--brand);
    font-weight: 600;
}

.sidebar__icon {
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar__menu {
    display: none;
    background: none;
    border: 0;
    font-size: 1.3rem;
    color: var(--text);
    cursor: pointer;
}

.topbar__event {
    flex: 1;
    min-width: 0;
}

.topbar__event-name {
    font-weight: 600;
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.content {
    padding: var(--space);
    padding-bottom: 84px;
    max-width: 1400px;
    width: 100%;
}

@media (min-width: 900px) {
    .content {
        padding: 24px;
        padding-bottom: 40px;
    }
}

/* ------------------------------------------------------------------- Menús */

.menu {
    position: relative;
}

.menu__summary {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    list-style: none;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
}

.menu__summary::-webkit-details-marker {
    display: none;
}

.menu__summary:hover {
    background: var(--surface-2);
}

.avatar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
}

.menu__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 210px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: 30;
}

.menu__panel a,
.menu__logout {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
}

.menu__panel a:hover,
.menu__logout:hover {
    background: var(--surface-2);
}

.menu__name {
    display: none;
}

@media (min-width: 700px) {
    .menu__name {
        display: inline;
    }
}

.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav__link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    font-size: .7rem;
    color: var(--text-muted);
    text-decoration: none;
}

.bottom-nav__link.active {
    color: var(--brand);
    font-weight: 600;
}

@media (max-width: 899px) {
    .sidebar {
        position: fixed;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow);
    }

    .app-shell.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .topbar__menu {
        display: block;
    }

    .bottom-nav {
        display: flex;
    }
}

/* ---------------------------------------------------------------- Tarjetas */

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

.card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.card__title {
    margin: 0;
    font-size: 1.05rem;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid--stats {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.grid--2 {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.stat__label {
    color: var(--text-muted);
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat__value {
    font-size: 1.7rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-top: 4px;
}

.stat__hint {
    color: var(--text-muted);
    font-size: .85rem;
}

/* ------------------------------------------------------------------ Tablas */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .93rem;
}

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: var(--surface-2);
}

.table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-numeric);
    white-space: nowrap;
}

.table__empty {
    text-align: center;
    color: var(--text-muted);
    padding: 28px 12px;
}

/* En pantallas chicas las tablas marcadas se convierten en tarjetas. */
@media (max-width: 640px) {
    .table--cards thead {
        display: none;
    }

    .table--cards tbody tr {
        display: block;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 8px;
    }

    .table--cards td {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        border: 0;
        padding: 6px 4px;
    }

    .table--cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: .82rem;
    }

    .table--cards .num {
        text-align: right;
    }
}

/* ------------------------------------------------------------ Formularios */

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field--full {
    grid-column: 1 / -1;
}

label {
    font-weight: 600;
    font-size: .9rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-height: 42px;
}

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

input:disabled,
select:disabled,
textarea:disabled {
    background: var(--surface-2);
    color: var(--text-muted);
}

.field__hint {
    color: var(--text-muted);
    font-size: .82rem;
}

.field__error {
    color: var(--danger);
    font-size: .85rem;
}

.checkbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-weight: 500;
}

.checkbox input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex-shrink: 0;
}

fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin: 0 0 14px;
}

legend {
    font-weight: 650;
    padding: 0 6px;
}

/* ------------------------------------------------------------------ Botones */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    min-height: 42px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    background: var(--brand-strong);
}

.btn[disabled],
.btn[aria-busy="true"] {
    opacity: .6;
    cursor: not-allowed;
}

.btn--secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn--secondary:hover {
    background: var(--surface-2);
}

.btn--danger {
    background: var(--danger);
}

.btn--danger:hover {
    filter: brightness(.92);
}

.btn--ghost {
    background: transparent;
    color: var(--text);
    border-color: transparent;
}

.btn--ghost:hover {
    background: var(--surface-2);
}

.btn--block {
    width: 100%;
}

.btn--lg {
    min-height: 56px;
    font-size: 1.1rem;
    padding: 12px 24px;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* ------------------------------------------------------------------ Avisos */

.alert {
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert ul {
    margin: 6px 0 0;
    padding-left: 20px;
}

.alert--success {
    background: var(--success-soft);
    border-color: var(--success);
    color: var(--success);
}

.alert--error {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
}

.alert--warning {
    background: var(--warning-soft);
    border-color: var(--warning);
    color: var(--warning);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 650;
    background: var(--surface-2);
    color: var(--text-muted);
    white-space: nowrap;
}

.badge--success { background: var(--success-soft); color: var(--success); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--info    { background: var(--brand-soft);   color: var(--brand-strong); }

.muted {
    color: var(--text-muted);
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; }

.page-header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 14px;
}

.filters .field {
    min-width: 150px;
}

.pagination {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 14px;
}

.pagination a,
.pagination span {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
}

.pagination .is-current {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

/* ------------------------------------------------------------------ Cartón */

.bingo-card {
    display: inline-grid;
    gap: 3px;
    background: var(--border);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 3px;
}

.bingo-card__cell {
    display: grid;
    place-items: center;
    background: var(--surface);
    aspect-ratio: 1;
    min-width: 38px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    border-radius: 4px;
}

.bingo-card__cell--empty {
    background: var(--surface-2);
}

.bingo-card__cell--free {
    background: var(--brand-soft);
    color: var(--brand-strong);
    font-size: .7rem;
}

.bingo-card__cell--marked {
    background: var(--success);
    color: #fff;
}

.bingo-card__cell--required {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.bingo-card__header {
    display: grid;
    gap: 3px;
    margin-bottom: 3px;
}

.bingo-card__letter {
    display: grid;
    place-items: center;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
    border-radius: 4px;
    padding: 4px 0;
}

/* ------------------------------------------------- Consola del operador */

.console {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

@media (min-width: 1100px) {
    .console {
        grid-template-columns: minmax(0, 1.4fr) minmax(300px, .9fr);
    }
}

.candidate {
    display: grid;
    place-items: center;
    gap: 10px;
    padding: 20px;
    text-align: center;
}

.candidate__number {
    font-size: clamp(3.5rem, 14vw, 7rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--brand);
}

.candidate__empty {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 4px;
}

.board--75 {
    grid-template-columns: repeat(15, minmax(0, 1fr));
}

.board__cell {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    background: var(--surface-2);
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.board__cell--called {
    background: var(--brand);
    color: #fff;
}

.board__cell--last {
    background: var(--accent);
    color: #17120a;
    animation: pop .4s ease;
}

@keyframes pop {
    from { transform: scale(.7); opacity: .4; }
    to { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}

.recent-numbers {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.recent-numbers__item {
    display: grid;
    place-items: center;
    min-width: 46px;
    padding: 8px;
    border-radius: 10px;
    background: var(--surface-2);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------- Pantalla pública */

.board-screen {
    background: #05070d;
    color: #f8fafc;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 2vh 2vw;
    gap: 2vh;
}

.board-screen__header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: baseline;
    justify-content: space-between;
    font-size: clamp(1rem, 2.2vw, 1.8rem);
}

.board-screen__title {
    font-weight: 800;
    margin: 0;
}

.board-screen__main {
    display: grid;
    gap: 2vw;
    grid-template-columns: 1fr;
    align-items: center;
}

@media (min-width: 900px) {
    .board-screen__main {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    }
}

.board-screen__current {
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, .05);
    border-radius: 24px;
    padding: 3vh 2vw;
}

.board-screen__number {
    font-size: clamp(5rem, 22vw, 16rem);
    font-weight: 900;
    line-height: .95;
    font-variant-numeric: tabular-nums;
}

.board-screen__letter {
    font-size: clamp(1.5rem, 5vw, 4rem);
    color: #fbbf24;
    font-weight: 800;
    letter-spacing: .1em;
}

.board-screen .board__cell {
    background: rgba(255, 255, 255, .08);
    color: #cbd5e1;
    font-size: clamp(.6rem, 1.3vw, 1.2rem);
}

.board-screen .board__cell--called {
    background: #2563eb;
    color: #fff;
}

.board-screen .board__cell--last {
    background: #fbbf24;
    color: #111827;
}

.board-screen__footer {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: space-between;
    align-items: center;
    font-size: clamp(.9rem, 1.8vw, 1.4rem);
    border-top: 1px solid rgba(255, 255, 255, .15);
    padding-top: 1.5vh;
}

.board-screen__winners {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.board-screen__winner {
    background: rgba(34, 197, 94, .18);
    border: 1px solid rgba(34, 197, 94, .5);
    border-radius: 999px;
    padding: 4px 14px;
}

/* ------------------------------------------------------------ Autenticación */

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    background: linear-gradient(160deg, var(--bg), var(--surface-2));
}

.auth__card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 26px;
}

.auth__logo {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--brand);
    color: #fff;
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0 auto 14px;
}

/* -------------------------------------------------------------- Impresión */

@media print {
    .sidebar,
    .topbar,
    .bottom-nav,
    .no-print {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .card,
    .content {
        box-shadow: none;
        border: 0;
        padding: 0;
        margin: 0;
    }

    .print-sheet {
        page-break-after: always;
    }
}

.receipt {
    background: #fff;
    color: #111;
    margin: 0 auto;
    padding: 12mm;
    font-size: 12px;
}

.receipt--a4 { width: 210mm; min-height: 297mm; }
.receipt--a5 { width: 148mm; min-height: 210mm; }
.receipt--ticket58 { width: 58mm; padding: 4mm; font-size: 10px; }
.receipt--ticket80 { width: 80mm; padding: 5mm; font-size: 11px; }

.receipt table {
    width: 100%;
    border-collapse: collapse;
}

.receipt th,
.receipt td {
    padding: 3px 2px;
    border-bottom: 1px dashed #bbb;
    text-align: left;
}

.receipt .num {
    text-align: right;
}
