html,
body {
    width: 100%;
    max-width: 100vw;
    min-height: 100%;
    margin: 0;
    padding: 8px;
    box-sizing: border-box;
    overflow-x: hidden;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, #eef3f8 0%, #e8edf4 100%);
    color: #1f2937;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

.main-content {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
}

.header {
    width: 100%;
    padding: 20px 22px;
    border-bottom: 4px solid #0a4d92;
    background: linear-gradient(90deg, #0b74de, #0957a8);
    color: #fff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
}

.title {
    margin: 0;
    font-size: clamp(2rem, 4.8vw, 3rem);
    font-weight: 700;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: baseline;
}

.slogan {
    font-size: clamp(0.95rem, 2vw, 1.35rem);
    font-style: italic;
}

.hero-subtitle {
    margin: 10px 0 0;
    max-width: 680px;
    font-size: 0.95rem;
    opacity: 0.96;
}

.powered-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}

.powered-container {
    text-align: right;
}

.powered-by {
    margin: 0 0 4px;
    font-size: 0.88rem;
    font-style: italic;
}

.powered-by a {
    color: #ffe066;
    font-weight: 700;
    text-decoration: none;
}

.new-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.workspace {
    width: 100%;
    padding: 14px 0 28px;
}

.page-title {
    margin: 0 0 18px;
    font-size: 1.8rem;
    letter-spacing: 0.02em;
}

.panel {
    background: #fff;
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
    margin-bottom: 18px;
}

.module-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 2px;
    margin: 0 0 14px;
    border-bottom: 1px solid #d7dce4;
}

.module-tab {
    display: inline-block;
    padding: 10px 14px;
    color: #475569;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    border-bottom: 3px solid transparent;
}

.module-tab:hover {
    color: #0b74de;
}

.module-tab.active {
    color: #0b74de;
    border-bottom-color: #0b74de;
}

.section-head {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.section-head-actions {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    flex-shrink: 0;
}

.tutorial-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid #8a1c1c;
    background: linear-gradient(180deg, #ff6b5f 0%, #d63a2d 100%);
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    box-shadow: 0 4px 0 #8f1f18, 0 10px 20px rgba(185, 28, 28, 0.18);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.tutorial-button:hover {
    transform: translateY(1px);
    box-shadow: 0 3px 0 #8f1f18, 0 8px 16px rgba(185, 28, 28, 0.2);
    filter: brightness(1.02);
}

.tutorial-button:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #8f1f18, 0 4px 10px rgba(185, 28, 28, 0.18);
}

