:root {
    --bg: #f4f5f5;
    --surface: #ffffff;
    --ink: #36454f;
    --muted: #708090;
    --line: #d3d3d3;
    --soft: #eef0f1;
    --green: #0b8f52;
    --blue: #2b6fff;
    --amber: #b7791f;
    --radius: 8px;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "DejaVu Sans", Inter, Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    padding: 24px 18px;
    background: #11181d;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 21px;
    font-weight: 800;
}

.brand-mark {
    width: 28px;
    height: 28px;
    background: #fff;
    display: inline-block;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a,
.logout-link {
    color: #d8d8d8;
    padding: 11px 12px;
    border-radius: var(--radius);
    font-weight: 650;
}

.nav a:hover,
.logout-link:hover {
    background: #1d1d1d;
    color: #fff;
}

.logout-link {
    margin-top: auto;
}

.shell {
    margin-left: 240px;
    padding: 32px;
}

.page-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 22px;
}

.page-top h1,
.panel h2,
.live-card h2 {
    margin: 0;
    letter-spacing: 0;
}

.page-top h1 {
    font-size: 34px;
    line-height: 1.12;
}

.muted,
.page-top p,
.login-card p {
    color: var(--muted);
}

.eyebrow {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.page-actions,
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.button,
.button-link,
.filter-bar button,
.login-card button {
    border: 0;
    border-radius: var(--radius);
    background: #000;
    color: #fff;
    padding: 11px 16px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.button.secondary,
.button-link.secondary {
    background: var(--soft);
    color: var(--ink);
}

.text-link {
    color: var(--muted);
    font-weight: 800;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.tabs a {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
    padding: 10px 14px;
    font-weight: 850;
}

.tabs a.active {
    background: #000;
    border-color: #000;
    color: #fff;
}

.filter-bar {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 22px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
}

.filter-bar input,
.filter-bar select,
.login-card input,
.stacked-form input,
.stacked-form select,
.stacked-form textarea {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 0 12px;
    font: inherit;
}

.stacked-form textarea {
    min-height: 110px;
    padding: 12px;
    resize: vertical;
}

.button:focus-visible,
.button-link:focus-visible,
.filter-bar button:focus-visible,
.login-card button:focus-visible,
.mini-button:focus-visible,
.nav a:focus-visible,
.logout-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(43, 111, 255, 0.35);
    outline-offset: 2px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.metric-grid.executive-grid {
    grid-template-columns: repeat(5, minmax(170px, 1fr));
}

.metric {
    min-height: 132px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.metric.primary {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}

.metric.warning-metric {
    background: #fff7ed;
    border-color: #fed7aa;
}

.metric span,
.metric small {
    color: var(--muted);
    font-weight: 750;
}

.metric.primary span,
.metric.primary small {
    color: #cfcfcf;
}

.metric strong {
    display: block;
    margin: 12px 0 8px;
    font-size: clamp(24px, 3vw, 36px);
    letter-spacing: 0;
}

.panel-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
    gap: 18px;
    margin-bottom: 18px;
}

.panel-grid.dashboard-charts {
    grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.8fr);
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.stat-section {
    min-height: 100%;
}

.compact-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 10px;
}

.compact-stat-grid div {
    min-height: 92px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfbfb;
    padding: 12px;
}

.compact-stat-grid span {
    display: block;
    min-height: 32px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.compact-stat-grid strong {
    display: block;
    margin-top: 10px;
    color: var(--ink);
    font-size: 20px;
    letter-spacing: 0;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
}

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

.chart-canvas {
    display: block;
    width: 100%;
    height: 320px;
}

.chart-canvas.compact {
    height: 320px;
}

.chart-canvas.tall {
    height: 380px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap.flat {
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

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

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    background: #fbfbfa;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
}

td {
    font-size: 14px;
}

tbody tr:hover {
    background: #fafafa;
}

tbody tr.warning-row,
tbody tr.warning-row:hover {
    background: #fff7ed;
}

.positive {
    color: var(--green);
    font-weight: 850;
}

.trust-warning {
    max-width: 360px;
    color: #b42318;
    font-weight: 850;
    white-space: normal;
    line-height: 1.35;
}

.trust-ok {
    color: var(--green);
    font-weight: 850;
}

.comment-cell {
    max-width: 320px;
    white-space: normal;
    line-height: 1.35;
}

.reports-table {
    min-width: 1560px;
}

.cash-layout {
    grid-template-columns: minmax(320px, 0.9fr) minmax(280px, 0.7fr);
}

.stacked-form {
    display: grid;
    gap: 14px;
}

.stacked-form label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
}

.stacked-form small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.inline-adjust-form {
    display: grid;
    min-width: 230px;
    gap: 8px;
}

.inline-adjust-form label {
    display: grid;
    grid-template-columns: 72px minmax(90px, 1fr);
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
}

.inline-adjust-form input {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 9px;
    font: inherit;
}

.trust-hint {
    border: 1px solid #fed7aa;
    border-radius: var(--radius);
    background: #fffaf0;
    color: #9a3412;
    padding: 9px;
    font-size: 12px;
    font-weight: 750;
    line-height: 1.45;
    white-space: normal;
}

.stacked-form button {
    min-height: 46px;
    border: 0;
    border-radius: var(--radius);
    background: #000;
    color: #fff;
    font: inherit;
    font-weight: 850;
    cursor: pointer;
}

.audit-note {
    display: grid;
    gap: 12px;
    color: var(--muted);
    line-height: 1.55;
}

.audit-note strong {
    display: block;
    padding: 14px;
    border-radius: var(--radius);
    background: #11181d;
    color: #fff;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.mini-button {
    border: 0;
    border-radius: var(--radius);
    background: #000;
    color: #fff;
    padding: 8px 10px;
    font: inherit;
    font-size: 12px;
    font-weight: 850;
    cursor: pointer;
}

.mini-button.secondary {
    background: var(--soft);
    color: var(--ink);
}

.mini-button.danger {
    background: #b42318;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 850;
}

.status-badge.pending {
    background: #fff7ed;
    color: #9a3412;
}

.status-badge.accepted {
    background: #ecfdf3;
    color: #067647;
}

.status-badge.rejected {
    background: #fef3f2;
    color: #b42318;
}

.alert {
    margin-bottom: 16px;
    border-radius: var(--radius);
    padding: 12px 14px;
    font-weight: 800;
}

.alert.success {
    background: #ecfdf3;
    color: #067647;
}

.alert.error {
    background: #fef3f2;
    color: #b42318;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 28px;
}

.live-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
}

.live-card {
    position: relative;
    min-height: 190px;
    padding: 20px;
    border-radius: var(--radius);
    background: #000;
    color: #fff;
    box-shadow: var(--shadow);
}

.live-card p {
    margin: 8px 0 22px;
    color: #cfcfcf;
}

.live-card dl {
    display: grid;
    gap: 10px;
    margin: 0;
}

.live-card div {
    min-width: 0;
}

.live-card dt {
    color: #a8a8a8;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.live-card dd {
    margin: 4px 0 0;
    font-size: 18px;
    font-weight: 850;
}

.live-status {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #30e884;
}

.empty-panel {
    max-width: 520px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #000;
}

.login-card {
    width: min(440px, 100%);
    background: #fff;
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 32px;
}

.login-card form {
    display: grid;
    gap: 14px;
    margin-top: 24px;
}

.login-card label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 750;
}

.settings-panel {
    max-width: 980px;
}

.settings-form {
    display: grid;
    gap: 16px;
}

.settings-section {
    display: grid;
    gap: 14px;
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.checkbox-line input {
    width: 18px;
    height: 18px;
}

.settings-form label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 800;
}

.settings-form input,
.settings-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    color: var(--ink);
    font: inherit;
}

