/* ============ Componentes ============ */

/* ---- Botones ---- */
/* Ícono SVG en línea (js/ui/icons.js) */
.ico { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ico svg { display: block; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--ink);
    font-weight: 600;
    border: 1px solid var(--line);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 54px; font-size: 1.05rem; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; }

/* ---- Campos ---- */
.field { display: grid; gap: 5px; }
.field > label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.input {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.input { min-height: 76px; resize: vertical; }
.field-error { color: var(--red); font-size: .78rem; }
.input.is-invalid {
    border-color: var(--red);
    background: color-mix(in srgb, var(--red) 7%, var(--surface));
}
.input.is-invalid:focus { outline-color: var(--red); }

/* ---- Aviso en línea (js/ui/alert.js) ---- */
.alert {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
    background: color-mix(in srgb, var(--red) 12%, var(--surface));
    color: var(--ink);
    font-size: .88rem; line-height: 1.35;
    animation: alert-in .16s ease;
}
.alert-ico { flex: none; margin-top: 1px; }
.alert-ico svg { display: block; }
.alert-error { border-color: color-mix(in srgb, var(--red) 40%, transparent); background: color-mix(in srgb, var(--red) 12%, var(--surface)); }
.alert-error .alert-ico { color: var(--red); }
.alert-warn { border-color: color-mix(in srgb, var(--amber) 45%, transparent); background: color-mix(in srgb, var(--amber) 13%, var(--surface)); }
.alert-warn .alert-ico { color: var(--amber); }
.alert-ok { border-color: color-mix(in srgb, var(--green) 40%, transparent); background: color-mix(in srgb, var(--green) 12%, var(--surface)); }
.alert-ok .alert-ico { color: var(--green); }
.alert-info { border-color: color-mix(in srgb, var(--info) 40%, transparent); background: color-mix(in srgb, var(--info) 12%, var(--surface)); }
.alert-info .alert-ico { color: var(--info); }
@keyframes alert-in { from { opacity: 0; transform: translateY(-4px); } }

/* Sacudida para llamar la atención (login, validaciones) */
.shake { animation: shake .4s ease; }
@keyframes shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-5px); }
    40%, 60% { transform: translateX(5px); }
}
@media (prefers-reduced-motion: reduce) {
    .shake, .alert { animation: none; }
}

/* Campo con botón a la derecha (mostrar/ocultar contraseña) */
.input-with-btn { position: relative; }
.input-with-btn .input { padding-right: 48px; }
.input-with-btn .reveal {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: calc(var(--tap) - 8px);
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--muted);
}
.input-with-btn .reveal:active { background: var(--surface-2); }

/* ---- Tarjetas ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
}
.list { display: grid; gap: 8px; }
.list-row {
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    text-align: left;
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t1 { font-weight: 600; }
.list-row .t2 { font-size: .82rem; color: var(--muted); }

/* ---- Badges / chips ---- */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .72rem; font-weight: 700;
    background: var(--surface-2); color: var(--muted);
    text-transform: uppercase; letter-spacing: .3px;
}
.badge.is-open { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.badge.is-billed { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.badge.is-paid { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }
.badge.is-cancelled { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.badge.is-delivered { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); gap: 3px; }
.badge.is-partial { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 999px;
    background: var(--surface-2); color: var(--muted);
    font-size: .75rem;
}

/* ---- Toast ---- */
#toast-stack {
    position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 12px + var(--safe-bottom));
    z-index: 60;
    display: grid; gap: 8px; justify-items: center;
    padding: 0 14px;
    pointer-events: none;
}
.toast {
    display: flex; align-items: center; gap: 8px;
    max-width: 420px;
    padding: 11px 16px;
    border-radius: 999px;
    background: #2a2622; color: #fdf6ec;
    font-size: .9rem; font-weight: 600;
    box-shadow: var(--shadow);
    animation: toast-in .18s ease;
}
.toast-ico { flex: none; display: inline-flex; }
.toast-ico svg { display: block; }
.toast.err { background: var(--red); color: #fff; }
.toast.ok { background: var(--green); color: #fff; }
.toast.info { background: var(--info); color: #fff; }

/* ---- Barra de "hay versión nueva" ---- */
.update-bar {
    position: fixed;
    left: 0; right: 0;
    top: 0;
    z-index: 70;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 14px;
    padding-top: calc(10px + var(--safe-top));
    background: var(--ink); color: var(--bg);
    font-size: .9rem; font-weight: 600;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
    animation: toast-in .2s ease;
}
.update-bar-txt { display: inline-flex; align-items: center; gap: 8px; }
.update-bar .btn { background: var(--accent); color: var(--accent-ink); border: 0; }

/* deja hueco para que la barra no tape el encabezado / la tarjeta de login */
body.has-update-bar .app { padding-top: calc(44px + var(--safe-top)); }
body.has-update-bar .login { padding-top: calc(64px + var(--safe-top)); }

.menu-version { text-align: center; font-size: .74rem; color: var(--muted); padding: 10px 0 2px; }
.ios-steps { display: grid; gap: 12px; padding-left: 22px; font-size: .92rem; line-height: 1.4; }
.ios-steps li { padding-left: 4px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- Bottom sheet ---- */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(20, 12, 4, .45);
    display: flex; align-items: flex-end; justify-content: center;
    animation: fade .15s ease;
}
.sheet {
    position: relative;
    width: 100%; max-width: 560px;
    max-height: 92dvh;
    display: flex; flex-direction: column;
    background: var(--bg);
    border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(18px + var(--safe-bottom));
    animation: sheet-up .2s ease;
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { font-size: 1.05rem; }
.sheet-body { overflow-y: auto; display: grid; gap: 14px; padding-bottom: 4px; }
.sheet-foot { padding-top: 12px; display: grid; gap: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(30px); } }

/* ---- Numpad ---- */
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.numpad button {
    min-height: 44px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line);
    font-size: 1.15rem; font-weight: 600;
}
.numpad button:active { background: var(--surface-2); }
.numpad-display {
    text-align: right;
    font-size: 1.8rem; font-weight: 700;
    padding: 6px 10px;
    font-variant-numeric: tabular-nums;
}

/* ---- Grid de productos / mesas ---- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile {
    display: flex; flex-direction: column; gap: 4px;
    min-height: 84px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line);
    text-align: left;
}
.tile .tile-name { font-weight: 600; font-size: .9rem; line-height: 1.2; }
.tile .tile-sub { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile.state-available { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.tile.state-occupied { border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); background: color-mix(in srgb, var(--amber) 8%, var(--surface)); }
.tile.state-bill_pending { border-color: color-mix(in srgb, var(--red) 55%, var(--line)); background: color-mix(in srgb, var(--red) 8%, var(--surface)); }
.tile:disabled { opacity: .5; }

/* ---- Tabs horizontales ---- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
    flex: 0 0 auto;
    padding: 8px 14px; border-radius: 999px;
    background: var(--surface-2); color: var(--muted);
    font-weight: 600; font-size: .85rem;
    border: 1px solid var(--line);
}
.tabs button.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
