/* =============================================
   Sistema El Rebusque - Web
   Design System (Mobile-First)
   Tokens replicados de ui_shared.py
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --color-bg: #0B0E14;
    --color-card: #161B22;
    --color-surface: #0D1117;
    --color-accent: #58A6FF;
    --color-accent-hover: #1F6FEB;
    --color-text-main: #F0F6FC;
    --color-text-dim: #8B949E;
    --color-success: #238636;
    --color-gold: #D1A054;
    --color-danger: #F85149;
    --color-border: #30363D;
    --color-input-bg: #0D1117;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius-card: 15px;
    --radius-btn: 10px;
    --radius-input: 10px;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --bottom-nav-height: 65px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text-main);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); text-decoration: none; }
img { max-width: 100%; height: auto; }

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at center, rgba(88,166,255,0.03) 0%, transparent 70%);
    animation: loginGlow 8s ease-in-out infinite alternate;
}

@keyframes loginGlow {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5%, 5%) scale(1.1); }
}

.login-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    padding: 40px 30px;
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
    animation: slideUp 0.6s ease-out;
}

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

.login-logo {
    display: block;
    width: 180px;
    margin: 0 auto 25px;
}

.login-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-accent);
    margin-bottom: 8px;
}

.login-subtitle {
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 30px;
}

.login-error {
    background: rgba(248,81,73,0.1);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    padding: 12px 15px;
    border-radius: var(--radius-btn);
    font-size: 0.875rem;
    margin-bottom: 20px;
    text-align: center;
    animation: shake 0.4s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-dim);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-input);
    color: var(--color-text-main);
    font-family: var(--font-family);
    font-size: 1rem;
    transition: var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(88,166,255,0.15);
}

.form-input::placeholder { color: var(--color-text-dim); }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 24px;
    border: none;
    border-radius: var(--radius-btn);
    font-family: var(--font-family);
    font-size: 0.9375rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-accent);
    color: #fff;
    width: 100%;
}

.btn-primary:hover { background: var(--color-accent-hover); transform: translateY(-1px); }

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

.btn-secondary:hover { background: #3D444D; }

.btn-danger {
    background: transparent;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

.btn-danger:hover { background: rgba(248,81,73,0.1); }

.btn-success {
    background: var(--color-success);
    color: #fff;
}

.btn-gold {
    background: var(--color-gold);
    color: #0B0E14;
}

.btn-sm { height: 38px; padding: 0 16px; font-size: 0.8125rem; width: auto !important; }
.btn-lg { height: 56px; font-size: 1.0625rem; }
.btn-block { width: 100% !important; }

/* ===== APP LAYOUT ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR (Desktop) ===== */
.sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.sidebar.open { left: 0; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 999;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.show { display: block; }

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 1px solid var(--color-border);
    text-align: center;
}

.sidebar-logo {
    width: 120px;
    margin-bottom: 10px;
}

.sidebar-title {
    display: block;
    font-size: 1rem;
    font-weight: 800;
    color: var(--color-accent);
    letter-spacing: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 15px 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-btn);
    color: var(--color-text-dim);
    font-size: 0.9375rem;
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
    margin-bottom: 4px;
}

.nav-item:hover { background: rgba(88,166,255,0.08); color: var(--color-text-main); }
.nav-item.active { background: rgba(88,166,255,0.12); color: var(--color-accent); font-weight: 700; }

.nav-icon { font-size: 1.25rem; width: 28px; text-align: center; }

.nav-divider { height: 1px; background: var(--color-border); margin: 12px 16px; }

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--color-border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.875rem;
}

.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 0.8125rem; font-weight: 600; color: var(--color-text-main); }
.user-role { font-size: 0.6875rem; color: var(--color-text-dim); }

.logout-btn { color: var(--color-danger) !important; }
.logout-btn:hover { background: rgba(248,81,73,0.1) !important; }

/* ===== TOPBAR ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 15px;
    height: var(--topbar-height);
    padding: 0 20px;
    background: rgba(11,14,20,0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
}

.hamburger {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.hamburger span {
    width: 22px;
    height: 2px;
    background: var(--color-text-main);
    border-radius: 2px;
    transition: var(--transition);
}

.topbar-title {
    flex: 1;
    font-size: 1.125rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-role-badge {
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.badge-admin { background: rgba(88,166,255,0.15); color: var(--color-accent); }
.badge-employee { background: rgba(209,160,84,0.15); color: var(--color-gold); }
.badge-cashier { background: rgba(46,160,67,0.15); color: #3fb950; }

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    min-width: 0;
    max-width: 100vw;
    min-height: 100vh;
    padding-bottom: var(--bottom-nav-height);
    overflow-x: hidden;
}

.content-wrapper {
    padding: 20px;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    min-width: 0;
}

/* ===== CARDS ===== */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    padding: 20px;
    margin-bottom: 15px;
    transition: var(--transition);
    min-width: 0;
    max-width: 100%;
}

.card:hover { border-color: rgba(88,166,255,0.2); }

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

.card-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-accent);
}

