* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body {
    margin: 0; padding: 0;
    height: 100vh; height: 100dvh;
    font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: #1c1c1e; color: #1c1c1e;
    overscroll-behavior: none; user-select: none;
    touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
a, input, select, label { touch-action: manipulation; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }

/* ---- Barra superior ---- */
.topbar {
    background: #1c1c1e; color: #fff;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 0 10px; flex-shrink: 0;
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar .btn-icon {
    background: none; border: none; color: #fff; font-size: 26px; line-height: 1;
    padding: 8px 12px; border-radius: 8px; text-decoration: none;
}
.topbar .btn-icon:active { background: rgba(255,255,255,0.15); }
.topbar .title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip {
    background: #3a3a3c; color: #fff; border: none; border-radius: 20px;
    padding: 8px 14px; font-size: 14px; font-weight: 600; max-width: 160px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-chip:empty { display: none; }
.btn-cajon {
    background: #fff; color: #000; border: none; border-radius: 10px;
    padding: 7px 12px; font-size: 20px; display: flex; align-items: center; gap: 6px;
}
.btn-cajon span { font-size: 15px; font-weight: 600; }

/* ---- Layout principal POS ---- */
.pos-screen { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: #f2f2f5; }
.pos-body { flex: 1; display: flex; min-height: 0; }

.ticket-panel { width: 34%; background: #fff; border-right: 1px solid #e0e0e2; display: flex; flex-direction: column; }
.ticket-lines { flex: 1; overflow-y: auto; padding: 8px; }
.ticket-line { position: relative; overflow: hidden; border-radius: 10px; margin-bottom: 6px; background: #f7f7f9; height: 54px; }
.ticket-line .line-content {
    position: relative; z-index: 2; background: #f7f7f9;
    display: flex; align-items: center; justify-content: space-between;
    height: 100%; padding: 0 12px; transition: transform .15s ease; touch-action: pan-y;
}
.ticket-line .line-name { font-size: 15px; font-weight: 600; }
.ticket-line .line-price { font-size: 15px; color: #555; }
.ticket-line .line-action {
    position: absolute; top: 0; bottom: 0; width: 70px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 13px; font-weight: 600; z-index: 1;
}
.ticket-line .line-action { top: 1px; bottom: 1px; }
.line-action.delete { right: 1px; background: #d9483b; border-radius: 0 9px 9px 0; }
.line-action.add { left: 1px; background: #2f9e5c; border-radius: 9px 0 0 9px; }

.ticket-total {
    border-top: 1px solid #e0e0e2; padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex; justify-content: space-between; align-items: baseline;
}
.ticket-total .label { font-size: 20px; color: #666; }
.ticket-total .value { font-size: 28px; font-weight: 700; }
.ticket-empty { color: #999; text-align: center; padding: 24px 12px; font-size: 14px; }
.ticket-mobile-actions, .family-mobile-bar { display: none; }

.action-panel { width: 66%; padding: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; min-height: 0; }
.grid-buttons { flex: 1; display: grid; gap: 8px; min-height: 0; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; }
.grid-buttons .big-btn { min-width: 0; padding: 4px; overflow: hidden; }

.big-btn {
    border: none; border-radius: 14px; background: #fff;
    font-size: 24px; font-weight: 600; color: #1c1c1e;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.big-btn:active { filter: brightness(.88); transform: scale(.97); }
.big-btn { transition: transform .06s; }
.big-btn.accent { background: #2f6fed; color: #fff; }
.big-btn.success { background: #2f9e5c; color: #fff; font-size: 20px; }
.big-btn.danger { background: #d9483b; color: #fff; }
.big-btn.ghost { background: #e9e9ec; color: #1c1c1e; font-size: 16px; }

.finalize-row { margin-top: 8px; height: 68px; flex-shrink: 0; }

.keypad-header { text-align: center; padding: 6px 0 10px; flex-shrink: 0; }
.keypad-header .family-label { font-size: 16px; color: #666; }
.keypad-header .amount { font-size: 40px; font-weight: 700; }
.keypad-grid { flex: 1; display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(4,1fr); gap: 8px; min-height: 0; }
.keypad-grid .big-btn { font-size: 34px; min-width: 0; }
.keypad-grid.modal-keypad { height: 230px; margin-top: 10px; flex: none; }
.keypad-grid.modal-keypad .big-btn { font-size: 26px; background: #f2f2f5; box-shadow: none; }
.keypad-grid.modal-keypad .big-btn.danger { background: #d9483b; }
.keypad-grid.modal-keypad .big-btn.ghost { background: #e4e4e8; }

/* ---- Modales ---- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-overlay.top { z-index: 70; }
.modal-box {
    background: #fff; border-radius: 16px; padding: 22px; width: 380px; max-width: 100%;
    max-height: calc(100dvh - 32px); overflow-y: auto;
}
.modal-box h2 { margin: 0 0 14px; font-size: 19px; }
.modal-box p { font-size: 15px; line-height: 1.4; }
.modal-sub { color: #888; font-size: 13px; margin: -8px 0 10px; }
.modal-box .amount-display { font-size: 34px; font-weight: 700; text-align: center; margin: 10px 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .big-btn { flex: 1; height: 54px; font-size: 18px; }
.modal-row { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; padding: 4px 0; }
.modal-row.total { font-weight: 700; font-size: 18px; border-top: 1px solid #eee; margin-top: 6px; padding-top: 10px; }
.modal-row.total.neg { color: #d9483b; }
.quick-cash { display: flex; gap: 8px; margin-top: 10px; }
.quick-cash .big-btn { flex: 1; height: 44px; font-size: 16px; }
.dojo-msg { text-align: center; font-size: 17px !important; min-height: 44px; }
.error-text { color: #d9483b; }
.hint { color: #666; font-size: 14px !important; }
.confirm-text { font-size: 17px !important; margin: 0 0 6px; }

/* ---- Pantalla de PIN ---- */
.pin-screen {
    position: fixed; inset: 0; z-index: 100; background: #1c1c1e;
    display: flex; align-items: center; justify-content: center; padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
}
.pin-box { width: 340px; max-width: 100%; text-align: center; color: #fff; }
.pin-logo { max-width: 220px; max-height: 90px; background: #fff; border-radius: 12px; padding: 8px; margin-bottom: 14px; }
.pin-title { font-size: 26px; font-weight: 700; margin-bottom: 10px; }
.pin-sub { font-size: 16px; color: #c7c7cc; min-height: 22px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 20px 0 24px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #8e8e93; }
.pin-dot.on { background: #fff; border-color: #fff; }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-key {
    height: 68px; border-radius: 16px; border: none; background: #3a3a3c; color: #fff;
    font-size: 28px; font-weight: 500;
}
.pin-key:active { background: #636366; transform: scale(.95); }
.pin-key.ghost { font-size: 16px; background: #2c2c2e; }
.pin-key.accent { font-size: 17px; font-weight: 700; background: #2f6fed; }

/* ---- Avisos ---- */
#toastHost { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: #1c1c1e; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: opacity .3s, transform .3s; }
.toast.ok { background: #257e49; }
.toast.error { background: #b8392e; }
.toast.out { opacity: 0; transform: translateY(10px); }

/* ---- Historial ---- */
.historial-screen { height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: #f2f2f5; }
.hist-summary { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 10px 14px 0; font-size: 14px; color: #555; }
.historial-body { flex: 1; overflow-y: auto; padding: 12px; }
.ticket-row {
    background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
    display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.ticket-row.anulado { opacity: 0.5; }
.ticket-row .info { font-size: 14px; }
.ticket-row .num { font-weight: 700; }
.ticket-row .time { color: #888; font-size: 12px; margin-top: 2px; }
.ticket-row .amount { font-size: 17px; font-weight: 700; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 20px; margin-left: 6px; font-weight: 600; }
.pill.efectivo { background: #e2f5e9; color: #1c7a44; }
.pill.tarjeta { background: #e6eefc; color: #1e4fb0; }
.pill.anulado { background: #eee; color: #888; }
.close-day-bar { padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); flex-shrink: 0; }
.close-day-bar .big-btn { width: 100%; height: 56px; font-size: 18px; }

/* ---- Instalación / vincular ---- */
.setup-page { background: #f2f2f5; height: auto; min-height: 100dvh; user-select: text; padding: 16px; }
.setup-box { max-width: 460px; margin: 30px auto; background: #fff; border-radius: 16px; padding: 24px; }
.setup-box h1 { font-size: 22px; margin: 0 0 12px; }
.setup-box h1 small { font-size: 13px; color: #888; font-weight: 400; }
.setup-box p { line-height: 1.45; color: #444; }
.setup-box .big-btn { width: 100%; height: 52px; font-size: 18px; margin-top: 8px; }
.form-grid { display: flex; flex-direction: column; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 600; color: #333; }
input, select, textarea {
    font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 10px; border: 1px solid #ccc;
    background: #fff; color: #1c1c1e; width: 100%; user-select: text;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #2f6fed; border-color: transparent; }
.alert { background: #e6eefc; color: #1e4fb0; padding: 12px 14px; border-radius: 10px; margin: 10px 0; font-size: 14px; line-height: 1.4; }
.alert.error { background: #fdecea; color: #b8392e; }

/* ---- Layout móvil ---- */
@media (max-width: 700px) {
    .pos-body { flex-direction: column; }
    .ticket-panel { width: 100%; border-right: none; display: none; flex: 1; }
    .action-panel { width: 100%; flex: 1; }
    body.mobile-view-resumen .ticket-panel { display: flex; }
    body.mobile-view-resumen .action-panel { display: none; }
    body.mobile-view-resumen .ticket-mobile-actions {
        display: flex; gap: 8px; padding: 10px 16px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom)); flex-shrink: 0;
    }
    .ticket-mobile-actions .big-btn { flex: 1; height: 56px; }
    .family-finalize-row { display: none; }
    .family-mobile-bar {
        display: flex; align-items: center; justify-content: space-between;
        gap: 10px; padding: 10px 16px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        flex-shrink: 0; border-top: 1px solid #e0e0e2; background: #fff;
        margin: 8px -10px calc(-10px - env(safe-area-inset-bottom));
    }
    .family-mobile-total { font-size: 20px; font-weight: 700; }
    .family-mobile-bar .big-btn { height: 48px; padding: 0 24px; }
    .grid-buttons { grid-template-columns: repeat(2, 1fr); }
    .grid-buttons .big-btn { font-size: 20px; }
    .btn-cajon span { display: none; }
    .topbar .title { display: none; }
    .user-chip { max-width: 110px; }
}
