/* Shared calculator controls and saved-project picker. */
:root {
    --sa-brand-500: #4fcccd;
    --sa-brand-600: #47b8b8;
    --sa-brand-700: #378e8f;
    --sa-brand-800: #2d7172;
}

.sa-button {
    display: inline-flex;
    height: 42px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    transition: 160ms ease;
}

.sa-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.sa-button--primary {
    color: #fff;
    background: var(--sa-brand-700);
    box-shadow: 0 5px 12px rgba(55, 142, 143, 0.2);
}

.sa-button--primary:hover {
    color: #fff;
    background: var(--sa-brand-800);
    transform: translateY(-1px);
    box-shadow: 0 7px 16px rgba(55, 142, 143, 0.24);
}

.sa-button--primary:active {
    transform: translateY(0);
}

.sa-button--full {
    width: 100%;
}

.sa-icon-button {
    display: inline-flex;
    flex: none;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #d7e0e8;
    border-radius: 8px;
    color: #5f6c7c;
    background: #fff;
    transition: 140ms ease;
}

.sa-icon-button:hover:not(:disabled) {
    border-color: #b9c7d4;
    color: #27364a;
    background: #f8fafc;
}

.sa-icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.36;
}

.sa-icon-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.sa-button--secondary {
    border-color: #d4e1e8;
    color: #3e6570;
    background: #f7fbfc;
}

.sa-section-label,
.sa-section-label-row .sa-section-label {
    margin: 0 0 8px;
    color: #8a95a5;
    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.sa-dialog-backdrop {
    position: fixed;
    z-index: 80;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.48);
    backdrop-filter: blur(4px);
}

.sa-dialog-backdrop[hidden] {
    display: none;
}

.sa-dialog {
    display: grid;
    width: min(760px, 100%);
    max-height: min(640px, calc(100dvh - var(--sa-site-header-height, 81px) - 32px));
    /* max-content keeps header/filters from shrinking under overflow:hidden */
    grid-template-rows: max-content max-content minmax(180px, 1fr) max-content;
    overflow: hidden;
    border: 1px solid #dce4eb;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 28px 70px rgba(15, 23, 42, 0.24);
}

.sa-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 18px;
    border-bottom: 1px solid #e7ecf0;
    min-height: max-content;
}

.sa-dialog__header .sa-section-label {
    margin-bottom: 2px;
    color: var(--sa-brand-700);
}

.sa-dialog__header h2 {
    margin: 0;
    color: #263448;
    font-size: 18px;
}

.sa-dialog button,
.sa-dialog input,
.sa-dialog select {
    font-family: inherit;
}

.sa-field {
    display: grid;
    min-width: 0;
    gap: 5px;
}

.sa-field--full {
    grid-column: 1 / -1;
}

.sa-field label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 7px;
    color: #667386;
    font-size: 9px;
    font-weight: 750;
}

.sa-field label span {
    color: #9aa5b3;
    font-size: 8px;
    font-weight: 650;
}

.sa-field input,
.sa-field select {
    width: 100%;
    height: 37px;
    min-width: 0;
    padding: 0 9px;
    border: 1px solid #d9e1e8;
    border-radius: 7px;
    outline: none;
    color: #27364a;
    background: #fff;
    font-size: 11px;
    font-weight: 700;
    transition: 120ms ease;
}

.sa-field input:hover,
.sa-field select:hover {
    border-color: #becbd6;
}

.sa-field input:focus,
.sa-field select:focus {
    border-color: var(--sa-brand-500);
    box-shadow: 0 0 0 3px rgba(79, 204, 205, 0.15);
}

.sa-field input[readonly] {
    color: #8a96a5;
    background: #f8fafc;
}

/* Give the dialog a viewport-sized column before sizing its rows. */
.sa-project-backdrop {
    grid-template-columns: minmax(0, 1fr);
}

