.apu-editor-shell {
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto 48px;
    color: #1f2937;
}

.apu-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 0 16px;
}

.apu-title-block span,
.apu-panel-heading span,
.apu-section-title span,
.apu-kpi-strip span,
.apu-flow-guide span,
.apu-selected-rubro span,
.apu-percent-base span,
.apu-effective-summary span,
.apu-final-total span {
    display: block;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.apu-title-block h2 {
    margin: 4px 0 0;
    color: #0f172a;
    font-size: clamp(1.35rem, 2vw, 2rem);
    line-height: 1.15;
}

.apu-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.apu-action-button,
.apu-icon-action {
    flex: 0 0 auto;
}

.apu-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.apu-kpi-strip > div,
.apu-work-panel,
.apu-tree-panel,
.apu-selected-rubro {
    background: #fff;
    border: 1px solid #dbe3ea;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.apu-kpi-strip > div {
    min-height: 76px;
    padding: 14px;
}

.apu-kpi-strip strong {
    display: block;
    margin-top: 6px;
    color: #0f172a;
    font-size: 1.08rem;
    line-height: 1.2;
    min-width: 0;
    overflow-wrap: anywhere;
}

.apu-flow-guide {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.apu-flow-guide > div {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 10px;
    align-items: center;
    min-width: 0;
    padding: 12px;
    border: 1px solid #dbe3ea;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.apu-flow-guide span {
    grid-row: span 2;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #eef2ff;
    color: #1d4ed8;
}

.apu-flow-guide strong {
    min-width: 0;
    color: #0f172a;
    font-size: 0.88rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.apu-flow-guide small {
    min-width: 0;
    color: #64748b;
    font-size: 0.76rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.apu-flow-guide > div.active {
    border-color: #99f6e4;
    background: #f0fdfa;
}

.apu-flow-guide > div.active span {
    background: #ccfbf1;
    color: #0f766e;
}

.apu-editor-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
    gap: 14px;
}

.apu-tree-panel {
    position: sticky;
    top: 88px;
    max-height: calc(100vh - 112px);
    overflow: auto;
    padding: 12px;
}

.apu-panel-heading,
.apu-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.apu-tree-chapter {
    border-top: 1px solid #e2e8f0;
}

.apu-tree-chapter:first-of-type {
    border-top: 0;
}

.apu-tree-chapter-button,
.apu-tree-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
}

.apu-tree-chapter-button {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto 22px;
    gap: 8px;
    align-items: center;
    padding: 12px 4px;
}

.apu-chapter-code {
    display: inline-flex;
    min-width: 34px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #ecfeff;
    color: #0e7490;
    font-size: 0.72rem;
    font-weight: 900;
}

.apu-chapter-name {
    min-width: 0;
    overflow: hidden;
    color: #0f172a;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.apu-chapter-toggle {
    color: #64748b;
    font-weight: 900;
    text-align: center;
}

.apu-tree-items {
    display: grid;
    gap: 6px;
    padding: 0 0 10px 18px;
}

.apu-tree-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    min-height: 58px;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.apu-tree-item:hover,
.apu-tree-item.active {
    border-color: #0f766e;
    background: #f0fdfa;
}

.apu-tree-item-main {
    min-width: 0;
}

.apu-tree-item-main strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.apu-tree-item-main small {
    display: block;
    margin-top: 3px;
    color: #64748b;
}

.apu-tree-item-total {
    color: #14532d;
    font-size: 0.8rem;
    font-weight: 900;
}

.apu-detail-column {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.apu-selected-rubro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
}

.apu-selected-rubro h3 {
    margin: 4px 0 0;
    color: #0f172a;
    font-size: 1.08rem;
    line-height: 1.25;
}

.apu-selected-rubro > strong {
    display: inline-flex;
    min-width: 52px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #f8fafc;
    color: #334155;
    border: 1px solid #e2e8f0;
}

.apu-work-panel {
    padding: 16px;
    min-width: 0;
    overflow: hidden;
}

.apu-percentages-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

.apu-percentages-panel .apu-section-title,
.apu-percentages-panel .apu-section-title > div {
    min-width: 0;
}

.apu-percentages-panel .apu-section-title {
    margin-bottom: 0;
}

.apu-percentages-panel .apu-section-title strong,
.apu-percent-base strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.apu-empty-state {
    display: grid;
    gap: 6px;
    padding: 18px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    color: #64748b;
}

.apu-empty-state strong {
    color: #334155;
}

.apu-empty-action {
    justify-self: start;
    margin-top: 6px;
}

.apu-measurement-table-wrap {
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.apu-measurement-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.apu-measurement-table th,
.apu-measurement-table td {
    padding: 8px;
    border-bottom: 1px solid #e2e8f0;
}

.apu-measurement-table th {
    background: #f8fafc;
    color: #475569;
    font-size: 0.72rem;
    text-transform: uppercase;
}

.apu-line-index {
    width: 42px;
    color: #64748b;
    text-align: center;
}

.apu-cell-input,
.apu-field-input,
.apu-percent-name,
.apu-percent-rate {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #0f172a;
    padding: 8px;
    font: inherit;
}

.apu-cell-input[type="number"],
.apu-field-input[type="number"],
.apu-percent-rate {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: #0f172a;
    -webkit-text-fill-color: #0f172a;
    appearance: textfield;
}

.apu-cell-input[type="number"]::-webkit-outer-spin-button,
.apu-cell-input[type="number"]::-webkit-inner-spin-button,
.apu-field-input[type="number"]::-webkit-outer-spin-button,
.apu-field-input[type="number"]::-webkit-inner-spin-button,
.apu-percent-rate::-webkit-outer-spin-button,
.apu-percent-rate::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.apu-override-placeholder {
    display: flex;
    min-height: 38px;
    align-items: center;
    padding: 8px 10px;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    color: #64748b;
    font-size: 0.82rem;
    font-weight: 700;
}

.apu-cell-input:focus,
.apu-field-input:focus,
.apu-percent-name:focus,
.apu-percent-rate:focus {
    border-color: #0f766e;
    outline: 2px solid rgba(15, 118, 110, 0.16);
}

.apu-description-input {
    min-width: 220px;
}

.apu-sign-select {
    min-width: 48px;
}

.apu-partial-cell {
    color: #14532d;
    font-weight: 900;
}

.apu-row-action-cell {
    width: 44px;
    text-align: center;
}

.apu-icon-action {
    font-size: 0.92rem;
}

.apu-override-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.apu-override-block {
    display: grid;
    gap: 10px;
    min-width: 280px;
    padding: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fbfdff;
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.apu-override-block--active {
    border-color: rgba(15, 118, 110, 0.42);
    background: linear-gradient(180deg, #f6fffd 0%, #ecfdf5 100%);
    box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.08);
}

.apu-override-row,
.apu-effective-summary,
.apu-percent-base,
.apu-final-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.apu-toggle-line {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #334155;
    font-size: 0.88rem;
    font-weight: 700;
}

.apu-toggle-line input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    accent-color: #0f766e;
}

.apu-toggle-line input[type="checkbox"]:checked {
    filter: drop-shadow(0 0 6px rgba(15, 118, 110, 0.22));
}

.apu-override-input {
    display: block;
    width: 100%;
    min-width: 100%;
    max-width: none;
    min-height: 48px;
    padding: 12px 14px;
    border-width: 2px;
    border-color: #94a3b8;
    background: #ffffff;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.2;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.apu-override-input::placeholder {
    color: #94a3b8;
    font-weight: 600;
}

.apu-override-input:focus {
    border-color: #0f766e;
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

.apu-composition-toggle,
.apu-composition-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #0f172a;
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.apu-composition-toggle:hover,
.apu-composition-section-head:hover {
    border-color: rgba(15, 118, 110, 0.42);
    background: #f8fffd;
}

.apu-composition-toggle:focus-visible,
.apu-composition-section-head:focus-visible {
    outline: none;
    border-color: #0f766e;
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

.apu-composition-toggle--inline {
    margin-top: -2px;
}

.apu-composition-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.apu-composition-chip {
    display: grid;
    gap: 3px;
    padding: 10px 12px;
    border: 1px solid #dbe2ea;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
}

.apu-composition-chip span {
    color: #64748b;
    font-size: 0.77rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.apu-composition-chip strong {
    color: #0f172a;
    font-size: 0.98rem;
}

.apu-composition-panel {
    display: grid;
    gap: 10px;
    padding: 12px;
    border-radius: 10px;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #dbe2ea;
}

.apu-composition-note {
    margin: 0;
    color: #475569;
    font-size: 0.82rem;
    line-height: 1.45;
}

.apu-composition-section {
    display: grid;
    gap: 8px;
}

.apu-composition-list {
    display: grid;
    gap: 8px;
}

.apu-composition-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e2e8f0;
}

.apu-composition-main {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.apu-composition-main strong,
.apu-composition-main small {
    min-width: 0;
}

.apu-composition-main small {
    color: #64748b;
    font-size: 0.8rem;
}

.apu-effective-summary {
    flex-wrap: wrap;
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    background: #f0fdfa;
    color: #134e4a;
}

.apu-final-total {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    justify-content: stretch;
    gap: 4px;
    width: 100%;
    box-sizing: border-box;
    margin-top: 0;
    padding: 14px;
    border-radius: 8px;
    background: #f0fdfa;
    color: #134e4a;
    overflow: hidden;
}

.apu-effective-summary > *,
.apu-percent-base > *,
.apu-final-total > * {
    min-width: 0;
}

.apu-percent-base {
    flex-wrap: wrap;
    padding: 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.apu-panel-hint {
    margin: -4px 0 12px;
    color: #64748b;
    font-size: 0.86rem;
    line-height: 1.4;
}

.apu-percent-list {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
    margin-top: 0;
}

.apu-percent-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    min-width: 0;
    overflow: hidden;
}

.apu-percent-active {
    width: 100%;
    min-width: 0;
}

.apu-toggle-line.apu-percent-active {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: center;
}

.apu-percent-controls {
    display: grid;
    grid-template-columns: minmax(96px, 1fr) 74px 16px minmax(92px, 118px) 34px;
    gap: 8px;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.apu-percent-controls > * {
    min-width: 0;
}

.apu-percent-controls input[type="range"] {
    width: 100%;
    accent-color: #0f766e;
}

.apu-percent-controls span {
    text-align: center;
    white-space: nowrap;
}

.apu-final-total strong {
    width: 100%;
    max-width: 100%;
    color: #0f172a;
    font-size: clamp(1.05rem, 2vw, 1.28rem);
    line-height: 1.1;
    text-align: left;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.apu-percent-amount {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    color: #0f172a;
    font-size: 0.82rem;
    line-height: 1.15;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: right;
}

.apu-empty-detail {
    min-height: 260px;
    align-content: center;
    justify-items: start;
}

@media (max-width: 1100px) {
    .apu-editor-grid {
        grid-template-columns: 1fr;
    }

    .apu-tree-panel {
        position: static;
        max-height: none;
    }
}

@media (max-width: 760px) {
    .apu-editor-shell {
        width: min(100% - 18px, 720px);
    }

    .apu-editor-header,
    .apu-selected-rubro,
    .apu-effective-summary {
        align-items: stretch;
        flex-direction: column;
    }

    .apu-header-actions {
        width: 100%;
    }

    .apu-header-actions > button,
    .apu-action-button {
        width: 100%;
    }

    .apu-kpi-strip,
    .apu-flow-guide,
    .apu-override-grid,
    .apu-percent-row,
    .apu-composition-summary {
        grid-template-columns: 1fr;
    }

    .apu-override-block {
        min-width: 0;
    }

    .apu-tree-chapter-button {
        grid-template-columns: 38px minmax(0, 1fr) 22px;
    }

    .apu-tree-chapter-button strong {
        grid-column: 2 / 3;
        font-size: 0.8rem;
    }

    .apu-percent-controls {
        grid-template-columns: minmax(0, 1fr) 72px 18px 34px;
    }

    .apu-percent-controls strong {
        grid-column: 1 / -1;
        text-align: left;
    }

    .apu-percent-controls .apu-icon-action {
        grid-column: 4;
        grid-row: 1;
        justify-self: end;
    }

    .apu-final-total strong {
        text-align: left;
    }
}
