:root {
    --bg-dark: #0a0f1d;
    --bg-card: #141c33;
    --bg-body: #080b15;
    --border-color: #202b47;
    
    --primary-color: #0033FF;
    --primary-glow: rgba(0, 51, 255, 0.4);
    --accent-orange: #FF6B00;
    --accent-orange-glow: rgba(255, 107, 0, 0.3);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-body);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    border: none;
    text-decoration: none;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #0055ff);
    color: white;
}
.btn-primary:hover {
    box-shadow: 0 0 15px var(--primary-glow);
    transform: translateY(-1px);
}
.btn-secondary {
    background: var(--border-color);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}
.btn-block {
    display: flex;
    width: 100%;
    justify-content: center;
}

/* Forms */
.form-group {
    margin-bottom: 1.2rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}
.form-group label i {
    margin-right: 5px;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 0.7rem 1rem;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-control-inline {
    width: auto;
    display: inline-block;
    padding: 0.5rem 1rem;
}

/* Login Panel */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-body);
    padding: 1.5rem;
    background: radial-gradient(circle at 50% 30%, rgba(0, 51, 255, 0.12) 0%, transparent 60%);
}
.login-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
}
.login-logo {
    text-align: center;
    margin-bottom: 2.5rem;
}
.login-logo .logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    background-color: rgba(255, 107, 0, 0.15);
    border: 1px solid var(--accent-orange);
    border-radius: 12px;
    color: var(--accent-orange);
    font-size: 1.8rem;
    margin-bottom: 1rem;
    box-shadow: 0 0 15px var(--accent-orange-glow);
}
.login-logo h2 {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
}
.login-logo h2 span {
    color: var(--accent-orange);
}
.login-logo p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 2px;
}
.login-error-msg {
    color: var(--color-danger);
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 1rem;
    font-weight: 600;
}

/* Main Dashboard wrapper */
.app-wrapper {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    background-color: var(--bg-dark);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.2rem;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 3rem;
}
.sidebar-header .logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background-color: rgba(255, 107, 0, 0.1);
    border: 1px solid var(--accent-orange);
    border-radius: 8px;
    color: var(--accent-orange);
    font-size: 1.1rem;
}
.sidebar-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 800;
}
.sidebar-header h3 span {
    color: var(--accent-orange);
}
.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}
.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}
.menu-item:hover, .menu-item.active {
    background-color: rgba(0, 51, 255, 0.1);
    color: var(--text-main);
}
.menu-item.active {
    border-left: 3px solid var(--primary-color);
    border-radius: 0 8px 8px 0;
}
.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: white;
    font-size: 0.9rem;
}
.user-info {
    display: flex;
    flex-direction: column;
}
.user-info .username {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}
.user-info .role {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: capitalize;
}
.btn-logout {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s;
}
.btn-logout:hover {
    color: var(--color-danger);
}

/* Content Area */
.content-area {
    padding: 2.5rem;
    overflow-y: auto;
    height: 100vh;
}
.app-view {
    display: none;
}
.app-view.active {
    display: block;
}
.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}
.view-header h2 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.8rem;
}
.header-actions {
    display: flex;
    gap: 10px;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.8rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.card h3 {
    font-family: 'Outfit', sans-serif;
    margin-bottom: 1.25rem;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}
.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}
.card-header-flex h3 {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}
.grid-costs {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1.5rem;
}
.mt-2 { margin-top: 1.5rem; }
.mt-1 { margin-top: 1rem; }

/* Tables */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}
.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}
.table th, .table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}
.table th {
    background-color: rgba(255, 255, 255, 0.02);
    font-weight: 600;
    color: var(--text-muted);
}
.table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}
.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.01);
}

/* Badges Status */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}
.status-borrador { background-color: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.status-enviado { background-color: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.status-aprobado { background-color: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.status-rechazado { background-color: rgba(239, 68, 68, 0.2); color: #fca5a5; }

/* Totales block */
.totals-layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.5rem;
}
.totals-card {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.totals-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    color: var(--text-muted);
}
.totals-row strong {
    color: var(--text-main);
}
.totals-row.highlight-sub {
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    font-size: 1.05rem;
}
.totals-row.highlight {
    border-top: 2px solid var(--primary-color);
    padding-top: 10px;
    margin-top: 5px;
    font-size: 1.25rem;
    color: var(--text-main);
    font-weight: 700;
}
.totals-row.highlight strong {
    color: var(--accent-orange);
}

/* Upload input wrappers */
.upload-btn-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
}
.upload-btn-wrapper input[type=file] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}

.scrollable-table-container {
    max-height: 500px;
    overflow-y: auto;
}

/* Action buttons in tables */
.btn-action-group {
    display: flex;
    gap: 6px;
}
.btn-action {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.btn-action:hover {
    background: var(--border-color);
    border-color: var(--text-muted);
}
.btn-action.delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
    border-color: var(--color-danger);
}

/* Template Cards */
.template-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 180px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
.template-card-header h4 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}
.template-card-header span {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    display: block;
    margin-top: 4px;
}
.template-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

