/* ============================================
   Sistema de Ventas — Estilos base
   ============================================ */

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.icon { width: 18px; height: 18px; flex-shrink: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ NAVBAR ============ */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.navbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    height: 62px;
    gap: 20px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.brand-icon { color: var(--primary); width: 22px; height: 22px; }
.brand-logo { height: 30px; width: auto; display: block; }

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    margin-left: auto;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-wrap: nowrap;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-link.active svg { color: var(--primary); }

.nav-divider { width: 1px; height: 24px; background: var(--border); margin: 0 6px; }

.nav-user { display: flex; flex-direction: column; margin-right: 4px; }
.nav-user-name { font-size: 13px; font-weight: 600; }
.nav-user-role { font-size: 11px; color: var(--text-muted); }

.nav-logout { color: var(--danger); }
.nav-logout:hover { background: var(--danger-light); color: var(--danger); }

/* ============ TABBAR (barra inferior estilo iOS, solo móvil) ============ */
.tabbar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    z-index: 150;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px 6px;
    font-size: 10.5px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}
.tabbar-item .icon { width: 22px; height: 22px; }
.tabbar-item.active { color: var(--primary); }
.tabbar-item:active { opacity: 0.6; }

/* ============ LAYOUT ============ */
.page-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.breadcrumb { font-size: 14px; margin-bottom: 12px; display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.breadcrumb a:hover { color: var(--primary); text-decoration: none; }

.back-link {
    display: flex; justify-content: flex-end; align-items: center; gap: 4px;
    font-size: 14px; color: var(--text-muted); text-decoration: none;
    margin: 4px 0 18px;
    padding-top: 4px;
    cursor: pointer;
}
.back-link:hover { color: var(--primary); text-decoration: none; }

/* ============ BUTTONS ============ */
.btn, button, .btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s;
}
.btn:hover, button:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active, button:active { transform: scale(0.98); }

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 6px 10px; font-size: 13px; }

/* ============ CARDS ============ */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-top: 20px; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    text-align: left;
    display: block;
    transition: box-shadow 0.15s, transform 0.15s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.card-icon { color: var(--primary); margin-bottom: 10px; }
.card-icon .icon { width: 26px; height: 26px; }
.card-title { font-weight: 600; font-size: 15px; color: var(--text); }
.card small { color: var(--text-muted); font-size: 12px; }
.card strong { font-size: 22px; }

/* ============ TABLE ============ */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; min-width: 480px; }

/* ============ TABLA DE VENTAS: columnas de ancho fijo ============ */
.sales-table { table-layout: fixed; }
.sales-table th, .sales-table td {
    overflow-wrap: break-word;
    word-break: break-word;
}
.sales-table th:nth-child(1), .sales-table td:nth-child(1) { width: 12%; } /* Fecha */
.sales-table th:nth-child(2), .sales-table td:nth-child(2) { width: 18%; } /* Cliente */
.sales-table th:nth-child(3), .sales-table td:nth-child(3) { width: 32%; } /* Producto */
.sales-table th:nth-child(4), .sales-table td:nth-child(4) { width: 14%; } /* Precio */
.sales-table th:nth-child(5), .sales-table td:nth-child(5) { width: 14%; } /* Entrega */
.sales-table th:nth-child(6), .sales-table td:nth-child(6) { width: 10%; } /* Acciones */
.table th, .table td { padding: 12px 16px; text-align: left; font-size: 14px; }
.table th {
    background: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}