.sa-project-dialog {
    box-sizing: border-box;
    width: min(780px, 100%);
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    font-family: "Open Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

.sa-project-open {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sa-project-save {
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr);
    gap: 4px 18px;
    align-items: end;
    padding: 14px 18px;
    border-bottom: 1px solid #e7edf1;
    background: linear-gradient(90deg, #f3fbfb 0%, #f9fcfc 100%);
}

.sa-project-save[hidden] {
    display: none;
}

.sa-project-save .sa-field {
    grid-row: 1 / span 2;
}

.sa-project-save .sa-field > span,
.sa-project-search .sa-field > span {
    color: #667386;
    font-size: 9px;
    font-weight: 800;
}

.sa-project-save > p {
    grid-column: 2;
    margin: 0;
    color: #738195;
    font-size: 9px;
    line-height: 1.45;
}

.sa-project-save__warning {
    color: #a45d0a !important;
    font-weight: 750;
}

.sa-project-save__limit {
    grid-column: 1 / -1;
    padding: 12px;
    margin-top: 8px;
    border: 1px solid #ebc78e;
    border-radius: 8px;
    background: #fff8eb;
    color: #714510;
    font-size: 12px;
    line-height: 1.5;
}

.sa-project-save__limit[hidden] {
    display: none;
}

.sa-project-save__limit p {
    margin: 4px 0 8px;
}

.sa-project-save__limit > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
}

.sa-project-save__limit a {
    color: inherit;
    font-weight: 700;
    text-decoration: underline;
}

.sa-project-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 170px 38px;
    align-items: end;
    gap: 10px;
    padding: 12px 18px 10px;
    background: #fbfcfd;
}

.sa-project-sort {
    width: 170px;
}

.sa-project-new-folder {
    height: 36px;
    padding-inline: 13px;
    white-space: nowrap;
}

.sa-project-new-folder:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.sa-project-breadcrumb {
    display: flex;
    min-height: 32px;
    align-items: center;
    gap: 7px;
    padding: 4px 18px 8px;
    color: #7c8999;
    background: #fbfcfd;
    font-size: 9px;
}

.sa-project-breadcrumb button {
    border: 0;
    padding: 2px 0;
    color: var(--sa-brand-800);
    background: transparent;
    font: inherit;
    font-weight: 800;
}

.sa-project-breadcrumb button[aria-current="page"] {
    color: #526175;
    cursor: default;
}

.sa-project-breadcrumb strong {
    overflow: hidden;
    color: #526175;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-project-list-shell {
    min-height: 0;
    flex: 1;
    margin: 0 18px 14px;
    overflow: hidden;
    border: 1px solid #dfe7ed;
    border-radius: 11px;
    background: #fff;
}

.sa-project-list__header {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 116px 108px 74px;
    align-items: center;
    gap: 11px;
    min-height: 31px;
    padding: 0 12px;
    border-bottom: 1px solid #dfe7ed;
    color: #8290a1;
    background: #f7f9fb;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sa-project-list {
    min-height: 258px;
    max-height: min(430px, 52vh);
    overflow-y: auto;
}

.sa-project-list > p {
    display: grid;
    min-height: 258px;
    place-items: center;
    margin: 0;
    padding: 24px;
    color: #8390a1;
    font-size: 11px;
    text-align: center;
}

.sa-project-row {
    position: relative;
    display: grid;
    width: 100%;
    min-height: 57px;
    grid-template-columns: 36px minmax(0, 1fr) 116px 108px 74px;
    align-items: center;
    gap: 11px;
    padding: 8px 12px;
    border: 0;
    border-bottom: 1px solid #edf1f4;
    color: #657286;
    background: transparent;
    text-align: left;
    transition: background 120ms ease, box-shadow 120ms ease;
}

.sa-project-row:last-child {
    border-bottom: 0;
}

.sa-project-row:hover,
.sa-project-row.is-selected {
    background: #f3fbfb;
}

.sa-project-row:focus-visible {
    z-index: 1;
    outline: 2px solid rgba(79, 204, 205, 0.55);
    outline-offset: -2px;
}

.sa-project-row.is-selected {
    box-shadow: inset 3px 0 0 var(--sa-brand-600);
}

.sa-project-row__icon {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 7px;
    color: var(--sa-brand-800);
    background: #dff6f6;
}

.sa-project-row__icon svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.sa-project-row--folder .sa-project-row__icon {
    color: #9a6700;
    background: #fff3c4;
}