/* Responsive */
@media (max-width: 1024px) {
    .app-wrapper {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none; /* simple collapse, app.js could handle sidebar toggle if we add a mobile bar */
    }
    .grid-costs {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
    .totals-layout {
        grid-template-columns: 1fr;
    }
    .content-area {
        padding: 1.2rem;
    }
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}

/* -------------------------------------------------------------
   PRINT STYLING (FOR PRODUCING PROFESSIONAL CLEAN PDF INVOICES)
   ------------------------------------------------------------- */
@media print {
    /* Set defaults to ensure everything that is not display: none prints correctly */
    html, body {
        visibility: visible !important;
        opacity: 1 !important;
        background-color: white !important;
        color: #1a1a1a !important;
    }

    /* Hide everything on the app UI safely */
    #app-container, #login-container, .toast-msg, #clear-db-modal, #preview-quote-modal {
        display: none !important;
    }
    
    /* Make invoice area visible */
    #print-quote-sheet {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    #print-quote-sheet * {
        visibility: visible !important;
    }
    
    /* Position print sheet in top-left */
    #print-quote-sheet {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background-color: white !important;
        color: #1a1a1a !important;
        font-family: 'Inter', Arial, sans-serif;
        padding: 0;
        margin: 0;
    }
    
    body {
        background-color: white !important;
        color: #1a1a1a !important;
    }
    
    /* Details styling for print */
    .print-invoice-sheet {
        background-color: white !important;
        color: #111 !important;
    }
    .print-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 20px;
    }
    .print-header .logo-wrapper {
        display: flex;
        align-items: center;
        gap: 15px;
    }
    .print-header .logo-lightning {
        font-size: 32px;
        color: #FF6B00 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .print-header h2 {
        font-family: 'Outfit', sans-serif;
        font-size: 22px;
        font-weight: 800;
        color: #0033FF !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        margin: 0;
    }
    .print-header p {
        font-size: 11px;
        color: #666;
        margin: 2px 0 0 0;
    }
    .matricula {
        font-size: 10px;
        background-color: #eee;
        padding: 2px 6px;
        border-radius: 4px;
        display: inline-block;
        margin-top: 4px;
        font-weight: bold;
    }
    
    .invoice-meta {
        text-align: right;
    }
    .invoice-meta h1 {
        font-family: 'Outfit', sans-serif;
        font-size: 26px;
        font-weight: 800;
        color: #FF6B00 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        margin-bottom: 6px;
    }
    .invoice-meta p {
        font-size: 12px;
        margin: 2px 0;
        color: #333;
    }

    .print-divider {
        height: 2px;
        background-color: #0033FF !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        margin: 20px 0;
    }

    .print-info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        margin-bottom: 30px;
    }
    .info-block h4 {
        font-family: 'Outfit', sans-serif;
        font-size: 12px;
        font-weight: 700;
        border-bottom: 1px solid #ddd;
        padding-bottom: 4px;
        margin-bottom: 8px;
        color: #0033FF !important;
    }
    .info-block p {
        font-size: 12px;
        margin: 4px 0;
        color: #333;
    }

    /* Print Table */
    .print-table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 30px;
    }
    .print-table th {
        background-color: #f5f5f5 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        border-bottom: 2px solid #ddd;
        color: #111;
        font-weight: bold;
        font-size: 11px;
        padding: 8px 10px;
        text-transform: uppercase;
    }
    .print-table td {
        border-bottom: 1px solid #eee;
        padding: 10px;
        font-size: 11px;
        color: #333;
    }

    .print-totals-layout {
        display: grid;
        grid-template-columns: 1.2fr 1fr;
        gap: 30px;
        page-break-inside: avoid;
    }
    .terms-conditions h4 {
        font-family: 'Outfit', sans-serif;
        font-size: 12px;
        font-weight: 700;
        border-bottom: 1px solid #ddd;
        padding-bottom: 4px;
        margin-bottom: 8px;
        color: #0033FF !important;
    }
    .terms-conditions p {
        font-size: 11px;
        margin: 4px 0;
        color: #555;
    }

    .print-totals-table {
        width: 100%;
        border-collapse: collapse;
    }
    .print-totals-table td {
        padding: 6px 10px;
        font-size: 12px;
        color: #333;
    }
    .print-totals-table td:last-child {
        text-align: right;
        font-weight: bold;
    }
    .print-totals-table .print-grand-total {
        background-color: #f5f5f5 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-size: 15px;
        font-weight: bold;
        border-top: 2px solid #FF6B00;
    }
    .print-totals-table .print-grand-total td {
        padding: 10px;
        color: #FF6B00 !important;
    }

    .print-footer {
        margin-top: 60px;
        border-top: 1px solid #eee;
        padding-top: 15px;
        text-align: center;
    }
    .print-footer p {
        font-size: 10px;
        color: #777;
        margin: 2px 0;
    }
}

/* Fix quote items header and select button visual overlap */
.quote-items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}
.quote-items-title {
    flex-shrink: 0;
    white-space: nowrap;
}
.item-selector-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    flex-grow: 1;
    justify-content: flex-end;
}
.select-search-db {
    min-width: 260px;
    max-width: 420px;
    flex-grow: 1;
}

/* Toast confirmation for adding items */
.toast-msg {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--color-success);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
}
.toast-msg.show {
    opacity: 1;
    transform: translateY(0);
}

