:root {
    /* Color Palette - Modern Light Theme */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --accent-purple: #8b5cf6;
    --danger: #ef4444;
    --success: #10b981;
    --glass-border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 80px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-primary);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

h1,
h2,
h3,
.logo span {
    font-family: 'Outfit', sans-serif;
}

/* App Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.sidebar-header {
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-purple);
}

.sidebar-nav {
    padding: 1rem;
    flex-grow: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    transition: var(--transition);
}

.nav-link i {
    font-size: 1.2rem;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    transition: var(--transition);
}

/* Top Header */
.top-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.header-info h1 {
    font-size: 1.8rem;
    margin-bottom: 0.2rem;
}

.header-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

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

.liquidar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.7rem 1.2rem;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    background: #fee2e2;
    color: var(--danger);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.liquidar-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    background: var(--danger);
    color: white;
}

#liquidar-comisiones-btn {
    background: #dcfce7;
    color: var(--success);
}

#liquidar-comisiones-btn:hover {
    background: var(--success);
    color: white;
}

.toggle-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
}

/* Sections Control */
.content-section {
    display: none;
    animation: fadeIn 0.5s ease;
}

.content-section.active {
    display: block;
}

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

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.full-width {
    grid-column: span 2;
}

.stat-card,
.worker-card,
.chart-card,
.form-card,
.history-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

/* Goal Card */
.goal-card {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-color: #bfdbfe;
    color: var(--text-main);
}


.goal-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}

.goal-numbers {
    text-align: right;
}

.current-total {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-purple);
}

.target-total {
    font-size: 1.2rem;
    color: var(--text-muted);
}

/* Progress Bars */
.progress-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.progress-bar-wrap {
    flex-grow: 1;
    height: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar-wrap.small {
    height: 8px;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-light), var(--primary));
    width: 0%;
    transition: width 1.5s cubic-bezier(0.1, 0, 0.1, 1);
    box-shadow: 0 0 10px rgba(142, 68, 173, 0.5);
}

/* Worker Cards */
.worker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.worker-name h2 {
    font-size: 1.5rem;
}

.badge {
    background: #eff6ff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--primary);
}

.worker-header i {
    font-size: 2.5rem;
    color: var(--primary-light);
}

.worker-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.mini-stat {
    display: flex;
    flex-direction: column;
}

.mini-stat .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.mini-stat .value {
    font-size: 1.3rem;
    font-weight: 700;
}

.missing-amount {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: right;
}

.worker-details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 1.5rem;
}

.detail-item,
.detail-itemHighlight {
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
}

.detail-itemHighlight {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.detail-item small,
.detail-itemHighlight small {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-bottom: 2px;
}

.detail-item span,
.detail-itemHighlight span {
    font-weight: 600;
    font-size: 0.95rem;
}

/* Forms */
.form-card {
    max-width: 600px;
    margin: 0 auto;
}

.form-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 2rem;
}

.form-header i {
    font-size: 2rem;
    color: var(--primary-light);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

input,
select,
textarea {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

textarea {
    height: 100px;
    resize: none;
}

.submit-btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 1rem;
}

.submit-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(142, 68, 173, 0.4);
}

.small-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: #f1f5f9;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.small-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

.small-btn i { font-size: 0.9rem; }

/* History/Tables */
.table-container {
    overflow-x: auto;
    margin-top: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--glass-border);
}

