/* ============================================================
   MAYOR LV - SISTEMA ADMINISTRATIVO
   Mobile-First | Modern Design | Inspired by Mercado Libre
   ============================================================ */

:root {
    --primary: #3483fa;
    --primary-dark: #2968c8;
    --primary-light: #e8f0fe;
    --secondary: #ff6000;
    --success: #00a650;
    --danger: #ff3333;
    --warning: #fff0d6;
    --info: #3483fa;
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --text: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border: #e0e0e0;
    --border-light: #f0f0f0;
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --shadow-hover: 0 4px 16px rgba(0,0,0,.12);
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --sidebar-width: 260px;
    --header-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: .2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, #1a4f8b 100%);
}

.login-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    text-align: center;
}

.login-logo {
    font-size: 48px;
    margin-bottom: 8px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.97); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #008f45; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #cc0000; }

.btn-warning { background: var(--secondary); color: white; }
.btn-warning:hover { background: #e65500; }

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

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

.btn-sm { padding: 8px 16px; font-size: 13px; min-height: 36px; }
.btn-lg { padding: 16px 32px; font-size: 16px; }
.btn-icon { padding: 8px; width: 40px; height: 40px; border-radius: 50%; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: var(--font);
    color: var(--text);
    background: white;
    transition: border-color var(--transition);
    -webkit-appearance: none;
    appearance: none;
    min-height: 48px;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { min-height: 100px; resize: vertical; }
.form-input-lg { padding: 16px; font-size: 18px; }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

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

/* SIDEBAR */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: white;
    border-right: 1px solid var(--border);
    z-index: 100;
    overflow-y: auto;
    transition: transform var(--transition);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--header-height);
}

.sidebar-logo { font-size: 28px; }
.sidebar-title { font-size: 18px; font-weight: 700; color: var(--text); }
.sidebar-subtitle { font-size: 11px; color: var(--text-muted); }

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 2px;
    -webkit-tap-highlight-color: transparent;
}
.nav-item:hover { background: var(--border-light); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item .nav-icon { font-size: 20px; width: 24px; text-align: center; }
.nav-item .nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-user { flex: 1; }
.sidebar-user-name { font-size: 14px; font-weight: 600; }
.sidebar-user-role { font-size: 12px; color: var(--text-muted); }

/* MAIN CONTENT */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin var(--transition);
}

.main-header {
    position: sticky;
    top: 0;
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    color: var(--text);
}

.main-header h2 { font-size: 18px; font-weight: 600; flex: 1; }

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

.main-body {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

/* SIDEBAR OVERLAY */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.5);
    z-index: 99;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-hover); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}