.tutorial-button-disabled {
    background: linear-gradient(180deg, #cbd5e1 0%, #94a3b8 100%);
    border-color: #64748b;
    box-shadow: 0 4px 0 #64748b, 0 10px 18px rgba(100, 116, 139, 0.18);
    cursor: not-allowed;
}

.tutorial-button-disabled:hover,
.tutorial-button-disabled:active {
    transform: none;
    filter: none;
    box-shadow: 0 4px 0 #64748b, 0 10px 18px rgba(100, 116, 139, 0.18);
}

.panel h3 {
    margin: 0 0 6px;
    font-size: 1.35rem;
}

.muted {
    margin: 0;
    color: #64748b;
    font-size: 0.93rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field[hidden] {
    display: none !important;
}

.field-span-2 {
    grid-column: span 2;
}

.iva-cv-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.iva-cv-split[hidden] {
    display: none !important;
}

.iva-cv-card {
    padding: 14px;
    border: 1px solid #dbe2ea;
    border-radius: 12px;
    background: #f8fafc;
}

.iva-cv-card-active {
    background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
    border-color: #c9def7;
}

.iva-cv-card h4 {
    margin: 0 0 6px;
    font-size: 1rem;
    color: #1f2937;
}

.iva-cv-card .field {
    margin-top: 10px;
}

.iva-cv-note {
    margin: 0;
    color: #1f2937;
    font-size: 0.93rem;
}

.preview-split {
    margin-top: 6px;
}

.preview-split .iva-cv-card {
    padding: 14px;
}

.preview-split .table-wrap {
    margin-top: 10px;
}

.field span {
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
}

.readonly-info {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #d7dce4;
    border-radius: 10px;
    background: #f8fafc;
    font-size: 0.95rem;
    color: #334155;
    display: flex;
    align-items: center;
}

input {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid #d7dce4;
    border-radius: 10px;
    background: #fff;
    font-size: 0.95rem;
    color: #1f2937;
}

input:focus {
    outline: none;
    border-color: #0b74de;
    box-shadow: 0 0 0 3px rgba(11, 116, 222, 0.14);
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.btn-wrap {
    display: inline-flex;
}

.dynamic-block {
    margin-top: 16px;
    padding: 14px;
    border: 1px solid #dbe2ea;
    border-radius: 12px;
    background: #f8fafc;
    display: inline-block;
    min-width: 0;
    max-width: 100%;
}

.dynamic-block:has(input[data-porcentaje="compras"]):has(input[data-porcentaje="ventas"]) {
    display: block;
    width: 100%;
}

.dynamic-block:has(input[data-porcentaje="compras"]):has(input[data-porcentaje="ventas"]) .saldo-grid {
    width: 100%;
}

.dynamic-block:has(input[data-porcentaje="compras"]):has(input[data-porcentaje="ventas"]) .saldo-inline {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
}

.dynamic-block h4 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.saldo-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    align-items: flex-start;
}

.saldo-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1 1 240px;
    min-width: 240px;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid #dbe2ea;
    border-radius: 10px;
    background: #fff;
}

.saldo-inline span {
    font-size: 0.92rem;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
}

.saldo-inline input {
    width: 110px;
    padding: 7px 10px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.saldo-inline input::-webkit-outer-spin-button,
.saldo-inline input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

button {
    border: none;
    border-radius: 10px;
    padding: 11px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(90deg, #0b74de, #0957a8);
    box-shadow: 0 6px 14px rgba(11, 116, 222, 0.16);
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 10px 18px rgba(11, 116, 222, 0.22);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    box-shadow: none;
}

.blocked-action-hint {
    position: fixed;
    z-index: 9999;
    max-width: 360px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(24, 24, 27, 0.96);
    color: #f8fafc;
    font-size: 0.87rem;
    line-height: 1.35;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}

.blocked-action-hint.visible {
    opacity: 1;
    transform: translateY(0);
}

button.secondary {
    background: linear-gradient(90deg, #6b7280, #4b5563);
    box-shadow: 0 6px 14px rgba(75, 85, 99, 0.18);
}

button.success {
    background: linear-gradient(90deg, #28a745, #218838);
    box-shadow: 0 6px 14px rgba(33, 136, 56, 0.18);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid #dbe2ea;
    border-radius: 12px;
    background: #fff;
}

.compact-height {
    max-height: 360px;
    overflow: auto;
}

table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid #edf1f5;
    text-align: left;
    vertical-align: top;
    font-size: 0.92rem;
}

thead th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    z-index: 1;
}

th.right,
td.right {
    text-align: right;
}

.report-shell {
    min-height: 160px;
    max-height: 720px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.empty-state {
    padding: 26px 18px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    text-align: center;
    color: #64748b;
    background: #f8fafc;
}

.report {
    border: 1px solid #dbe2ea;
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
}

.report-header {
    padding: 18px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.report-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.report-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    color: #475569;
    font-size: 0.92rem;
}

.account-band {
    padding: 12px 18px;
    background: #ecf5ff;
    color: #0a4d92;
    font-weight: 700;
    border-bottom: 1px solid #d4e6fb;
}

.initial-row {
    background: #f8fafc;
    font-weight: 700;
}

.final-row {
    background: #e8f7ee;
    font-weight: 700;
}

@media (max-width: 760px) {
    .form-grid,
    .report-meta,
    .saldo-grid {
        grid-template-columns: 1fr;
    }

    .iva-cv-split {
        grid-template-columns: 1fr;
    }

    .field-span-2 {
        grid-column: span 1;
    }
}

@media (max-width: 640px) {
    html,
    body {
        padding: 4px;
    }

    .header,
    .panel {
        padding: 16px;
    }

    .action-row,
    .section-head {
        flex-direction: column;
        align-items: stretch;
    }
}

@media print {
    @page {
        size: landscape;
        margin: 10mm;
    }

    .header,
    .panel:first-of-type,
    .panel:nth-of-type(2) {
        display: none !important;
    }

    html,
    body,
    .main-content,
    .workspace {
        background: #fff;
        padding: 0;
        max-width: 100%;
    }

    .panel:last-of-type {
        box-shadow: none;
        margin: 0;
        padding: 0;
    }

    .report,
    .table-wrap,
    table {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        border: none;
        box-shadow: none;
        table-layout: fixed;
    }

    th,
    td {
        font-size: 9pt;
        padding: 3px 5px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip;
    }

    th:nth-child(1),
    td:nth-child(1) { width: 19%; }
    th:nth-child(2),
    td:nth-child(2) { width: 13%; }
    th:nth-child(3),
    td:nth-child(3) { width: 7%; }
    th:nth-child(4),
    td:nth-child(4) { width: 8%; }
    th:nth-child(5),
    td:nth-child(5) { width: 9%; }
    th:nth-child(6),
    td:nth-child(6) { width: 19%; }
    th:nth-child(7),
    td:nth-child(7) { width: 8%; }
    th:nth-child(8),
    td:nth-child(8) { width: 8%; }
    th:nth-child(9),
    td:nth-child(9) { width: 9%; }

    .report-meta {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .account-band,
    .report-header {
        padding-left: 0;
        padding-right: 0;
    }
}
