/* 
  AFM POS Mobile v2 - Styles
  Optimized for touch, single-hand use, and "power outage" scenarios.
*/

:root {
    --primary: #7c3aed;
    --primary-dark: #6d28d9;
    --bg-dark: #0f172a;
    --surface-dark: #1e293b;
    --border-dark: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Evitar scroll doble con el body */
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* App Wrapper: Restablece el contexto flex que tenían antes del refactor */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* Header Styles */
.main-header {
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
    box-sizing: border-box;
    position: sticky;
    top: 0;
    z-index: 100;
}

body.light .main-header {
    background: rgba(255, 255, 255, 0.85);
    border-bottom: 1px solid #f1f5f9;
    box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

.header-left {
    flex: 1;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-container img {
    height: 32px;
    width: 32px;
}

.brand-info h1 {
    font-size: 16px;
    font-weight: 900;
    margin: 0;
    letter-spacing: -0.5px;
    line-height: 1;
}

.brand-info h1 span {
    color: var(--primary);
}

.user-subtext {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sucursal-pill {
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.3);
    padding: 8px 14px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    max-width: 150px;
}

.sucursal-pill span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sucursal-pill i:last-child {
    font-size: 8px;
    opacity: 0.5;
}

.sucursal-pill:active {
    scale: 0.95;
    background: rgba(124, 58, 237, 0.2);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 10px var(--danger);
}

.status-dot.active {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

/* Sucursal List Items */
.sucursal-item {
    padding: 18px;
    border-radius: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 8px;
}

.sucursal-item:active {
    scale: 0.98;
    background: rgba(124, 58, 237, 0.05);
}

.sucursal-item.active {
    border-color: var(--primary);
    background: rgba(124, 58, 237, 0.1);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.1);
}

.sucursal-item-name {
    font-size: 14px;
    font-weight: 900;
    color: var(--text-contrast);
}

.sucursal-item-check {
    color: var(--primary);
    font-size: 18px;
    display: none;
}

.sucursal-item.active .sucursal-item-check {
    display: block;
}

/* Main Container */
main {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 160px; 
}

.section {
    display: none;
    padding: 16px;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Common UI Elements */
.card {
    background: var(--surface-dark);
    border-radius: 20px;
    border: 1px solid var(--border-dark);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.label-title {
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: block;
}

/* Search Area */
#search-input-container {
    position: relative;
}

#mobile-search-input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    border-radius: 12px;
    padding: 14px 14px 14px 44px;
    color: white;
    font-weight: 600;
    font-size: 16px;
    box-sizing: border-box;
    outline: none;
}

#mobile-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* Results Area */
#mobile-search-results {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.search-result-item {
    background: var(--surface-dark);
    border: 1px solid var(--border-dark);
    padding: 12px;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.res-info h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
}

.res-info p {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.res-price {
    font-weight: 900;
    color: var(--primary-light);
    font-size: 15px;
}

/* Cart Items */
.cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-dark);
}

.item-info {
    flex: 1;
}

.item-info h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
}

.item-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-dark);
    border-radius: 12px;
    padding: 4px;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--surface-dark);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-val {
    font-weight: 900;
    font-size: 14px;
    min-width: 24px;
    text-align: center;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(15px);
    border-top: 1px solid var(--border-dark);
    display: flex;
    justify-content: space-around;
    padding: 10px 0 24px; /* Space for home bar on iOS */
    z-index: 200;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item i {
    font-size: 20px;
}

/* Floating Action Button (Checkout) */
.checkout-fab {
    position: fixed;
    bottom: 90px;
    right: 20px;
    left: 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 900;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 10px 25px -5px rgba(124, 58, 237, 0.5);
    z-index: 150;
    transition: transform 0.2s;
}

.checkout-fab:active {
    transform: scale(0.96);
}

/* Sheets / Modals */
.mobile-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: flex-end;
    z-index: 1000;
}

.mobile-modal.active {
    display: flex;
}

.modal-sheet {
    background: var(--surface-dark);
    width: 100%;
    border-radius: 30px 30px 0 0;
    padding: 24px 20px 40px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 900;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: -0.5px;
}

.close-sheet {
    padding: 8px;
    color: var(--text-muted);
}

/* Payment Grid */
.payment-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.payment-btn {
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
}

.payment-btn.active {
    border-color: var(--primary);
    background: rgba(124, 58, 237, 0.1);
    color: var(--primary);
}

.payment-btn i {
    font-size: 24px;
}

/* Utilities */
.text-primary { color: var(--primary); }
.font-black { font-weight: 900; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.mt-2 { margin-top: 8px; }
.hidden { display: none; }

/* Modal & Search Fixes */
.close-sheet, #btn-clear-search {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.close-sheet:active, #btn-clear-search:active {
    transform: scale(0.9);
}

/* History Card Enhancement */
#section-historial .card {
    border-left: 4px solid var(--primary);
    transition: transform 0.1s;
}

#section-historial .card:active {
    transform: scale(0.98);
    background: var(--bg-dark);
}

@keyframes bounceIn {
    0% { transform: translateX(-50%) translateY(20px); opacity: 0; }
    50% { transform: translateX(-50%) translateY(-5px); opacity: 1; }
    100% { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Cart Inputs */
.cart-qty-input,
.cart-edit-input {
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    color: var(--text-contrast);
    padding: 6px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    width: 70px;
    text-align: center;
    transition: all 0.2s;
}

.cart-qty-input:focus,
.cart-edit-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.cart-qty-input {
    width: 55px;
    color: var(--primary);
}

/* Chrome, Safari, Edge, Opera: Remove arrows */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Firefox: Remove arrows */
input[type=number] {
  appearance: none;
  -moz-appearance: textfield;
}

/* Mobile Login Screen */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--bg-dark);
    display: flex; /* Visible by default, auth.js hides it if session is found */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-image: 
        radial-gradient(at 0% 0%, rgba(124, 58, 237, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(124, 58, 237, 0.1) 0px, transparent 50%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-dark);
    border-radius: 32px;
    padding: 40px 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: zoomIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header img {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
}

.login-header h2 {
    font-size: 24px;
    font-weight: 900;
    margin: 0;
    letter-spacing: -1px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 8px;
    font-weight: 500;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.login-input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border-dark);
    border-radius: 12px;
    padding: 16px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    box-sizing: border-box;
    transition: all 0.2s;
}

.login-input:focus {
    border-color: var(--primary);
    background: #000;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
    outline: none;
}

#login-btn {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 14px;
    padding: 18px;
    font-size: 16px;
    font-weight: 900;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 12px;
    box-shadow: 0 10px 15px -3px rgba(124, 58, 237, 0.4);
    transition: all 0.2s;
}

#login-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

#login-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

#login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
    padding: 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 20px;
    display: none;
    text-align: center;
}
