:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #eff6ff;
    --success: #059669;
    --success-soft: #ecfdf5;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --purple: #7c3aed;
    --purple-soft: #f5f3ff;
    --cyan: #0891b2;
    --cyan-soft: #ecfeff;
    --gold: #b45309;
    --gold-soft: #fefce8;
    --wa: #16a34a;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* TOPBAR & STEPPER */
.topbar {
    background: #0f172a;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-inner {
    max-width: 1360px;
    margin: 0 auto;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
    width: 36px; height: 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, #2563eb, #06b6d4);
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
}
.brand-icon.lg { width: 50px; height: 50px; font-size: 24px; margin: 0 auto 10px; }
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #94a3b8; }

.context-switcher {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: rgba(255,255,255,0.08);
    padding: 6px 12px;
    border-radius: 10px;
}

.ctx-group { display: flex; flex-direction: column; gap: 2px; }
.ctx-group label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: #cbd5e1; }
.ctx-group select {
    background: #1e293b;
    color: #fff;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 13px;
    font-weight: 600;
}
.ctx-client select { min-width: 240px; max-width: 360px; }

.user-actions { display: flex; align-items: center; gap: 10px; }
.btn-link { color: #cbd5e1; font-size: 13px; padding: 5px 9px; border-radius: 6px; }
.btn-link:hover, .btn-link.active { background: rgba(255,255,255,0.12); color: #fff; text-decoration: none; }
.user-pill { font-size: 12px; color: #e2e8f0; background: rgba(255,255,255,0.1); padding: 5px 10px; border-radius: 99px; }
.btn-logout {
    color: #fecaca; font-size: 12px; padding: 5px 10px;
    border: 1px solid rgba(248,113,113,0.4); border-radius: 6px;
}
.btn-logout:hover { background: rgba(239,68,68,0.2); text-decoration: none; }

.stepper-bar {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
}
.stepper-inner {
    max-width: 1360px;
    margin: 0 auto;
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
}
.step-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 8px;
    color: var(--text);
    border: 1px solid transparent;
    white-space: nowrap;
    transition: all 0.15s;
}
.step-item:hover { background: #f8fafc; border-color: var(--border); text-decoration: none; }
.step-item.active { background: var(--primary-soft); border-color: #bfdbfe; color: var(--primary); }
.step-num {
    width: 24px; height: 24px; border-radius: 50%;
    background: #e2e8f0; color: #334155;
    font-weight: 700; font-size: 12px;
    display: flex; align-items: center; justify-content: center;
}
.step-item.active .step-num { background: var(--primary); color: #fff; }
.step-text { display: flex; flex-direction: column; line-height: 1.15; }
.step-text strong { font-size: 13px; }
.step-text small { font-size: 11px; color: var(--muted); }
.step-arrow { color: #cbd5e1; font-weight: bold; }

/* LAYOUT & CARDS */
.main-container { max-width: 1360px; margin: 20px auto; padding: 0 18px 40px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 4px; font-size: 21px; color: #0f172a; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.subcard {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}
.subcard h3 { margin: 0 0 8px; font-size: 14px; color: #0f172a; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.card-header h2 { margin: 0; font-size: 16px; color: #0f172a; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2-asymmetric { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) {
    .grid-2, .grid-2-asymmetric { grid-template-columns: 1fr; }
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}
@media (max-width: 980px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 4px;
}
.kpi-card.kpi-cyan { border-left: 4px solid var(--cyan); }
.kpi-card.kpi-purple { border-left: 4px solid var(--purple); }
.kpi-card.kpi-gold { border-left: 4px solid #eab308; background: var(--gold-soft); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 20px; color: #0f172a; }
.kpi-card small { font-size: 11px; color: var(--muted); }

.progress-track { width: 100%; height: 7px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin: 4px 0; }
.progress-fill { height: 100%; border-radius: 99px; }
.progress-fill.cyan { background: var(--cyan); }
.progress-fill.purple { background: var(--purple); }
.progress-fill.red { background: var(--danger); }

/* BADGES & ALERTS */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.badge-rmt { background: #dbeafe; color: #1e40af; }
.badge-rer { background: #d1fae5; color: #065f46; }
.pill-active {
    background: #16a34a; color: #fff;
    font-size: 10px; padding: 2px 6px; border-radius: 4px; margin-left: 6px; font-weight: 700;
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    font-weight: 500;
}
.alert-success { background: var(--success-soft); border-color: #a7f3d0; color: #065f46; }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }

.edu-box {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-left: 4px solid #0284c7;
    border-radius: 8px;
    padding: 12px 14px;
    color: #0c4a6e;
}
.edu-box.edu-green { background: #ecfdf5; border-color: #a7f3d0; border-left-color: #059669; color: #065f46; }
.edu-box ul { margin: 6px 0 0 18px; padding: 0; }
.edu-box p { margin: 4px 0 0; }

/* FORMS & BUTTONS */
.stack-form { display: flex; flex-direction: column; gap: 12px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.inline-grid-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
@media (max-width: 720px) {
    .form-row-2, .form-row-3, .inline-grid-form { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-size: 13.5px;
    font-family: inherit;
    background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.readonly-input { background: #f1f5f9 !important; font-weight: 700; color: #334155; }

.checkbox-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; cursor: pointer; }
.checkbox-row input { width: auto; margin-top: 2px; }

.coef-preview {
    margin-top: 6px; padding: 6px 10px; background: #fff; border: 1px dashed #cbd5e1;
    border-radius: 6px; font-size: 12.5px;
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: 7px; font-size: 13px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; text-decoration: none;
    transition: all 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-lg { padding: 11px 18px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-wa { background: var(--wa); color: #fff; }
.btn-wa:hover { background: #15803d; }
.btn-outline { background: #fff; border-color: #cbd5e1; color: #1e293b; }
.btn-outline:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-danger-outline { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }
.inline-form { display: inline; }

/* TABLES */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table th { background: #f8fafc; font-weight: 700; color: #334155; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
.data-table.compact th, .data-table.compact td { padding: 7px 8px; font-size: 12.5px; }
.data-table tfoot th { background: #0f172a; color: #fff; font-size: 12.5px; }

.text-right { text-align: right !important; }
.text-green { color: var(--success) !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sub-line { font-size: 11.5px; color: var(--muted); }
.actions-cell { white-space: nowrap; }

.row-highlight { background: #eff6ff !important; }
.row-nc { background: #fff7ed; }
.row-subtotal { background: #f8fafc; }
.row-total-due { background: #fef2f2; color: #991b1b; font-size: 14px; }
.row-total-favor { background: #ecfdf5; color: #065f46; font-size: 14px; }

.cell-cyan { background: #cffafe !important; color: #155e75; }
.cell-purple { background: #ede9fe !important; color: #5b21b6; }
.cell-red { background: #fee2e2 !important; color: #991b1b; }
.cell-gold { background: #fef08a !important; color: #713f12; }

.legend-pills { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; font-weight: 600; }
.pill-tramo1 { background: #cffafe; color: #155e75; padding: 3px 8px; border-radius: 6px; }
.pill-tramo2 { background: #ede9fe; color: #5b21b6; padding: 3px 8px; border-radius: 6px; }

/* TABS & MODES */
.mode-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.mode-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.tab-btn {
    padding: 9px 16px; background: #fff; border: 1px solid var(--border);
    border-radius: 8px; font-weight: 600; color: var(--text);
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tag-class { font-size: 11px; background: #f1f5f9; padding: 2px 7px; border-radius: 4px; font-weight: 600; }
.calc-highlight { background: #f0f9ff; border: 1px solid #bae6fd; padding: 12px; border-radius: 8px; }

/* LIQUIDATION */
.month-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.month-pill {
    padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border);
    background: #fff; font-weight: 600; font-size: 12.5px; cursor: pointer;
}
.month-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.liq-summary-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; background: #f8fafc; border-radius: 8px; border: 1px solid var(--border);
}
.liq-result-box {
    background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 10px 12px;
}
.liq-line { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
.final-pay-box {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; border-radius: 8px;
    background: #ecfeff; border: 2px solid #0891b2; color: #164e63; font-size: 15px;
}
.final-pay-box strong { font-size: 20px; }
.final-pay-gold { background: #fefce8; border-color: #eab308; color: #713f12; }
.sticky-save-bar {
    display: flex; justify-content: center; gap: 12px; flex-wrap: wrap;
    padding: 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* GUIA PAGOS VARIOS SUNAT */
.guias-layout { display: grid; grid-template-columns: 1.55fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1060px) { .guias-layout { grid-template-columns: 1fr; } }

.guides-column { display: flex; flex-direction: column; gap: 18px; }
.sunat-guide {
    background: #fff;
    border: 2px solid #111827;
    padding: 12px 14px;
    color: #000;
    font-family: Arial, Helvetica, sans-serif;
    box-shadow: var(--shadow);
}
.sg-top-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 6px; }
.sg-draft-note { border: 1px solid #000; text-align: center; font-size: 10px; font-weight: 700; padding: 2px 8px; margin-bottom: 4px; }
.sg-main-title { font-size: 19px; font-weight: 800; letter-spacing: 0.3px; }
.sg-logo-block { text-align: right; max-width: 185px; }
.sg-sunat-logo { font-size: 24px; font-weight: 900; color: #1e3a8a; letter-spacing: 1px; line-height: 1; }
.sg-sunat-sub { font-size: 7.5px; color: #1e3a8a; line-height: 1.1; }

.sg-section-row { display: grid; grid-template-columns: 1.45fr 1fr; gap: 10px; margin-bottom: 6px; }
.sg-subhead { font-size: 10px; font-weight: 800; text-decoration: underline; margin-bottom: 4px; }
.sg-bar { background: #f1f5f9; border-top: 1px solid #000; border-bottom: 1px solid #000; padding: 2px 6px; text-decoration: none; margin: 6px 0; }
.sg-check-line { font-size: 10.5px; margin-bottom: 2px; display: flex; align-items: center; gap: 5px; }
.sg-check-line small { font-size: 8.5px; }
.sg-box {
    display: inline-flex; align-items: center; justify-content: center;
    width: 14px; height: 14px; border: 1.5px solid #000; font-weight: 800; font-size: 11px; flex-shrink: 0;
}

.sg-taxpayer-box { border: 1.5px solid #000; display: flex; flex-direction: column; justify-content: space-between; text-align: center; }
.sg-taxpayer-hdr { font-size: 9px; font-weight: 800; border-bottom: 1px solid #000; padding: 3px; background: #f8fafc; }
.sg-taxpayer-name { background: #fef08a; padding: 5px; font-weight: 800; font-size: 12px; border-bottom: 1px solid #000; }
.sg-tribute-label { padding: 4px; font-weight: 800; font-size: 13px; color: #dc2626; }

.sg-data-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 10px; align-items: stretch; }
.sg-data-left { display: flex; flex-direction: column; gap: 6px; }
.sg-field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sg-label { font-size: 10.5px; font-weight: 700; min-width: 140px; }
.sg-value-box {
    border: 1.5px solid #000; padding: 4px 10px; font-weight: 800; font-size: 15px;
    text-align: center; background: #fff; min-width: 110px;
}
.sg-value-box.ruc-box { flex: 1; letter-spacing: 1px; }
.sg-period-wrap { display: flex; gap: 6px; }
.sg-period-col { text-align: center; }
.sg-period-hdr { background: #fef08a; border: 1px solid #000; border-bottom: none; font-size: 9.5px; font-weight: 700; padding: 1px 10px; }
.sg-period-col .sg-value-box { min-width: 58px; font-size: 14px; }
.sg-value-box.code-box { min-width: 90px; }
.sg-value-box.amount-box { flex: 1; text-align: right; font-size: 16px; }
.sg-value-box .cents { font-size: 11px; color: #475569; }

.sg-important-box { border: 1.5px solid #000; padding: 6px 8px; font-size: 9px; }
.sg-important-box ol { margin: 4px 0 0 14px; padding: 0; }
.sg-important-box li { margin-bottom: 3px; }

.sg-footer-boxes { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; }
.sg-footer-col { border: 1.5px solid #000; padding: 5px 7px; }
.sg-footer-title { font-size: 9px; font-weight: 800; text-decoration: underline; text-align: center; margin-bottom: 4px; }
.sg-footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 8.5px; font-weight: 700; margin-bottom: 3px; }
.sg-empty-rect { border: 1px solid #000; height: 22px; width: 65px; flex-shrink: 0; }
.sg-empty-rect.wide { width: 130px; }
.sg-footer-col small { font-size: 7.5px; display: block; line-height: 1.15; }

.print-btn-grid { display: flex; flex-direction: column; gap: 8px; }
.wa-box { background: #f0fdf4; border: 1px solid #bbf7d0; padding: 10px; border-radius: 8px; }
.wa-box label { display: block; font-size: 12px; font-weight: 700; color: #166534; margin-bottom: 4px; }
.wa-box textarea { width: 100%; border: 1px solid #86efac; border-radius: 6px; padding: 7px; font-family: inherit; font-size: 12.5px; }

/* LOGIN */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a, #1e3a8a); padding: 20px;
}
.login-card {
    width: 100%; max-width: 400px; background: #fff; border-radius: 14px;
    padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand h1 { margin: 0 0 4px; font-size: 20px; }
.login-brand p { margin: 0; font-size: 12.5px; color: var(--muted); }
.login-hint { margin-top: 16px; text-align: center; color: var(--muted); }

/* HELPERS */
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }
.empty-state { text-align: center; padding: 40px 20px; }

/* PRINT STYLES FOR SUNAT GUIA 1662 */
@media print {
    @page { size: A4 portrait; margin: 8mm; }
    body { background: #fff !important; }
    .no-print { display: none !important; }
    .main-container { max-width: 100%; margin: 0; padding: 0; }
    .guias-layout { display: block; }
    .guides-column { gap: 12px; }
    .sunat-guide { box-shadow: none; break-inside: avoid; page-break-inside: avoid; }

    body[data-print-mode="igv"] .guide-renta-wrap { display: none !important; }
    body[data-print-mode="renta"] .guide-igv-wrap { display: none !important; }
}
