:root {
    --page-bg: #f4f7fb;
    --panel-bg: #ffffff;
    --panel-muted: #f8fafc;
    --text: #172033;
    --text-muted: #667085;
    --border: #dde5ee;
    --border-strong: #cbd7e4;
    --control-border: var(--border);
    --brand: #287fb8;
    --brand-bright: #469eda;
    --brand-soft: #eaf4fb;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --shadow: 0 12px 30px rgba(31, 50, 73, 0.06);
    --icon-white: brightness(0) invert(1);
    --icon-brand: invert(44%) sepia(92%) saturate(496%) hue-rotate(158deg) brightness(88%) contrast(91%);
    /* Shared readable bounds; JavaScript only moves within these tokens when content overflows. */
    --table-compact-body-font-size: 0.78rem;
    --table-compact-heading-font-size: 0.68rem;
    --table-compact-cell-padding-min: 6px;
    --table-compact-cell-block-padding: var(--table-compact-cell-padding-min);
    --table-compact-cell-inline-padding: 24px;
    --plan-expanded-body-font-size: 1.05rem;
    --plan-expanded-heading-font-size: 0.88rem;
    --plan-expanded-cell-block-padding: 0.5em;
    --plan-expanded-cell-inline-padding: 32px;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--page-bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    width: min(100%, 1480px);
    margin: 0 auto;
    padding: 18px 28px 38px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
    padding: 0 2px 14px;
    border-bottom: 1px solid var(--border);
}

.brand-link {
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.brand-link:hover {
    color: inherit;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(1.65rem, 3vw, 2.2rem);
    font-weight: 720;
    letter-spacing: -0.04em;
}

.run-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 62px;
    padding: 3px 12px 3px 16px;
    color: #ffffff;
    background: var(--brand);
    border: 1px solid var(--brand);
    border-radius: 11px;
    box-shadow: 0 7px 16px rgba(40, 127, 184, 0.2);
    font-size: 0.92rem;
    font-weight: 700;
    transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.run-button:hover:not(:disabled) {
    background: #206e9f;
    border-color: #206e9f;
    box-shadow: 0 9px 20px rgba(40, 127, 184, 0.26);
    transform: translateY(-1px);
}

.run-button:focus-visible,
.upload-button:focus-visible,
.info-tip:focus-visible {
    outline: 3px solid rgba(70, 158, 218, 0.3);
    outline-offset: 2px;
}

.run-button:disabled {
    color: var(--brand);
    background: var(--brand-soft);
    border-color: #d4e9f7;
    box-shadow: none;
    cursor: default;
    opacity: 1;
}

#pigBtnImg {
    width: 56px;
    height: 56px;
    filter: var(--icon-white);
}

#pigBtn:disabled > #pigBtnImg {
    filter: var(--icon-brand);
}

.workspace-section,
.data-panel {
    margin-bottom: 14px;
}

.section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 9px;
    padding: 0 2px;
}

.section-heading.compact {
    padding: 0;
}

.section-heading h2 {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 720;
    letter-spacing: -0.02em;
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.editor-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 13px 14px;
}