.sa-project-row__name {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.sa-project-row__name strong {
    overflow: hidden;
    color: #263448;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-project-row__name small,
.sa-project-row__details,
.sa-project-row__date {
    color: #8a96a6;
    font-size: 8px;
}

.sa-project-row__details,
.sa-project-row__date {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-project-row__name input {
    width: 100%;
    height: 32px;
    min-width: 0;
    padding: 0 8px;
    border: 1px solid var(--sa-brand-500);
    border-radius: 7px;
    outline: 0;
    color: #263448;
    background: #fff;
    font-size: 11px;
    font-weight: 750;
    box-shadow: 0 0 0 3px rgba(79, 204, 205, 0.13);
}

.sa-project-row__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.sa-project-row__open {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #778597;
    background: transparent;
}

.sa-project-row__open:hover,
.sa-project-row__open:focus-visible {
    border-color: #c9e4e5;
    color: var(--sa-brand-800);
    background: #fff;
}

.sa-project-row__open svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.sa-project-row__menu {
    position: relative;
}

.sa-project-row__menu summary {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #7f8b9b;
    cursor: pointer;
    list-style: none;
}

.sa-project-row__menu summary::-webkit-details-marker {
    display: none;
}

.sa-project-row__menu summary:hover,
.sa-project-row__menu summary:focus-visible,
.sa-project-row__menu[open] summary {
    border-color: #d8e2e9;
    color: #405166;
    background: #fff;
}

.sa-project-row__menu summary svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.sa-project-row__menu-panel {
    position: fixed;
    z-index: 95;
    display: grid;
    width: 126px;
    padding: 5px;
    border: 1px solid #dce4eb;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
}

.sa-project-row__menu-panel button {
    min-height: 31px;
    padding: 0 9px;
    border: 0;
    border-radius: 6px;
    color: #435268;
    background: transparent;
    text-align: left;
    font-size: 9px;
    font-weight: 750;
}

.sa-project-row__menu-panel button:hover,
.sa-project-row__menu-panel button:focus-visible {
    background: #f2f6f8;
}

.sa-project-row__menu-panel button.is-danger {
    color: #b43b45;
}

.sa-project-row__menu-spacer {
    width: 30px;
}

.sa-project-row__editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
}

.sa-project-row__editor-actions button {
    min-height: 28px;
    padding: 0 7px;
    border: 1px solid #d5e0e7;
    border-radius: 6px;
    color: #526175;
    background: #fff;
    font-size: 8px;
    font-weight: 800;
}

.sa-project-row__editor-actions button:first-child {
    border-color: var(--sa-brand-600);
    color: #fff;
    background: var(--sa-brand-700);
}

.sa-project-row--confirm {
    grid-template-columns: 36px minmax(0, 1fr) auto;
}

.sa-project-row--confirm .sa-project-row__name small {
    color: #526175;
}

.sa-project-row--confirm .sa-project-row__name strong {
    overflow-wrap: anywhere;
    white-space: normal;
}

.sa-project-row--confirm .sa-project-row__editor-actions .is-danger {
    border-color: #b43b45;
    background: #b43b45;
}

.sa-project-row--confirm .sa-project-row__editor-actions button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.sa-project-manager__footer {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 64px;
    padding: 10px 18px;
    border-top: 1px solid #e7ecf0;
    background: #fbfcfd;
}

.sa-project-manager__footer .sa-button {
    height: 36px;
    padding-inline: 14px;
    font-size: 10px;
}

.sa-project-manager__footer .sa-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
    box-shadow: none;
}

.sa-project-manager__status {
    min-width: 0;
    flex: 1;
    color: #66808a;
    font-size: 9px;
    overflow-wrap: anywhere;
}

.sa-project-manager__status.is-error {
    color: #b43b45;
}

@media (max-width: 900px) {
    .sa-project-dialog {
        max-height: calc(100vh - 16px);
    }

    .sa-project-save {
        grid-template-columns: minmax(0, 1fr);
        padding: 12px;
    }

    .sa-project-save .sa-field,
    .sa-project-save > p {
        grid-column: 1;
        grid-row: auto;
    }

    .sa-project-search {
        grid-template-columns: minmax(0, 1fr) 38px;
        padding: 10px 12px 8px;
    }

    .sa-project-search .sa-field:first-child {
        grid-column: 1 / -1;
    }

    .sa-project-sort {
        width: auto;
    }

    .sa-project-breadcrumb {
        padding-inline: 12px;
    }

    .sa-project-list-shell {
        margin: 0 12px 10px;
    }

    .sa-project-list__header {
        display: none;
    }

    .sa-project-row {
        grid-template-columns: 32px minmax(0, 1fr) auto;
        gap: 9px;
        padding-inline: 10px;
    }

    .sa-project-row--confirm .sa-project-row__name,
    .sa-project-row--confirm .sa-project-row__editor-actions {
        grid-column: 2 / -1;
    }

    .sa-project-row__details,
    .sa-project-row__date {
        display: none;
    }

    .sa-project-manager__footer {
        flex-wrap: wrap;
        min-height: 0;
        padding: 10px 12px;
    }

    .sa-project-manager__status {
        order: -1;
        flex-basis: 100%;
        min-height: 12px;
    }
}