/* ===== STAT CARDS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    padding: 18px 15px;
    text-align: center;
    min-width: 0;
    overflow: hidden;
}

.stat-icon { font-size: 1.75rem; margin-bottom: 8px; }
.stat-label { font-size: 0.75rem; color: var(--color-text-dim); font-weight: 600; margin-bottom: 4px; }
.stat-value { font-size: 1.375rem; font-weight: 800; }
.stat-sub { font-size: 0.6875rem; color: var(--color-text-dim); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== TABLES (Mobile: cards, Desktop: table) ===== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    display: none;
}

.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.875rem;
}

.data-table th {
    background: var(--color-surface);
    color: var(--color-text-dim);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
}

.data-table tr:hover td { background: rgba(88,166,255,0.04); }

/* Mobile Product Cards */
.product-cards { display: flex; flex-direction: column; gap: 12px; }

.product-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    padding: 15px;
    display: flex;
    gap: 15px;
    align-items: center;
    transition: var(--transition);
    cursor: pointer;
}

.product-card:active { transform: scale(0.98); }

.product-card-img {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    flex-shrink: 0;
}

.product-card-info { flex: 1; min-width: 0; }

.product-card-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
    margin-bottom: 2px;
}

.product-card-code {
    font-size: 0.75rem;
    color: var(--color-text-dim);
    margin-top: 2px;
}

.product-card-price {
    font-size: 1rem;
    font-weight: 800;
    color: var(--color-accent);
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
}

.product-card-stock {
    font-size: 0.6875rem;
    color: var(--color-text-dim);
    text-align: right;
}

/* ===== BOTTOM NAVIGATION ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: rgba(13,17,23,0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 900;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 12px;
    color: var(--color-text-dim);
    text-decoration: none;
    font-size: 0.625rem;
    font-weight: 600;
    transition: var(--transition);
    border-radius: 8px;
}

.bottom-nav-item.active { color: var(--color-accent); }
.bottom-nav-item:active { transform: scale(0.9); }
.bottom-nav-icon { font-size: 1.375rem; }

/* ===== SEARCH BAR ===== */
.search-bar {
    position: relative;
    margin-bottom: 20px;
}

.search-bar .form-input {
    padding-left: 44px;
    height: 48px;
}

.search-bar::before {
    content: '🔍';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    z-index: 1;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-btn);
    font-size: 0.875rem;
    font-weight: 600;
    animation: toastIn 0.4s ease-out;
    min-width: 250px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.toast-success { background: var(--color-success); color: #fff; }
.toast-error { background: var(--color-danger); color: #fff; }
.toast-info { background: var(--color-accent); color: #fff; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
    min-width: 0;
}

@media (max-width: 500px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    .page-header .btn {
        width: 100% !important;
        justify-content: center;
    }
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--color-text-dim);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 15px; }
.empty-state-text { font-size: 1rem; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 25px;
    animation: slideUp 0.3s ease-out;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--color-accent);
    margin-bottom: 20px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-dim); }

/* ===== UTILITIES ===== */
.text-accent { color: var(--color-accent); }
.text-gold { color: var(--color-gold); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-dim { color: var(--color-text-dim); }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.fw-extra { font-weight: 800; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.p-0 { padding: 0 !important; }
.p-2 { padding: 10px !important; }
.p-3 { padding: 15px !important; }

/* ================================================================
   DESKTOP OVERRIDES (768px+)
   ================================================================ */
@media (min-width: 768px) {
    .sidebar {
        left: 0;
        position: fixed;
    }

    .sidebar-overlay { display: none !important; }

    .hamburger { display: none; }

    .main-content {
        margin-left: var(--sidebar-width);
        padding-bottom: 0;
    }

    .bottom-nav { display: none; }

    .content-wrapper { padding: 30px 40px; }

    .stats-grid { grid-template-columns: repeat(4, 1fr); }

    .data-table { display: table; }
    .product-cards { display: none; }

    .page-title { font-size: 2rem; }

    .toast-container { top: 30px; right: 30px; }
}

@media (min-width: 1200px) {
    .content-wrapper { padding: 40px 50px; }
}

/* ===== SCANNER UI ===== */
.scanner-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    position: relative;
    border-radius: var(--radius-card);
    overflow: hidden;
    background: #000;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    aspect-ratio: 1;
}

#reader {
    width: 100% !important;
    border: none !important;
}

#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

.scanner-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scanner-outline {
    width: 70%;
    height: 70%;
    border: 2px solid var(--color-accent);
    border-radius: 15px;
    box-shadow: 0 0 0 1000px rgba(0,0,0,0.5);
    position: relative;
}

.scanner-line {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-accent);
    box-shadow: 0 0 15px var(--color-accent);
    animation: scanLine 2s linear infinite;
}

@keyframes scanLine {
    0% { top: 0; }
    50% { top: 100%; }
    100% { top: 0; }
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.05); opacity: 1; }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.scanner-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}
/* Estilos para filas interactivas */
.data-table tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background-color: rgba(56, 139, 253, 0.1) !important;
}

.btn-delete {
    background-color: transparent;
    color: #f85149;
    border: 1px solid #30363d;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-delete:hover {
    background-color: #f85149;
    color: white;
    border-color: #f85149;
}
.nav-badge {
    background: #ff0000;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 900;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: auto;
    box-shadow: 0 0 12px #ff0000, 0 0 6px #ff5555;
    text-shadow: 0 0 3px #fff;
    border: 1px solid rgba(255,255,255,0.3);
    animation: badgePulse 1.5s infinite ease-in-out;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 12px #ff0000, 0 0 6px #ff5555; }
    50% { transform: scale(1.15); box-shadow: 0 0 22px #ff0000, 0 0 12px #ff5555; }
}