.panel-heading,
.chart-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.panel-heading {
    min-height: 30px;
    margin-bottom: 7px;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-heading h3,
.chart-heading h3 {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
}

.upload-button {
    padding: 6px 10px;
    color: var(--brand);
    background: var(--brand-soft);
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    transition: background 150ms ease, border-color 150ms ease;
}

.upload-button:hover {
    background: #deeffa;
    border-color: #c8e3f5;
}

.quick-amount-editor {
    margin-bottom: 8px;
    padding: 10px;
    background: var(--panel-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.quick-amount-heading {
    margin-bottom: 8px;
}

.quick-amount-heading h4 {
    margin: 0;
    color: #344054;
    font-size: 0.78rem;
    font-weight: 750;
}

.quick-amount-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
}

.quick-amount-label {
    display: block;
    margin-bottom: 4px;
    color: #526174;
    font-size: 0.75rem;
    font-weight: 750;
}

.quick-amount-control {
    display: flex;
    align-items: stretch;
    min-height: 44px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid var(--control-border);
    border-radius: 8px;
}

.quick-amount-control:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(70, 158, 218, 0.14);
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

.quick-amount-prefix {
    display: grid;
    flex: 0 0 30px;
    place-items: center;
    color: #667085;
    background: #f1f5f9;
    border-right: 1px solid var(--border);
    font-size: 0.78rem;
    font-weight: 700;
}

.quick-amount-input {
    width: 100%;
    min-width: 0;
    padding: 7px 9px;
    color: #26354b;
    background: transparent;
    border: 0;
    outline: 0;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.quick-amount-input:disabled {
    color: #98a2b3;
    cursor: not-allowed;
}

.quick-amount-field.is-invalid .quick-amount-control {
    background: var(--danger-soft);
    border-color: #e78f88;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.08);
}

.quick-amount-error,
.quick-amount-status {
    color: var(--danger);
    font-size: 0.75rem;
    line-height: 1.35;
}

.quick-amount-error {
    display: block;
    margin-top: 4px;
}

.quick-amount-status {
    margin: 7px 0 0;
}

.code-editor.form-control {
    flex: 1 1 auto;
    min-height: 250px;
    padding: 12px 13px;
    color: #26354b;
    background: var(--panel-muted);
    border: 1px solid var(--control-border);
    border-radius: 10px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.78rem;
    line-height: 1.55;
    resize: vertical;
    white-space: pre;
}

.code-editor.form-control:focus {
    color: #26354b;
    background: #ffffff;
    border-color: var(--brand-bright);
    box-shadow: 0 0 0 3px rgba(70, 158, 218, 0.14);
}

.editor-footer {
    display: flex;
    align-items: center;
    min-height: 26px;
    margin-top: 7px;
}

.form-check-input {
    border-color: var(--border-strong);
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.form-check-input:focus {
    border-color: var(--brand-bright);
    box-shadow: 0 0 0 3px rgba(70, 158, 218, 0.16);
}

.form-check-label {
    color: #344054;
    font-size: 0.82rem;
    font-weight: 620;
    cursor: pointer;
}

.info-tip {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    margin-left: 4px;
    color: var(--text-muted);
    background: #eef2f6;
    border-radius: 50%;
    font-size: 0.68rem;
    font-weight: 800;
    cursor: help;
}

.info-tip::after {
    position: absolute;
    z-index: 20;
    right: -8px;
    bottom: calc(100% + 10px);
    width: min(270px, 75vw);
    padding: 9px 11px;
    color: #ffffff;
    background: #253044;
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(23, 32, 51, 0.2);
    content: attr(data-tooltip);
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.45;
    opacity: 0;
    pointer-events: none;
    text-align: left;
    transform: translateY(4px);
    transition: opacity 140ms ease, transform 140ms ease;
}

.info-tip:hover::after,
.info-tip:focus::after {
    opacity: 1;
    transform: translateY(0);
}

.data-panel {
    padding: 11px 16px 7px;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

table.dataTable,
table.table {
    --table-current-body-font-size: var(--table-compact-body-font-size);
    --table-current-heading-font-size: var(--table-compact-heading-font-size);
    --table-current-body-block-padding: var(--table-compact-cell-block-padding);
    --table-current-heading-block-padding: var(--table-compact-cell-block-padding);
    --table-current-inline-padding: var(--table-compact-cell-inline-padding);

    width: 100% !important;
    margin: 0 !important;
    color: #344054;
    border-collapse: separate !important;
    border-spacing: 0;
    font-size: var(--table-current-body-font-size);
}

table.dataTable.no-footer {
    border-bottom: 0;
}

table.dataTable thead th,
table.dataTable thead td {
    padding: var(--table-current-heading-block-padding) var(--table-current-inline-padding);
    color: #526174;
    background: var(--panel-muted);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border) !important;
    font-size: var(--table-current-heading-font-size);
    font-weight: 780;
    letter-spacing: 0.015em;
    text-transform: none;
    white-space: nowrap;
}

table.dataTable thead th:first-child {
    border-left: 1px solid var(--border);
    border-radius: 9px 0 0 9px;
}

table.dataTable thead th:last-child {
    border-right: 1px solid var(--border);
    border-radius: 0 9px 9px 0;
}

table.dataTable tbody td {
    padding: var(--table-current-body-block-padding) var(--table-current-inline-padding);
    border-bottom: 1px solid #edf1f5;
    white-space: nowrap;
}

table.dataTable#plan,
table.dataTable#allEquityInfo {
    font-variant-numeric: tabular-nums;
}

table.dataTable#allEquityInfo {
    width: max-content !important;
    margin-right: auto !important;
    margin-left: auto !important;
}

table.dataTable#plan {
    --table-current-body-font-size: var(--plan-expanded-body-font-size);
    --table-current-heading-font-size: var(--plan-expanded-heading-font-size);
    --table-current-body-block-padding: var(--plan-expanded-cell-block-padding);
    --table-current-heading-block-padding: var(--plan-expanded-cell-block-padding);
    --table-current-inline-padding: var(--plan-expanded-cell-inline-padding);

    width: 100% !important;
}

.data-panel table.dataTable thead > tr > th.sorting,
.data-panel table.dataTable thead > tr > th.sorting_asc,
.data-panel table.dataTable thead > tr > th.sorting_desc,
.data-panel table.dataTable thead > tr > th.sorting_asc_disabled,
.data-panel table.dataTable thead > tr > th.sorting_desc_disabled {
    padding-right: var(--table-current-inline-padding);
}

.data-panel table.dataTable thead > tr > th.sorting::before,
.data-panel table.dataTable thead > tr > th.sorting::after,
.data-panel table.dataTable thead > tr > th.sorting_asc::before,
.data-panel table.dataTable thead > tr > th.sorting_asc::after,
.data-panel table.dataTable thead > tr > th.sorting_desc::before,
.data-panel table.dataTable thead > tr > th.sorting_desc::after,
.data-panel table.dataTable thead > tr > th.sorting_asc_disabled::before,
.data-panel table.dataTable thead > tr > th.sorting_asc_disabled::after,
.data-panel table.dataTable thead > tr > th.sorting_desc_disabled::before,
.data-panel table.dataTable thead > tr > th.sorting_desc_disabled::after {
    display: none;
}

.data-panel table.dataTable thead > tr > th.sorting:hover,
.data-panel table.dataTable thead > tr > th.sorting_asc:hover,
.data-panel table.dataTable thead > tr > th.sorting_desc:hover,
.data-panel table.dataTable thead > tr > th[aria-sort] {
    color: var(--brand);
}

.data-panel table.dataTable .sticky-symbol {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--panel-bg);
    box-shadow: 8px 0 10px -11px rgba(31, 50, 73, 0.8);
}

