/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    min-height: 100vh;
}

/* ─── App Shell ─── */
.app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1.5rem;
}

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-700);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--gray-100); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--gray-700); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-icon { padding: 0.4rem 0.6rem; font-size: 1.1rem; font-weight: 700; }

/* ─── Year Navigation ─── */
.year-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.year-nav h2 {
    font-size: 1.5rem;
    min-width: 4rem;
    text-align: center;
}

/* ─── Months Grid ─── */
.months-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.month-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: var(--shadow);
}
.month-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}
.month-card .month-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--gray-800);
}
.month-card .month-status {
    font-size: 0.8rem;
    color: var(--gray-400);
}
.month-card.generated .month-status {
    color: var(--success);
    font-weight: 500;
}
.month-card .month-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 0.3rem;
}
.month-card .month-actions {
    margin-top: 0.7rem;
    display: flex;
    gap: 0.4rem;
}

/* ─── Payslip Viewer ─── */
.viewer-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}
.viewer-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1.1rem;
}
.viewer-actions {
    display: flex;
    gap: 0.5rem;
}

/* ─── Payslip Document ─── */
.payslip {
    background: white;
    border: 1px solid var(--gray-400);
    padding: 1.2rem 1.5rem;
    max-width: 780px;
    margin: 0 auto;
    font-size: 0.75rem;
    line-height: 1.3;
    color: var(--gray-900);
    display: flex;
    flex-direction: column;
    min-height: 1050px; /* ~A4 height minus margins */
}
.payslip-spacer {
    flex: 1;
}

.payslip-title {
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.7rem;
    color: var(--gray-900);
    border-bottom: 2px solid var(--gray-800);
    padding-bottom: 0.3rem;
}

.payslip-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.payslip-party {
    border: 1px solid var(--gray-400);
    padding: 0.4rem 0.6rem;
}
.payslip-party h4 {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 0.15rem;
}
.payslip-party .field {
    display: flex;
    gap: 0.2rem;
    margin-bottom: 0.1rem;
    font-size: 0.7rem;
}
.payslip-party .field .label {
    font-weight: 600;
    color: var(--gray-600);
    min-width: 3.5rem;
    flex-shrink: 0;
}
.payslip-party .field .value {
    color: var(--gray-800);
}

.payslip-period {
    border: 1px solid var(--gray-400);
    padding: 0.25rem 0.6rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
}
.payslip-period strong {
    color: var(--gray-700);
}

/* Tables */
.payslip table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.5rem;
    font-size: 0.7rem;
}
.payslip table th,
.payslip table td {
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--gray-400);
    text-align: left;
}
.payslip table th {
    background: var(--gray-100);
    font-weight: 700;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--gray-700);
}
.payslip table .amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.payslip table .total-row {
    font-weight: 700;
}
.payslip table .total-row td {
    border-top: 2px solid var(--gray-500);
}

.payslip-liquido {
    border: 2px solid var(--gray-800);
    padding: 0.35rem 0.6rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.payslip-liquido .liquido-amount {
    font-size: 0.95rem;
}

/* Bottom section: bases + employer costs side by side */
.payslip-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}
.payslip-bottom table {
    margin-bottom: 0;
}

.payslip-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--gray-600);
    margin-bottom: 0.2rem;
}

.payslip-signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 0.8rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--gray-400);
}
.payslip-signatures .sig-block {
    text-align: center;
    font-size: 0.7rem;
    color: var(--gray-500);
}
.payslip-signatures .sig-block .sig-line {
    border-bottom: 1px solid var(--gray-400);
    height: 2rem;
    margin-bottom: 0.2rem;
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 2rem 1rem;
}
.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 700px;
    max-height: none;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h2 { font-size: 1.2rem; }
.modal-close { font-size: 1.5rem; border: none; background: none; cursor: pointer; color: var(--gray-400); padding: 0.2rem; }
.modal-close:hover { color: var(--gray-700); }
.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: 70vh;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
}

/* ─── Config Sections ─── */
.config-section {
    margin-bottom: 1.5rem;
}
.config-section h3 {
    font-size: 1rem;
    color: var(--gray-700);
    margin-bottom: 0.8rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--gray-200);
}
.config-section .help-text {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 0.8rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}
.form-grid .full-width { grid-column: 1 / -1; }
.rates-grid { grid-template-columns: 1fr 1fr 1fr; }

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.25rem;
}
.form-group label small {
    font-weight: 400;
    color: var(--gray-400);
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--gray-800);
    background: white;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* ─── Notifications ─── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--gray-800);
    color: white;
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes slideIn {
    from { transform: translateY(1rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
    .app-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .app-header h1 { font-size: 1.1rem; }
    .months-grid { grid-template-columns: repeat(2, 1fr); }
    .payslip-header { grid-template-columns: 1fr; }
    .payslip-bottom { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .rates-grid { grid-template-columns: 1fr 1fr; }
    .viewer-toolbar { flex-direction: column; align-items: flex-start; }
    .payslip { padding: 0.8rem; font-size: 0.7rem; }
    .payslip-signatures { grid-template-columns: 1fr; }
    .year-nav { flex-wrap: wrap; }
}

/* ─── Print Styles ─── */
@media print {
    body { background: white; }
    .app-header, .viewer-toolbar, .dashboard, .modal-overlay { display: none !important; }
    .payslip-viewer { display: block !important; }
    .payslip {
        border: none;
        box-shadow: none;
        padding: 0;
        max-width: none;
        font-size: 8pt;
    }
    .payslip-liquido { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
