/* 
   Facturia - Premium Design System Stylesheet
   Designed for High-End UX, Responsiveness, and RIDE print outputs.
*/

/* ===== Tema OSCURO (por defecto) ===== */
:root,
[data-theme="dark"] {
    --bg-app: #0b0f19;
    --bg-sidebar: #111827;
    --bg-secondary: #161d2e;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);

    --success: #10b981;
    --info: #06b6d4;
    --warning: #f59e0b;
    --danger: #ef4444;

    --font-sans: 'Plus Jakarta Sans', 'Outfit', sans-serif;
    --border-radius: 12px;
    --transition-speed: 0.2s;
}

/* ===== Tema CLARO ===== */
[data-theme="light"] {
    --bg-app: #f4f5f9;
    --bg-sidebar: #ffffff;
    --bg-secondary: #eef0f6;
    --card-bg: #ffffff;
    --card-border: rgba(15, 23, 42, 0.08);
    --border-color: rgba(15, 23, 42, 0.08);
    --text-primary: #111827;
    --text-secondary: #6b7280;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #9333ea 100%);

    --success: #059669;
    --info: #0891b2;
    --warning: #d97706;
    --danger: #dc2626;
}

/* ===== Tema ESMERALDA (tercera opción de marca) ===== */
[data-theme="esmeralda"] {
    --bg-app: #06120f;
    --bg-sidebar: #0a1a16;
    --bg-secondary: #0f231d;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(52, 211, 153, 0.15);
    --border-color: rgba(52, 211, 153, 0.15);
    --text-primary: #ecfdf5;
    --text-secondary: #a7bdb5;

    --primary: #10b981;
    --primary-hover: #059669;
    --primary-gradient: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);

    --success: #34d399;
    --info: #22d3ee;
    --warning: #fbbf24;
    --danger: #f87171;

    --font-sans: 'Plus Jakarta Sans', 'Outfit', sans-serif;
    --border-radius: 12px;
    --transition-speed: 0.2s;
}

/* Alias de compatibilidad para variables usadas en el HTML con otros nombres */
:root {
    --primary-color: var(--primary);
    --text-color: var(--text-primary);
    --accent-color: var(--primary);
    --success-color: var(--success);
    --danger-color: var(--danger);
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    overflow-x: hidden;
}

/* App Container (Sidebar + Main) */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ---------------- SIDEBAR ---------------- */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    flex-shrink: 0;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, border-right 0.3s ease;
}

.sidebar.collapsed {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    border-right: none;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    background: var(--primary-gradient);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.5rem;
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.sidebar-brand h2 {
    font-size: 1.35rem;
    font-weight: 700;
    background: linear-gradient(to right, #fff, #9ca3af);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    transition: all var(--transition-speed) ease;
}

.menu-item svg {
    transition: transform 0.2s ease;
}

.menu-item:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

.menu-item:hover svg {
    transform: translateX(3px);
}

.menu-item.active {
    color: #fff;
    background: var(--primary-gradient);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.25);
}

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

.sri-status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

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

.status-dot.offline {
    background-color: var(--warning);
    box-shadow: 0 0 10px var(--warning);
}

/* ---------------- MAIN CONTENT ---------------- */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 40px;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

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

.top-header h1 {
    font-size: 1.85rem;
    font-weight: 700;
}

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

.profile-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.profile-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.profile-avatar {
    width: 38px;
    height: 38px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    border: 1px solid var(--card-border);
}

/* ---------------- BUTTONS ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 8px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1.05rem;
}

/* ---------------- CARDS & STRUCTURE ---------------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    padding: 24px;
    backdrop-filter: blur(12px);
}

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

.card-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Stats Dashboard Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    backdrop-filter: blur(10px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.stat-icon.purple { background-color: rgba(99, 102, 241, 0.15); color: #818cf8; }
.stat-icon.green { background-color: rgba(16, 185, 129, 0.15); color: #34d399; }
.stat-icon.blue { background-color: rgba(6, 182, 212, 0.15); color: #22d3ee; }
.stat-icon.orange { background-color: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.stat-content h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ---------------- TABLES ---------------- */
.table-responsive {
    overflow-x: hidden;
    width: 100%;
}

/* Search bar */
.search-bar-container {
    flex: 1;
    min-width: 220px;
    max-width: 480px;
}

.search-input {
    background: rgba(255,255,255,0.05) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: 8px !important;
    padding: 8px 14px !important;
    color: var(--text-primary) !important;
    width: 100%;
    font-size: 0.88rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

.search-input::placeholder {
    color: var(--text-secondary);
}


.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table th, .table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--card-border);
    font-size: 0.85rem;
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.01);
}