td {
    padding: 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.btn-delete {
    background: rgba(231, 76, 60, 0.1);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.2);
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

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

/* Charts */
.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .full-width {
        grid-column: span 1;
    }

    .charts-container {
        grid-template-columns: 1fr;
    }
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
        z-index: 1001; /* Above overlay */
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 25px rgba(0,0,0,0.1);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .top-header {
        padding: 0 1rem;
        gap: 10px;
    }

    .header-info h1 {
        font-size: 1.2rem;
    }

    .toggle-btn {
        display: block;
    }

    .stats-grid, 
    .charts-container,
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .modal-content {
        width: 95%;
        padding: 1.5rem;
        margin: 2% auto;
    }

    .invoice-header-pro {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .invoice-title-box h1 {
        text-align: left;
        font-size: 1.8rem;
    }

    .invoice-footer-pro {
        flex-direction: column;
        gap: 1.5rem;
    }

    .totals-section {
        width: 100%;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow-y: auto;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 2.5rem;
    border-radius: 20px;
    width: 90%;
    max-width: 850px;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.close-modal {
    position: absolute;
    right: 25px;
    top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
}

.close-modal:hover {
    color: var(--danger);
}

/* --- Invoice Header: 3-column layout --- */
.invoice-header-pro {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #1e293b;
    gap: 10px;
}

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

.shop-logo-box {
    width: 55px;
    height: 55px;
    min-width: 55px;
    background: #1e293b;
    color: white;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    border-radius: 12px;
    font-family: 'Outfit', sans-serif;
}

.shop-details h3 {
    font-size: 1.1rem;
    font-weight: 900;
    color: #1e293b;
    margin: 0 0 3px 0;
    font-family: 'Outfit', sans-serif;
}

.shop-details p {
    font-size: 0.78rem;
    margin: 1px 0;
    color: #64748b;
}

/* Center column: title + compact metadata */
.invoice-title-center {
    flex: 1;
    text-align: center;
}

.invoice-title-center h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    color: #1e293b;
    margin: 0 0 6px 0;
    line-height: 1;
    letter-spacing: -0.02em;
}

.invoice-meta-box {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 6px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 4px 8px;
    min-width: 70px;
}

.meta-item > span:first-child {
    font-size: 0.6rem;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.meta-item > strong,
.meta-item > span:not(:first-child) {
    font-size: 0.82rem;
    color: #1e293b;
    font-weight: 700;
}

/* Right column: QR code */
.qr-header-section {
    flex: 0.8;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.qr-header-section #qrcode {
    width: 110px;
    height: 110px;
    background: white;
    padding: 5px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    box-sizing: border-box !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-header-section #qrcode img,
.qr-header-section #qrcode canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    display: block;
}

.qr-header-section small {
    font-size: 0.58rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}


.invoice-meta {
    background: #ffffff;
    padding: 0;
    border-radius: 8px;
    min-width: 220px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
}

.meta-row:last-child {
    border-bottom: none;
    background: #f8fafc;
}

.meta-row span {
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meta-row strong {
    color: #1e293b;
    font-weight: 800;
}

.client-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 20px;
    background: #ffffff;
    padding: 0;
    margin-bottom: 2.5rem;
}

.info-item {
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-left: 3px solid #f1f5f9;
    transition: all 0.2s;
}

.info-item:hover {
    border-left-color: #3b82f6;
    background: #f8fafc;
}

.info-item label {
    font-size: 0.6rem;
    font-weight: 800;
    color: #94a3b8;
    margin-bottom: 4px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.info-item span {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.9rem;
    word-break: break-word;
    line-height: 1.2;
}

.invoice-table-pro {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2.5rem;
}

.invoice-table-pro th {
    background: #1e293b;
    color: #ffffff;
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 12px 15px;
    text-align: left;
}

.invoice-table-pro th:last-child {
    text-align: right;
}

.invoice-table-pro td {
    padding: 15px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.85rem;
    color: #1e293b;
    vertical-align: middle;
}

.invoice-table-pro td:last-child {
    text-align: right;
    font-weight: 700;
}

.invoice-table-pro td:nth-child(5) {
    text-align: right;
}

.invoice-table-pro th:nth-child(5) {
    text-align: right;
}

.invoice-footer-pro {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 1rem;
}

.qr-section {
    width: 150px;
    text-align: center;
}

#qrcode {
    background: white;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 5px;
    display: inline-block;
}

#qrcode img {
    margin: 0 auto;
}

.totals-section {
    width: 320px;
    background: #f8fafc;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.total-row:last-child {
    margin-bottom: 0;
    padding-top: 12px;
    border-top: 2px solid #e2e8f0;
}

.total-row span {
    font-weight: 600;
    color: #64748b;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.total-row strong {
    font-size: 1.2rem;
    font-weight: 800;
    color: #1e293b;
}

.balance-row strong {
    font-size: 1.8rem;
    color: #3b82f6;
}

.pagare-section {
    border-top: 1px dashed #cbd5e1;
    padding-top: 2rem;
    margin-bottom: 2rem;
}

.pagare-section h3 {
    text-align: center;
    text-decoration: underline;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: #1e293b;
}

.pagare-section p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: #475569;
    margin-bottom: 1rem;
}

.signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
}