.card-title { font-size: 16px; font-weight: 600; }
.card-body { }
.card-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: #e8f5e9; color: var(--success); }
.stat-icon.red { background: #ffebee; color: var(--danger); }
.stat-icon.orange { background: #fff3e0; color: var(--secondary); }

.stat-info { flex: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-change { font-size: 12px; margin-top: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead { background: var(--bg); }
th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    border-bottom: 2px solid var(--border);
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
tr:hover td { background: var(--border-light); }
tr:last-child td { border-bottom: none; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    gap: 4px;
}
.badge-pendiente { background: #fff3cd; color: #856404; }
.badge-confirmado { background: #d4edda; color: #155724; }
.badge-entregado { background: #cce5ff; color: #004085; }
.badge-cancelado { background: #f8d7da; color: #721c24; }
.badge-success { background: #d4edda; color: #155724; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-info { background: #cce5ff; color: #004085; }

/* ============================================================
   SEARCH & FILTERS
   ============================================================ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}
.search-box input {
    width: 100%;
    padding: 12px 40px 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    background: white;
    transition: border-color var(--transition);
    min-height: 44px;
}
.search-box input:focus { outline: none; border-color: var(--primary); }
.search-box .search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    animation: fadeIn .2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    margin-top: 40px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: slideUp .3s ease;
    overflow: hidden;
}

.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title { font-size: 18px; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

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

.toast {
    padding: 14px 20px;
    border-radius: var(--radius);
    color: white;
    font-weight: 500;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    animation: slideIn .3s ease;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
.toast.warning { background: var(--secondary); }
.toast.removing { animation: slideOut .3s ease forwards; }

/* ============================================================
   CART (for pedidos)
   ============================================================ */
.cart-container {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    min-height: 100px;
    max-height: 400px;
    overflow-y: auto;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
}

.cart-item:last-child { border-bottom: none; }

.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; font-size: 14px; }
.cart-item-price { font-size: 13px; color: var(--text-muted); }

.cart-item-qty {
    display: flex;
    align-items: center;
    gap: 8px;
}
.cart-item-qty button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cart-item-qty input {
    width: 50px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    font-size: 14px;
}

.cart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 15px;
}

/* ============================================================
   PRODUCT SELECTOR
   ============================================================ */
.product-selector {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px 0;
}

.product-select-item {
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 12px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}
.product-select-item:hover { border-color: var(--primary); }
.product-select-item.selected { border-color: var(--primary); background: var(--primary-light); }
.product-select-item .prod-name { font-size: 13px; font-weight: 600; }
.product-select-item .prod-price { font-size: 15px; color: var(--primary); font-weight: 700; margin-top: 4px; }

/* ============================================================
   CHARTS (simple bar chart in CSS)
   ============================================================ */
.chart-bar-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 200px;
    padding: 20px 0;
}

.chart-bar {
    flex: 1;
    background: var(--primary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    min-width: 20px;
    transition: height .5s ease;
    position: relative;
    cursor: pointer;
}
.chart-bar:hover { opacity: .8; }
.chart-bar .chart-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.chart-bar .chart-value {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

/* ============================================================
   GRID
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100px); } }

/* ============================================================
   RESPONSIVE - MOBILE FIRST
   ============================================================ */

/* Mobile (< 768px) */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }

    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }

    .main-body { padding: 16px; }
    .main-header { padding: 0 16px; }

    .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
    .stat-icon { width: 44px; height: 44px; font-size: 20px; }

    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    .product-selector { grid-template-columns: repeat(2, 1fr); }

    .toolbar { flex-direction: column; }
    .toolbar > * { width: 100%; }

    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-content {
        max-width: 100%;
        margin-top: auto;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 90vh;
        overflow-y: auto;
    }

    .login-card { padding: 30px 20px; }
    table { font-size: 13px; }
    th, td { padding: 10px 12px; }
}

/* Tablet (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar { width: 220px; }
    .main-content { margin-left: 220px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .product-selector { grid-template-columns: repeat(3, 1fr); }
}

/* Desktop (1025px+) */
@media (min-width: 1025px) {
    html { font-size: 15px; }

    .sidebar {
        width: 260px;
        box-shadow: 2px 0 12px rgba(0,0,0,.04);
    }

    .sidebar-nav { padding: 12px; }
    .nav-item {
        padding: 14px 16px;
        font-size: 14px;
        border-radius: 8px;
    }
    .nav-item .nav-icon { font-size: 22px; }

    .main-content { margin-left: 260px; }
    .main-body { padding: 32px; }
    .main-header {
        padding: 0 32px;
        height: 64px;
    }
    .main-header h2 { font-size: 22px; }

    .stat-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
    .stat-card { padding: 24px; }
    .stat-value { font-size: 28px; }
    .stat-icon { width: 60px; height: 60px; font-size: 28px; }

    .grid-2 { grid-template-columns: 1fr 1fr; gap: 24px; }
    .grid-3 { grid-template-columns: 1fr 1fr 1fr; gap: 24px; }

    .card { padding: 24px; }
    .card-title { font-size: 18px; }

    .product-selector {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
        max-height: 400px;
    }
    .product-select-item { padding: 20px 16px; }
    .product-select-item .prod-name { font-size: 14px; }
    .product-select-item .prod-price { font-size: 16px; }

    table { font-size: 14px; }
    th, td { padding: 14px 20px; }

    .toolbar { gap: 16px; }
    .search-box { min-width: 300px; }
    .search-box input { font-size: 14px; }

    .modal-content { max-width: 700px; }
    .modal-body { padding: 28px; }
    .modal-header { padding: 24px 28px 16px; }
    .modal-footer { padding: 16px 28px; }
    .modal-title { font-size: 20px; }

    .chart-bar-container { height: 250px; }

    .btn { min-height: 40px; }
    .form-input, .form-select, .form-textarea { min-height: 44px; font-size: 14px; }

    /* Dashboard sections layout */
    .dashboard-grid-2 {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        margin-bottom: 24px;
    }
    .dashboard-grid-3 {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 24px;
        margin-bottom: 24px;
    }

    #toast-container { top: 20px; right: 24px; }
    .toast { padding: 16px 24px; font-size: 15px; max-width: 450px; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.flex { display: flex; }
.flex-1 { flex: 1; }
.flex-center { align-items: center; justify-content: center; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-lg { font-size: 18px; }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
}
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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