table.sortable th:hover { color: var(--primary); }
table.sortable th.sort-asc::after { content: ' ▲'; font-size: 10px; }
table.sortable th.sort-desc::after { content: ' ▼'; font-size: 10px; }
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--bg); }
.table .row-actions { display: flex; gap: 10px; align-items: center; }
.table .row-actions a { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.table .icon { width: 15px; height: 15px; }

/* ============ FORMS ============ */
.form-box {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 24px;
    border-radius: var(--radius);
    max-width: 460px;
    box-shadow: var(--shadow);
}
.form-box label { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-box input, .form-box select {
    width: 100%;
    padding: 10px 12px;
    margin-top: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
}
.form-box input:focus, .form-box select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-box .form-actions { margin-top: 22px; display: flex; gap: 8px; }
.hint { display: block; font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ============ LOGIN ============ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    padding: 20px;
}
.login-box {
    max-width: 380px;
    width: 100%;
    background: var(--surface);
    padding: 36px 32px;
    border-radius: 14px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.login-box .brand-center { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 24px; }
.login-logo { height: 46px; width: auto; }
.login-box label { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.login-box input {
    width: 100%; padding: 11px 12px; margin-top: 6px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.login-box button { margin-top: 22px; width: 100%; justify-content: center; padding: 11px; font-size: 15px; }

/* ============ ALERTS / BADGES ============ */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.success, .alert-success { background: var(--success-light); color: #15803d; }
.error, .alert-error { background: var(--danger-light); color: var(--danger); }

.text-red { color: var(--danger); font-weight: 600; }
.text-green { color: var(--success); font-weight: 600; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-yellow { background: #fef3c7; color: #b45309; }
.badge-gray { background: var(--border); color: var(--text-muted); }

.balance-box {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 14px 22px; border-radius: var(--radius); font-weight: 700;
    margin: 14px 0; font-size: 18px;
}
.balance-red { background: var(--danger-light); color: var(--danger); }
.balance-green { background: var(--success-light); color: var(--success); }

section.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-top: 24px;
}
section.panel h2 { font-size: 16px; margin-bottom: 4px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 860px) {
    .nav-toggle { display: block; }
    .tabbar { display: flex; }
    .page-content { padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
    .nav-links {
        position: absolute;
        top: 62px;
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        display: none;
        box-shadow: var(--shadow-md);
    }
    .nav-links.open { display: flex; }
    .nav-link { padding: 12px; }
    .nav-divider { display: none; }
    .nav-user { flex-direction: row; justify-content: space-between; padding: 10px 12px; }
    .nav-user-name, .nav-user-role { font-size: 13px; }

    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .actions { flex-direction: column; }
    .page-header .actions .btn, .page-header .actions .btn-secondary { justify-content: center; }
}

/* ============ MODAL ============ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 440px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    animation: modalPop 0.15s ease-out;
}
@keyframes modalPop {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modal-header h2 { font-size: 18px; }
.modal-close { background: none; border: none; color: var(--text-muted); padding: 4px; cursor: pointer; }
.modal-close:hover { color: var(--text); background: none; }
.modal-box form label { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.modal-box form input:not([type="radio"]):not([type="checkbox"]), .modal-box form textarea {
    width: 100%; padding: 10px 12px; margin-top: 6px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
}
.modal-box form input:focus, .modal-box form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.modal-box form textarea { resize: vertical; }
.modal-box form input[type="radio"], .modal-box form input[type="checkbox"] {
    width: auto; margin: 0; padding: 0; flex-shrink: 0;
}
.modal-box .form-actions { margin-top: 20px; display: flex; gap: 8px; }

.link-btn {
    background: none; border: none; padding: 0; color: var(--primary);
    font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.link-btn:hover { text-decoration: underline; background: none; }
.link-btn.text-red { color: var(--danger); }

.client-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--primary-light); color: var(--primary); flex-shrink: 0;
}
.client-avatar .icon { width: 15px; height: 15px; }

/* ============ PAGINACIÓN ============ */
.pagination {
    display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
    margin-top: 16px; justify-content: center;
}
.page-link {
    padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px;
    color: var(--text-muted); border: 1px solid var(--border); text-decoration: none;
}
.page-link:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-dots { padding: 0 4px; color: var(--text-muted); }

.pagination-bar {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 12px; margin-top: 16px;
}
.pagination-bar .pagination { margin-top: 0; }
.per-page-selector { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.per-page-selector select {
    padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-family: inherit;
}

.quote-thumb {
    width: 40px; height: 40px; border-radius: 6px; object-fit: cover;
    border: 1px solid var(--border); flex-shrink: 0; background: var(--bg);
}
.quote-thumb-placeholder {
    width: 40px; height: 40px; border-radius: 6px; background: var(--bg);
    border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); flex-shrink: 0;
}
.quote-thumb-placeholder .icon { width: 18px; height: 18px; }

/* ============ BUSCADOR DE CLIENTE ============ */
.client-search-wrap { position: relative; }
.client-search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 220px;
    overflow-y: auto;
    z-index: 50;
}
.client-search-dropdown.open { display: block; }
.client-search-item { padding: 9px 12px; font-size: 14px; cursor: pointer; }
.client-search-item:hover { background: var(--primary-light); color: var(--primary); }
.client-search-empty { padding: 9px 12px; font-size: 13px; color: var(--text-muted); }

.total-invertido-box {
    margin-top: 14px;
    padding: 10px 14px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
}
.total-invertido-box strong { color: var(--primary); font-size: 16px; }

/* ============ RECIBOS (grid de miniaturas) ============ */
.receipts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}
.receipt-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
}
.receipt-card img { width: 100%; height: 110px; object-fit: cover; display: block; }
.receipt-meta {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 10px; font-size: 12px; color: var(--text-muted);
}
.ebay-photo-card { cursor: pointer; border: 2px solid transparent; transition: border-color 0.15s; }
.ebay-photo-card:hover { border-color: var(--primary-light); }
.ebay-photo-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

.multi-product-row {
    display: flex; gap: 8px; align-items: center; margin-top: 8px;
}
.multi-product-row .multi-product-name { flex: 3; }
.multi-product-row .multi-product-qty { flex: 0 0 60px; text-align: center; }
.multi-product-row .multi-product-price { flex: 2; }
.multi-product-row input {
    padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
}

/* ============ SUBNAV (pestañas) ============ */
.subnav {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.subnav-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}
.subnav-tab:hover { color: var(--primary); text-decoration: none; }
.subnav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