.data-panel table.dataTable thead .sticky-symbol {
    z-index: 3;
    background: var(--panel-muted);
    border-left: 1px solid var(--border);
    border-radius: 9px 0 0 9px;
}

.data-panel table.dataTable tbody tr:nth-child(even) > .sticky-symbol {
    background: #fbfcfe;
}

.data-panel table.dataTable tbody tr:hover > .sticky-symbol {
    background: #f2f7fb;
}

table.dataTable.stripe > tbody > tr.odd > *,
table.dataTable.display > tbody > tr.odd > * {
    box-shadow: none;
}

table.dataTable tbody tr:nth-child(even) {
    background: #fbfcfe;
}

table.dataTable tbody tr:hover {
    background: #f2f7fb;
}

.dataTables_wrapper .dataTables_info {
    padding: 5px 2px 0 !important;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.dataTables_wrapper > .row {
    margin-right: 0;
    margin-left: 0;
}

.dataTables_wrapper > .row > * {
    padding-right: 0;
    padding-left: 0;
}

.review-notes {
    position: relative;
    z-index: 10;
    margin-left: auto;
}

.review-notes[hidden] {
    display: none;
}

.review-notes > summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 4px 7px 4px 9px;
    color: #4d5f73;
    background: var(--panel-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.review-notes > summary::-webkit-details-marker {
    display: none;
}

.review-notes > summary::after {
    color: #718096;
    content: "⌄";
    font-size: 0.72rem;
    line-height: 1;
    transition: transform 140ms ease;
}

.review-notes[open] > summary {
    color: var(--brand);
    background: var(--brand-soft);
    border-color: #c9e2f2;
}

.review-notes[open] > summary::after {
    transform: rotate(180deg);
}

.review-notes > summary:focus-visible {
    outline: 3px solid rgba(70, 158, 218, 0.24);
    outline-offset: 2px;
}

.review-notes-popover {
    position: absolute;
    z-index: 30;
    top: calc(100% + 8px);
    right: 0;
    width: min(520px, calc(100vw - 56px));
    max-height: 360px;
    padding: 13px;
    overflow-y: auto;
    color: var(--text);
    background: var(--panel-bg);
    border: 1px solid var(--border-strong);
    border-radius: 11px;
    box-shadow: 0 16px 38px rgba(31, 50, 73, 0.16);
}

.review-notes-group + .review-notes-group {
    margin-top: 13px;
    padding-top: 12px;
    border-top: 1px solid #e8edf2;
}

.review-notes-group h3 {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 750;
}

.review-notes-group p {
    margin: 3px 0 9px;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.skipped-rows-list,
.default-mapping-list,
.unused-mapping-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.skipped-rows-list {
    display: grid;
    gap: 6px;
}

.skipped-rows-list li {
    padding: 7px 8px;
    background: #fff8e7;
    border: 1px solid #f0dfb1;
    border-radius: 7px;
}

.skipped-row-symbol {
    display: block;
    margin-bottom: 5px;
    color: #5f4916;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.76rem;
    font-weight: 750;
}

.skipped-row-issues {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.skipped-row-issue {
    padding: 2px 5px;
    color: #765b1a;
    background: rgba(240, 223, 177, 0.5);
    border-radius: 4px;
    font-size: 0.7rem;
}

.default-mapping-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.default-mapping-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #fbf6e9;
    border: 1px solid #f0e2bd;
    border-radius: 7px;
    font-size: 0.76rem;
}

.default-mapping-list code,
.unused-mapping-list code {
    overflow: hidden;
    color: #344054;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.74rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.default-mapping-arrow {
    color: #9a7626;
}

.unused-mapping-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.unused-mapping-list li {
    max-width: 100%;
    padding: 4px 7px;
    background: #f1f4f7;
    border-radius: 6px;
}

.chart-card {
    height: 100%;
    padding: 13px;
}

.chart-heading {
    justify-content: flex-start;
    padding-bottom: 7px;
    border-bottom: 1px solid #edf1f5;
}

.chart-visual {
    display: grid;
    place-items: center;
    min-height: 240px;
    padding-top: 4px;
    text-align: center;
}

.chart-visual svg {
    display: block;
    width: min(100%, 330px);
    height: auto;
    overflow: visible;
}

@media (max-width: 991.98px) {
    .app-shell {
        padding: 18px 20px 36px;
    }

    .app-header {
        margin-bottom: 20px;
    }

    .code-editor.form-control {
        min-height: 250px;
    }
}

@media (max-width: 575.98px) {
    .app-shell {
        padding: 18px 13px 32px;
    }

    .app-header {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 18px;
        padding-bottom: 14px;
    }

    .run-button {
        width: 100%;
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 3px;
    }

    .review-notes {
        margin-left: 0;
    }

    .review-notes-popover {
        right: auto;
        left: 0;
        width: calc(100vw - 54px);
    }

    .default-mapping-list {
        grid-template-columns: 1fr;
    }

    .editor-panel,
    .chart-card {
        padding: 13px;
    }

    .quick-amount-fields {
        grid-template-columns: 1fr;
    }

    .data-panel {
        padding: 15px 14px 11px;
    }

    .code-editor.form-control {
        min-height: 220px;
        font-size: 0.72rem;
    }

    .chart-visual {
        min-height: 260px;
    }

    .info-tip::after {
        right: auto;
        left: 50%;
        transform: translate(-50%, 4px);
    }

    .info-tip:hover::after,
    .info-tip:focus::after {
        transform: translate(-50%, 0);
    }
}
