/* Responsive repair layer. Preserve calendar geometry and all print layouts. */
@media screen {
    .balance-simple-item { padding: 16px 0; border-bottom: 1px solid #353940; }
    .balance-simple-item:last-child { border-bottom: 0; padding-bottom: 0; }
    .balance-simple-item p { margin: 8px 0; }
    .balance-simple-numbers { display: flex; flex-wrap: wrap; gap: 16px 40px; margin: 16px 0; }
    .balance-simple-numbers > div { display: grid; gap: 5px; }
    .balance-simple-numbers span { color: #afb5bf; font-size: 13px; }
    .balance-popup summary { cursor: pointer; color: #e3c257; padding: 8px 0; }
    dialog.balance-popup { width: min(960px,calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); box-sizing: border-box; padding: 0; border: 1px solid #75632b; border-radius: 18px; background: #111316; color: #eef0f3; box-shadow: 0 24px 90px #000b; overflow: hidden; }
    dialog.balance-popup[open] { display: flex; flex-direction: column; }
    dialog.balance-popup::backdrop { background: #000b; backdrop-filter: blur(3px); }
    .balance-popup .balance-inline-head { padding: 16px 20px; margin: 0; border-bottom: 1px solid #39372b; flex-shrink: 0; }
    .balance-popup .balance-popup-close { width: 40px; height: 40px; padding: 0; font-size: 26px; line-height: 1; }
    .balance-popup .balance-inline-body { width: 100%; max-width: none; margin: 0; padding: 20px; overflow-y: auto; overscroll-behavior: contain; min-height: 0; box-sizing: border-box; }
    @media (max-width: 760px) {
        dialog.balance-popup { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); border-radius: 14px; }
        .balance-popup .balance-inline-head { padding: 12px; }
        .balance-popup .balance-inline-body { padding: 12px; }
    }
    .container, .panel, .page-head > div, .panel-head > div,
    .form-grid > *, .extension-form > *, .employee-workspace > * { min-width: 0; }
    .container :is(h1,h2,h3) { line-height: 1.22; overflow-wrap: break-word; }
    .container :is(p,.muted,.field-message) { line-height: 1.45; }
    .container p { overflow-wrap: anywhere; }
    .container label { min-width: 0; line-height: 1.35; }
    .container :is(input:not([type=checkbox]):not([type=radio]),select,textarea) { max-width: 100%; min-width: 0; }
    .container :is(.actions,.form-actions,.downloads,.quick-values) { flex-wrap: wrap; gap: 8px; }
    .container :is(.button,button) { line-height: 1.25; }
    .container :is(.badge,.days-box,.money,.cp-totals,.balance-overview) { font-variant-numeric: tabular-nums; }
    .table-wrap { max-width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; }
    .container table:not(.monthly-report-table):not(.investor-month-table):not(.organization-investor-card table) :is(th,td) { vertical-align: top; }
    .container .clients-table { width: 100% !important; table-layout: fixed; min-width: 0 !important; }
    .container .clients-table :is(th,td) { min-width: 0 !important; white-space: normal; overflow-wrap: anywhere; padding: 12px 10px; }
    .clients-table :is(th,td):nth-child(1) { width: 26% !important; }
    .clients-table :is(th,td):nth-child(2) { width: 19% !important; }
    .clients-table :is(th,td):nth-child(3) { width: 15% !important; }
    .clients-table :is(th,td):nth-child(4) { width: 18% !important; }
    .clients-table :is(th,td):nth-child(5) { width: 22% !important; }
    .clients-table :is(.actions,.row-actions) { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
    .clients-table .badge { white-space: normal; max-width: 100%; line-height: 1.35; }
    .clients-table .phone-nowrap { font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
    .investor-month-table .investor-car-col { overflow-wrap: anywhere; }
    .extra-services-summary { min-width: 0; flex-wrap: wrap; gap: 12px; }
    .extra-services-summary > div { min-width: 0; }
    .extra-services-summary h2 { font-size: clamp(16px,1.5vw,21px); white-space: normal; overflow-wrap: normal; }
    .extra-services-total { flex-shrink: 0; }
    .client-balance-link { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 5px; text-underline-offset: 4px; border-radius: 5px; }
    .client-balance-link::after { content: '⌄'; font-size: 13px; color: #e3c257; }
    .client-balance-link { padding: 4px 7px; transition: background .16s, box-shadow .16s; text-decoration: none !important; }
    .client-balance-link:hover, .client-balance-link[aria-expanded=true] { background: rgba(232,193,62,.14); box-shadow: 0 0 0 1px rgba(232,193,62,.45); text-decoration: none !important; }
    .client-balance-link:hover * { text-decoration: none !important; }
    .balance-inline-panel { margin: 14px 0; padding: 18px; border: 1px solid #75632b; border-radius: 14px; background: #111316; min-width: 0; }
    .balance-inline-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
    .balance-inline-head strong { overflow-wrap: anywhere; }
    .balance-inline-head button { flex-shrink: 0; }
    .balance-inline-body .panel { padding: 16px; }
    .balance-inline-row > td { width: auto !important; padding: 0 !important; }
    .balance-inline-row:hover > td { background: transparent !important; }
    .client-balance-link:focus-visible { outline: 2px solid #f2ce4b; outline-offset: 4px; }
    .client-selection-balance { display: block; margin-top: 8px; color: #f2d776; text-underline-offset: 3px; }
    .balance-positive { color: #63dbb0; }
    .balance-negative { color: #ff9aa4; }
    .balance-overview h2 { margin: 8px 0 14px; font-size: clamp(24px,3vw,34px); }
    .balance-overview ~ .panel { margin-top: 18px; }
    .balance-sources { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
    .balance-source { padding: 18px; border: 1px solid #3c424b; border-radius: 13px; background: #15171b; min-width: 0; }
    .balance-source.is-credit { border-left: 3px solid #63dbb0; }
    .balance-source.is-debt { border-left: 3px solid #e78089; }
    .balance-source :is(h3,p) { margin: 9px 0; }
    .balance-source small { color: #aeb5be; line-height: 1.45; display: block; }
    .balance-source-head,.balance-event-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px 16px; }
    .balance-source-head strong,.balance-event-head > span { font-variant-numeric: tabular-nums; white-space: nowrap; }
    .balance-source.is-credit .balance-source-head strong { color: #63dbb0; }
    .balance-source.is-debt .balance-source-head strong { color: #ff9aa4; }
    .balance-reconciliation { margin-top: 16px; padding: 16px; background: #292416; border: 1px solid #75632b; border-radius: 12px; }
    .balance-timeline { list-style: none; padding: 0; margin: 20px 0; }
    .balance-timeline > li { padding: 16px 0 16px 18px; border-left: 2px solid #776129; border-bottom: 1px solid #34383e; }
    .balance-timeline p { margin: 8px 0 0; }
    .balance-event-head > strong { flex: 1 1 220px; }
    .balance-equation { font-variant-numeric: tabular-nums; color: #e3cd86; }
    .client-credit-report { margin-top: 20px; }
    .credit-grand-total { font-size: clamp(22px,3vw,30px); white-space: nowrap; }
    .credit-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; margin: 16px 0; }
    .credit-metrics > div { display: grid; gap: 7px; border-left: 2px solid #807038; padding-left: 12px; }
    .credit-metrics span { color: #b9bec7; font-size: 13px; }
    .credit-metrics strong { font-size: 20px; font-variant-numeric: tabular-nums; }
    .client-credit-report summary { cursor: pointer; color: #eacb68; padding: 10px 0; }
    .client-credit-report table { min-width: 660px; }
    @media (min-width: 761px) and (max-width: 1740px) {
        body .topbar { height: auto !important; flex-wrap: wrap !important; row-gap: 8px !important; padding-bottom: 10px !important; }
        body .topbar .brand { flex: 0 0 204px !important; }
        body .topbar .current-user-box { margin-left: auto !important; flex-shrink: 0; }
        body .topbar nav { order: 3 !important; flex: 0 0 100% !important; width: 100% !important; max-width: 100% !important; justify-content: center !important; flex-wrap: wrap !important; overflow: visible !important; gap: 8px 18px !important; }
    }
    @media (max-width: 760px) {
        .extension-form { grid-template-columns: minmax(0,1fr); }
        .extension-form > * { grid-column: 1 / -1 !important; min-width: 0; }
        .extension-form :is(input,select) { width: 100%; font-size: 16px; }
        .client-credit-report table { min-width: 0; width: 100%; }
        .client-credit-report thead { display: none; }
        .client-credit-report :is(tbody,tr,td) { display: block; width: 100%; box-sizing: border-box; }
        .client-credit-report tr { padding: 12px; border-bottom: 1px solid #41454d; }
        .client-credit-report td { border: 0; padding: 7px 0; white-space: normal; overflow-wrap: anywhere; }
        .client-credit-report td:not(:first-child) { display: flex; justify-content: space-between; gap: 12px; }
        .client-credit-report td:nth-child(2)::before { content: 'До месяца'; color: #b9bec7; }
        .client-credit-report td:nth-child(3)::before { content: 'Увеличение'; color: #b9bec7; }
        .client-credit-report td:nth-child(4)::before { content: 'Уменьшение'; color: #b9bec7; }
        .client-credit-report td:nth-child(5)::before { content: 'Остаток'; color: #b9bec7; }
        .container :is(input:not([type=checkbox]):not([type=radio]),select,textarea) { font-size: 16px; }
        .container .page-head { align-items: stretch; gap: 12px; }
        .container .panel-head.split { flex-wrap: wrap; gap: 12px; }
        .container :is(.form-actions,.downloads) > .button { white-space: normal; text-align: center; }
        .extra-services-summary { display: grid !important; grid-template-columns: minmax(0,1fr) auto; text-align: left; }
        .extra-services-summary > div:first-child { grid-column: 1/-1; }
        .extra-services-summary h2 { font-size: 18px !important; }
        .extra-services-summary .extra-services-total { justify-self: start; width: auto; }
        .balance-sources { grid-template-columns: minmax(0,1fr); }
        .balance-source { padding: 14px; }
        .balance-timeline > li { padding-left: 12px; }
        .credit-metrics { grid-template-columns: minmax(0,1fr); }
        .credit-metrics > div { grid-template-columns: minmax(0,1fr) auto; align-items: baseline; }
        .credit-metrics strong { font-size: 18px; white-space: nowrap; }
    }
}
