* {
    box-sizing: border-box;
    text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background-color: #f7f8fa;
    color: #1a1a1a;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

button, input, select {
    font-family: inherit;
}

/* Deshabilitar flechas en inputs numéricos */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
input[type=number] {
    -moz-appearance: textfield;
}

/* HEADER */
header {
    background: #ffffff;
    border-bottom: 1px solid #dee2e6;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
    padding: 14px 20px;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-brand {
    font-size: 1.15rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge-sync {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 20px;
    font-weight: 600;
    background: #f1f3f5;
    color: #6c757d;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* BOTONES GLOBALES */
.btn-primary {
    background: #0d6efd;
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.btn-primary:hover { background: #0b5ed7; }

.btn-primary-block {
    background: #0d6efd;
    color: #ffffff;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.btn-primary-block:hover { background: #0b5ed7; }

.btn-outline-danger {
    background: transparent;
    color: #dc3545;
    border: 1px solid #dc3545;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-outline-danger:hover { background: #fff5f5; }

.btn-link {
    background: none;
    border: none;
    color: #0d6efd;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
}

/* CONTROLES Y FILTROS */
.controls-container {
    max-width: 1200px;
    margin: 25px auto 15px auto;
    padding: 0 20px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.tabs {
    display: flex;
    gap: 6px;
    background: #ffffff;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid #dee2e6;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    color: #6c757d;
    cursor: pointer;
    font-size: 0.88rem;
    transition: all 0.2s;
}

.tab-btn.active {
    background: #1a1a1a;
    color: #ffffff;
}

.search-input {
    flex: 1;
    min-width: 220px;
    padding: 10px 14px;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    font-size: 0.92rem;
    outline: none;
    background: #ffffff;
}

.sort-select {
    max-width: 230px;
    cursor: pointer;
}

/* CONTENEDOR PRINCIPAL */
.content-area {
    max-width: 1200px;
    margin: 0 auto 40px auto;
    padding: 0 20px;
}

.card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    border: 1px solid #dee2e6;
    overflow: hidden;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th {
    background: #f8f9fa;
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #6c757d;
    text-transform: uppercase;
    border-bottom: 2px solid #dee2e6;
    text-align: left;
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid #f1f3f5;
    vertical-align: middle;
}

.client-meta {
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 3px;
}

/* FILAS DE ÍTEMS */
.item-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    background: #f8f9fa;
    padding: 8px 12px;
    border-radius: 8px;
    gap: 12px;
    border: 1px solid #eef0f2;
}

/* BADGES HOMOGÉNEOS Y PASTEL */
.item-tag {
    font-size: 0.68rem;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border: 1px solid transparent;
}

/* 1. En Tránsito */
.tag-espera { 
    background: #fff8e1; 
    color: #b45309; 
    border-color: #fef3c7; 
}

/* 2. Llega Hoy */
.tag-hoy { 
    background: #ffedd5; 
    color: #c2410c; 
    border-color: #fed7aa; 
}

/* 3. Llegó */
.tag-pasado { 
    background: #e0f2fe; 
    color: #0369a1; 
    border-color: #bae6fd; 
}

/* 4. En Stock */
.tag-llegado { 
    background: #dcfce7; 
    color: #15803d; 
    border-color: #bbf7d0; 
}

a.item-tag:hover {
    filter: brightness(0.95);
    text-decoration: none;
}

/* ABONOS Y ESTADO PAGO */
.badge-pago {
    font-size: 0.78rem;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 700;
    display: inline-block;
}

.pago-completo { background: #d1e7dd; color: #0f5132; }
.pago-pendiente { background: #ffebee; color: #c62828; }

/* ACCIONES */
.action-buttons {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.btn-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    background: #ffffff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s ease;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
    stroke: currentColor;
    fill: none;
}

.btn-icon.edit { color: #0d6efd; }
.btn-icon.edit:hover { background: #e7f1ff; border-color: #0d6efd; }
.btn-icon.delete { color: #dc3545; }
.btn-icon.delete:hover { background: #f8d7da; border-color: #dc3545; }

/* VISTA COMPLETADOS (CARDS) */
.client-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    display: none;
}

.client-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
}

.client-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    border-bottom: 1px solid #f1f3f5;
    padding-bottom: 10px;
}

.client-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    color: #1a1a1a;
}

.client-stats {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.stat-box {
    flex: 1;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #e9ecef;
}

.stat-box.profit {
    background: #e8f5e9;
    border-color: #c8e6c9;
}

.stat-value {
    font-size: 1.05rem;
    font-weight: 800;
    display: block;
    color: #1a1a1a;
}

.stat-box.profit .stat-value {
    color: #198754;
}

.stat-label {
    font-size: 0.65rem;
    color: #6c757d;
    text-transform: uppercase;
    font-weight: 700;
}

.btn-history-styled {
    background: #1a1a1a;
    color: #ffffff;
    border: none;
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    width: 100%;
    margin-top: auto;
    transition: background 0.2s ease;
}

.btn-history-styled:hover {
    background: #333333;
}

/* VISTA MÉTRICAS */
.metrics-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.metrics-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.kpi-card {
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.kpi-card.profit-card {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.kpi-card.debt-card {
    background: #fff7ed;
    border-color: #fed7aa;
}

.debt-card .kpi-value {
    color: #c2410c;
}

.debt-card .kpi-sub {
    font-size: 0.8rem;
    color: #9a3412;
    font-weight: 600;
    margin-top: 4px;
}

.kpi-label {
    font-size: 0.75rem;
    color: #6c757d;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: #1a1a1a;
}

.profit-card .kpi-value {
    color: #16a34a;
}

.kpi-sub {
    font-size: 0.8rem;
    color: #15803d;
    font-weight: 600;
    margin-top: 4px;
}

.metrics-table-card {
    padding: 16px 20px;
}

.metrics-header-bar h3 {
    margin: 0 0 16px 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1a1a1a;
}

.metrics-table th {
    background: #f8f9fa;
}

.metrics-table td {
    font-size: 0.9rem;
}

/* MODAL Y FORMULARIO */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.45);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 16px;
}

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

.modal-content {
    background: #ffffff;
    width: 100%;
    max-width: 780px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 14px;
    padding: 22px;
}

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

.modal-header h3 { margin: 0; font-size: 1.15rem; }
.btn-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: #6c757d; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.82rem; font-weight: 700; color: #495057; margin-bottom: 5px; }

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    background: #ffffff;
}

.form-control:focus { border-color: #0d6efd; }

/* GRID 2x2 SUPERIOR EN DESKTOP */
.grid-form-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 4px;
}

/* COMBOBOX PERSONALIZADO */
.combobox-wrapper {
    position: relative;
    width: 100%;
}

.combobox-input-container {
    display: flex;
    position: relative;
    align-items: center;
}

.combobox-input-container input {
    padding-right: 36px;
}

.combobox-toggle-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 6px;
}

.combobox-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
    max-height: 220px;
    overflow-y: auto;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    z-index: 1050;
}

.combobox-item {
    padding: 10px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.combobox-item:hover, .combobox-item.active {
    background: #f1f3f5;
    color: #0d6efd;
    font-weight: 600;
}

.combobox-item-create {
    padding: 10px 14px;
    font-size: 0.88rem;
    cursor: pointer;
    color: #0d6efd;
    font-weight: 700;
    background: #f0f7ff;
    border-top: 1px solid #dee2e6;
    transition: background 0.15s ease;
}

.combobox-item-create:hover {
    background: #e1effe;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

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

.form-items-container {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.form-item-row {
    display: grid;
    grid-template-columns: 1.8fr 0.9fr 1.2fr 1.3fr 1.3fr auto;
    gap: 8px;
    align-items: center;
    background: #ffffff;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    margin-bottom: 8px;
}

.item-check-stock {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #495057;
    background: #f8f9fa;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #dee2e6;
    cursor: pointer;
}

.finance-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    background: #e9ecef;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.payment-box {
    background: #f1f8ff;
    border: 1px solid #c8e1ff;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 14px;
}



/* HISTORIAL CLIENTE */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-order-card {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 14px;
    border-radius: 8px;
}

.history-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed #dee2e6;
    font-size: 0.88rem;
}

/* AUTH */
#authLockScreen {
    display: flex;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background: #f7f8fa;
    padding: 16px;
}

.auth-card {
    background: #ffffff;
    padding: 35px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 320px;
    text-align: center;
    border: 1px solid #dee2e6;
}

.auth-card input { margin-bottom: 12px; }
#authErrorMsg { color: #dc3545; font-size: 0.8rem; display: none; margin-top: 8px; }

.empty-state {
    padding: 40px;
    text-align: center;
    color: #6c757d;
}

.font-bold { font-weight: 700; }
.text-blue { color: #0d6efd; }

/* OPTIMIZACIÓN MOBILE CON 16PX MIN PADDING */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    header {
        padding: 14px 16px;
    }
    .header-container {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    .header-actions {
        justify-content: space-between;
    }
    .controls-container {
        padding: 0 16px;
        margin: 16px auto 12px auto;
        gap: 10px;
    }
    .content-area {
        padding: 0 16px;
        margin-bottom: 24px;
    }
    .tabs {
        width: 100%;
    }
    .tab-btn {
        flex: 1;
        text-align: center;
    }
    .search-input {
        min-width: 100%;
    }
    .sort-select {
        max-width: 100%;
        width: 100%;
    }
    .client-card {
        padding: 16px;
    }
    .client-stats {
        flex-direction: column;
        gap: 8px;
    }
    .modal-overlay {
        padding: 16px;
    }
    .modal-content {
        padding: 16px;
    }
    .grid-form-top, .grid-2, .finance-grid, .form-item-row {
        grid-template-columns: 1fr;
    }
}