/* Badges de Estado */
.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background-color: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-warning { background-color: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-danger { background-color: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-info { background-color: rgba(6, 182, 212, 0.15); color: #22d3ee; }

/* ---------------- SPA VIEWS ---------------- */
.spa-view {
    display: none;
}

.spa-view.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

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

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

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.col-6 { flex: 0 0 calc(50% - 10px); }
.col-4 { flex: 0 0 calc(33.33% - 13px); }
.col-3 { flex: 0 0 calc(25% - 15px); }
.col-8 { flex: 0 0 calc(66.66% - 7px); }
.col-12 { flex: 0 0 100%; }

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* El autocompletado de Chrome/Safari pinta el campo con fondo claro y puede dejar el texto
   (blanco, por el tema oscuro) invisible. Forzamos aquí el mismo fondo/color del tema. */
.form-control:-webkit-autofill,
.form-control:-webkit-autofill:hover,
.form-control:-webkit-autofill:focus {
    -webkit-text-fill-color: #fff;
    caret-color: #fff;
    -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.05) inset;
    transition: background-color 9999s ease-in-out 0s;
}

select.form-control option {
    background-color: var(--bg-sidebar);
    color: #fff;
}

/* LOPDP Consent box */
.consent-clause-box {
    background-color: rgba(99, 102, 241, 0.05);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 8px;
    padding: 16px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.consent-clause-box h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #818cf8;
    margin-bottom: 8px;
}

.clause-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.4;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-group label {
    margin-bottom: 0;
    color: var(--text-primary);
    cursor: pointer;
}

/* ---------------- MODALS ---------------- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    width: 500px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-content.large {
    width: 850px;
}

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

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 30px;
}

/* Items Invoice Form Styles */
.items-section {
    margin-top: 25px;
    margin-bottom: 20px;
}

.items-section h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 8px;
}

.invoice-summary-box {
    margin-top: 25px;
    padding: 16px;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    width: 320px;
    margin-left: auto;
}

.summary-line {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.summary-line.total {
    border-top: 1px solid var(--card-border);
    padding-top: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
}

/* Notifications Box */
.alert {
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

/* Dentro de #notification-area (fijo, con gap) no se necesita el margen de flujo normal. */
#notification-area .alert {
    margin-bottom: 0;
}

.alert-success { background-color: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.3); color: #34d399; }
.alert-danger { background-color: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.3); color: #f87171; }
.alert-info { background-color: rgba(6, 182, 212, 0.15); border: 1px solid rgba(6, 182, 212, 0.3); color: #22d3ee; }
.alert-warning { background-color: rgba(234, 179, 8, 0.15); border: 1px solid rgba(234, 179, 8, 0.3); color: #fbbf24; }

/* ---------------- RIDE PRINT STYLES ---------------- */
.print-only {
    display: none;
}

@media print {
    body * {
        visibility: hidden;
    }
    
    .print-only, .print-only * {
        visibility: visible;
    }
    
    .print-only {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        color: #000 !important;
        background-color: #fff !important;
        padding: 20px;
    }
    
    /* Layout RIDE */
    .ride-container {
        font-family: Arial, sans-serif;
        color: #000;
    }
    
    .ride-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 30px;
        gap: 20px;
    }
    
    .ride-box {
        border: 1px solid #000;
        border-radius: 8px;
        padding: 15px;
        width: 48%;
        font-size: 0.8rem;
        line-height: 1.4;
    }
    
    .ride-info-title {
        font-weight: bold;
        font-size: 1rem;
        margin-bottom: 8px;
    }
    
    .ride-table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
    }
    
    .ride-table th, .ride-table td {
        border: 1px solid #000;
        padding: 8px;
        font-size: 0.8rem;
        text-align: left;
    }
    
    .ride-table th {
        background-color: #f2f2f2;
    }
    
    .ride-totals {
        width: 300px;
        margin-left: auto;
        border-collapse: collapse;
        margin-top: 20px;
    }
    
    .ride-totals td {
        border: 1px solid #000;
        padding: 6px;
        font-size: 0.8rem;
    }
    
    .ride-totals td:last-child {
        text-align: right;
    }
}

/* Searchable Select Dropdown */
.searchable-select {
    position: relative;
    width: 100%;
}

.searchable-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    background: #1e1b4b; /* Dark purple matching theme */
    border: 1px solid var(--card-border);
    border-radius: 6px;
    z-index: 1050;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

.searchable-option {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: background-color 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.searchable-option:last-child {
    border-bottom: none;
}

.searchable-option:hover {
    background-color: var(--primary);
    color: #fff;
}

/* ---------------- ADICIONALES PARA MÓDULOS DE CONTROL COMERCIAL ---------------- */
/* Report Header printable and screen views */
.report-header {
    border-left: 4px solid var(--primary);
    background: rgba(255, 255, 255, 0.02);
}

.report-company-logo {
    border-radius: 6px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
}

/* SVG Chart styles */
.chart-bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    width: 45px;
}

.chart-bar {
    width: 24px;
    background: var(--primary-gradient);
    border-radius: 4px 4px 0 0;
    transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 10px rgba(168, 85, 247, 0.2);
    position: relative;
}

.chart-bar:hover::after {
    content: attr(data-value);
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-sidebar);
    color: #fff;
    font-size: 0.75rem;
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid var(--card-border);
    white-space: nowrap;
    z-index: 10;
}

.chart-label {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Print Overrides for reports */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
    }
    
    .sidebar, .top-header, .view-actions, .card-header .btn, #statement-client-select, .form-group select {
        display: none !important;
    }
    
    .main-content {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .spa-view.active {
        display: block !important;
    }
    
    .spa-view:not(.active) {
        display: none !important;
    }
    
    .card {
        background: #fff !important;
        color: #000 !important;
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
        padding: 15px !important;
        margin-bottom: 20px !important;
    }
    
    .report-header {
        border-left: 4px solid #000 !important;
        background: #f9f9f9 !important;
    }
    
    .report-company-logo {
        background: none !important;
        border: 1px solid #ccc !important;
    }
    
    .table th, .table td {
        color: #000 !important;
        border-bottom: 1px solid #ddd !important;
    }
    
    .badge {
        border: 1px solid #ccc !important;
        background: none !important;
        color: #000 !important;
    }
}