.payroll-tier-list {
    display: grid;
    gap: 10px;
}

.payroll-tier-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(140px, 1fr)) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfbfb;
}

.salary-form {
    min-width: 130px;
    grid-template-columns: 1fr auto;
    align-items: center;
}

.salary-form label {
    grid-template-columns: 20px minmax(70px, 1fr);
}

.error {
    margin-top: 18px;
    border-radius: var(--radius);
    background: #fff1f0;
    color: #9f1d16;
    padding: 12px;
    font-weight: 750;
}

@media (max-width: 1080px) {
    .metric-grid {
        grid-template-columns: repeat(3, minmax(160px, 1fr));
    }

    .metric-grid.executive-grid {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }

    .panel-grid {
        grid-template-columns: 1fr;
    }

    .panel-grid.dashboard-charts,
    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .compact-stat-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }
}

@media (max-width: 760px) {
    body {
        overflow-x: hidden;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 20;
        width: auto;
        padding: 12px;
        gap: 12px;
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
    }

    .shell {
        margin-left: 0;
        padding: 16px 12px 28px;
    }

    .brand {
        font-size: 18px;
    }

    .brand-mark {
        width: 22px;
        height: 22px;
    }

    .nav {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .nav a,
    .logout-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        padding: 10px 12px;
        white-space: nowrap;
        scroll-snap-align: start;
        background: rgba(255, 255, 255, 0.06);
    }

    .logout-link {
        margin-top: 0;
        width: max-content;
    }

    .page-top {
        display: grid;
        gap: 14px;
        margin-bottom: 16px;
    }

    .page-top h1 {
        font-size: clamp(26px, 8vw, 32px);
    }

    .page-top p {
        margin-bottom: 0;
    }

    .page-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .page-actions .button,
    .page-actions .button-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

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

    .metric-grid.executive-grid,
    .compact-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric {
        min-height: 116px;
        padding: 14px;
    }

    .metric strong {
        font-size: clamp(22px, 7vw, 30px);
        overflow-wrap: anywhere;
    }

    .panel {
        padding: 14px;
    }

    .panel-head {
        display: grid;
        gap: 10px;
    }

    .panel-grid,
    .panel-grid.dashboard-charts,
    .analytics-grid,
    .cash-layout {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .compact-stat-grid div {
        min-height: 82px;
        padding: 10px;
    }

    .compact-stat-grid span {
        min-height: auto;
        font-size: 11px;
    }

    .chart-canvas,
    .chart-canvas.compact,
    .chart-canvas.tall {
        height: 260px;
    }

    .filter-bar {
        display: grid;
        gap: 10px;
        padding: 10px;
    }

    .filter-bar input,
    .filter-bar select,
    .filter-bar button {
        width: 100%;
        min-height: 44px;
    }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }

    .tabs a {
        flex: 0 0 auto;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .table-wrap {
        margin-inline: -12px;
        width: calc(100% + 24px);
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .table-wrap::before {
        content: "Прокрутите таблицу вбок →";
        display: block;
        position: sticky;
        left: 0;
        padding: 8px 12px;
        color: var(--muted);
        background: linear-gradient(90deg, #fff, rgba(255, 255, 255, 0.86));
        font-size: 12px;
        font-weight: 800;
        z-index: 2;
    }

    table {
        min-width: 760px;
    }

    th,
    td {
        padding: 11px 10px;
        font-size: 13px;
    }

    .reports-table {
        min-width: 1280px;
    }

    .inline-adjust-form {
        min-width: 210px;
    }

    .payroll-tier-row {
        grid-template-columns: 1fr;
    }

    .settings-panel {
        max-width: none;
    }

    .login-page {
        align-items: start;
        padding: 16px;
    }

    .login-card {
        padding: 22px;
    }
}

@media (max-width: 430px) {
    .shell {
        padding-inline: 10px;
    }

    .page-actions,
    .metric-grid,
    .metric-grid.executive-grid,
    .compact-stat-grid {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: 104px;
    }

    .button,
    .button-link,
    .filter-bar button,
    .login-card button,
    .stacked-form button {
        width: 100%;
    }

    .table-wrap {
        margin-inline: -10px;
        width: calc(100% + 20px);
    }

    .chart-canvas,
    .chart-canvas.compact,
    .chart-canvas.tall {
        height: 220px;
    }

    .row-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .row-actions form,
    .row-actions button {
        width: 100%;
    }
}