.sig-box {
    width: 45%;
    text-align: center;
}

.sig-line {
    border-top: 1px solid #1e293b;
    margin-bottom: 10px;
}

.sig-box span {
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
}

.notice-footer {
    border-top: 1px solid #f1f5f9;
    padding-top: 1rem;
    font-size: 0.7rem;
    color: #94a3b8;
    font-style: italic;
    line-height: 1.4;
}

/* Printing logic */
@media print {
    @page {
        margin: 0.5cm;
        size: auto;
    }

    /* Hide UI elements */
    header, aside, .toggle-btn, .close-modal, #print-invoice-btn, .modal-actions, button, .modal-header {
        display: none !important;
    }

    /* Reset body and layout */
    body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .app-container, .main-content, .public-container, .form-card {
        display: none !important;
    }

    #invoice-modal, #invoice-modal * {
        visibility: visible !important;
    }

    /* Optimize Invoice Modal for Print */
    #invoice-modal {
        display: block !important;
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        background: white !important;
        overflow: visible !important;
    }

    .modal-content {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }

    #invoice-print-area {
        display: block !important;
        padding: 0 !important;
    }

    /* Preserve Flexbox and Grid Layouts */
    .invoice-header-pro, 
    .client-info-grid, 
    .signatures, 
    .invoice-footer-pro,
    .shop-info {
        display: flex !important;
    }

    .invoice-header-pro {
        display: grid !important;
        grid-template-columns: 1.5fr 1fr 120px !important;
        align-items: center !important;
        border-bottom: 2px solid #334155 !important;
        padding-bottom: 0.5rem !important;
        margin-bottom: 0.8rem !important;
        overflow: visible !important;
    }

    .invoice-title-center h1 {
        font-size: 1.8rem !important;
    }

    .invoice-meta-box {
        gap: 10px !important;
    }

    .qr-header-section {
        align-items: flex-end !important;
        width: 120px !important;
        min-width: 120px !important;
        overflow: visible !important;
    }

    #qrcode {
        width: 110px !important;
        height: 110px !important;
        overflow: visible !important;
    }

    #qrcode img {
        width: 100px !important;
        height: 100px !important;
    }

    /* Pagaré Compacto */
    .pagare-section {
        margin-top: 0.5rem !important;
        padding-top: 0.5rem !important;
        margin-bottom: 0.5rem !important;
    }

    .pagare-section h3 {
        font-size: 9pt !important;
        margin-bottom: 5px !important;
    }

    .pagare-section p {
        font-size: 7.5pt !important;
        line-height: 1.3 !important;
        margin-bottom: 5px !important;
    }

    .signatures {
        margin-top: 1.5rem !important;
    }

    .sig-line {
        margin-bottom: 5px !important;
    }

    .sig-box span {
        font-size: 7pt !important;
    }

    /* Footer Notice */
    .notice-footer {
        padding-top: 0.5rem !important;
        font-size: 6.5pt !important;
    }

    /* Avoid page breaks in middle of sections */
    .invoice-header-pro, 
    .client-info-grid, 
    .pagare-section,
    .signatures {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Force background colors */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}