:root {
    --page-bg: #070814;
    --top-bg: rgba(18, 20, 42, 0.9);
    --panel: rgba(20, 22, 48, 0.86);
    --panel-strong: rgba(28, 30, 66, 0.95);
    --text: #f6f7ff;
    --muted: #9aa4ce;
    --line: rgba(124, 140, 255, 0.38);
    --line-soft: rgba(124, 140, 255, 0.18);
    --field: rgba(8, 10, 24, 0.86);
    --blue: #4d7cff;
    --blue-deep: #224ee8;
    --blue-soft: #8b7dff;
    --cyan: #3ee7ff;
    --red: #ff4d7a;
    --green: #4be69a;
    --error: #ff4d7a;
    --shadow: rgba(0, 0, 0, 0.36);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    background:
        radial-gradient(circle at 18% 0%, rgba(77, 124, 255, 0.28), transparent 34%),
        radial-gradient(circle at 78% 14%, rgba(62, 231, 255, 0.16), transparent 30%),
        linear-gradient(135deg, #070814 0%, #11122a 47%, #0a1028 100%),
        var(--page-bg);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    border-top: 4px solid var(--cyan);
}

.login-card {
    width: min(420px, 100%);
    display: grid;
    gap: 16px;
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 24px 70px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(18px);
}

.login-card h1 {
    margin: 12px 0 8px;
    font-size: 38px;
    line-height: 1;
}

.login-card label,
.user-form label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.login-card input,
.user-form input,
.user-form select {
    width: 100%;
    height: 46px;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0 14px;
    color: var(--text);
    background: var(--field);
    outline: 0;
    font-size: 14px;
    font-weight: 700;
}

.login-card input:focus,
.user-form input:focus,
.user-form select:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 4px rgba(62, 231, 255, 0.12), 0 0 22px rgba(77, 124, 255, 0.22);
}

.login-card button,
.user-form button,
.sync-panel button {
    height: 46px;
    border: 0;
    border-radius: 10px;
    padding: 0 18px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--blue), var(--blue-soft));
    font-size: 14px;
    font-weight: 800;
    box-shadow: 0 14px 34px rgba(77, 124, 255, 0.28);
}

.admin-shell {
    width: min(1540px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
        "sidebar"
        "workspace"
        "session";
    gap: 18px;
    padding: 18px;
}

.sidebar {
    grid-area: sidebar;
    display: grid;
    gap: 22px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--top-bg);
    box-shadow: 0 20px 60px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(18px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-brand {
    display: grid;
    grid-template-columns: auto minmax(260px, 1fr) minmax(260px, auto);
    align-items: center;
    gap: 24px;
}

.rapay-logo-image {
    width: 132px;
    height: auto;
    display: block;
    flex: 0 0 auto;
    object-fit: contain;
}

.brand > div > span {
    display: block;
    margin-top: 0;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.admin-brand-copy h1 {
    margin: 4px 0 6px;
    font-size: clamp(32px, 3.6vw, 48px);
    line-height: 0.98;
    text-align: right;
}

.admin-brand-copy p {
    max-width: 640px;
    margin: 0 0 0 auto;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    text-align: right;
}

.admin-brand-copy .eyebrow {
    text-align: right;
}

.side-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
}

.side-nav a {
    padding: 12px 13px;
    color: #c2caf0;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 800;
}

.side-nav a:hover,
.side-nav a.is-active {
    color: #ffffff;
    border-color: var(--line);
    background: linear-gradient(135deg, rgba(77, 124, 255, 0.2), rgba(62, 231, 255, 0.08));
    box-shadow: inset 0 0 0 1px rgba(62, 231, 255, 0.1);
}

.session-card {
    grid-area: session;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(180px, 2fr);
    align-items: center;
    gap: 8px;
    padding: 14px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    background: rgba(8, 10, 24, 0.54);
}

.session-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.session-card strong {
    color: var(--text);
    font-size: 15px;
}

.session-card button {
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    font-weight: 800;
}

.workspace {
    grid-area: workspace;
    display: grid;
    gap: 16px;
}

.topline {
    grid-area: topline;
    min-height: 156px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 20px 60px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(18px);
}

.eyebrow {
    display: block;
    color: var(--cyan);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

h1 {
    margin: 8px 0 10px;
    font-size: clamp(34px, 4vw, 52px);
    line-height: 0.98;
}

.topline p {
    max-width: 560px;
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.top-actions {
    display: grid;
    justify-items: end;
    gap: 10px;
}

.live-badge {
    max-width: 320px;
    padding: 10px 13px;
    color: #bfffe1;
    border: 1px solid rgba(75, 230, 154, 0.34);
    border-radius: 999px;
    background: rgba(75, 230, 154, 0.1);
    font-size: 13px;
    font-weight: 800;
    text-align: right;
}

.sync-panel {
    display: grid;
    justify-items: end;
    gap: 8px;
}

.sync-panel button:disabled {
    cursor: wait;
    opacity: 0.72;
}

.sync-result {
    max-width: 320px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-align: right;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.rates-panel {
    padding: 18px;
}

.rates-table {
    display: grid;
    gap: 9px;
    padding: 18px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    background: rgba(8, 10, 24, 0.34);
}

.rates-head,
.rate-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    align-items: center;
}

.rates-head {
    padding: 0 12px 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.rates-head span:nth-child(2),
.rates-head span:nth-child(3) {
    text-align: right;
}

.rate-row {
    min-height: 34px;
    padding: 8px 10px;
    border: 1px solid var(--line-soft);
    border-radius: 9px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.035);
    font-size: 13px;
    font-weight: 800;
}

.rate-row strong {
    color: var(--text);
    font-size: 14px;
}

.rate-row b {
    color: var(--cyan);
    text-align: right;
}

.rates-table p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.stat-card,
.panel {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 18px 54px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(16px);
}

.stat-card {
    min-height: 128px;
    padding: 18px;
}

.stat-card span,
.panel-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.stat-card strong {
    display: block;
    margin: 14px 0 7px;
    color: var(--text);
    font-size: clamp(24px, 3vw, 34px);
}

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

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

.panel {
    padding: 18px;
}

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

h2 {
    margin: 0;
    font-size: 22px;
    line-height: 1.15;
}

.bar-chart {
    display: grid;
    gap: 11px;
}

.bar-row {
    display: grid;
    grid-template-columns: 128px 1fr 118px;
    gap: 12px;
    align-items: center;
    color: #c2caf0;
    font-size: 13px;
    font-weight: 700;
}

.bar-track {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(124, 140, 255, 0.16);
}

.bar-fill {
    height: 100%;
    min-width: 3px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--cyan), var(--blue-soft));
}

.bar-row strong {
    color: var(--text);
    text-align: right;
}

.table-wrap {
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 520px;
}

.table-wrap.compact {
    overflow-x: auto;
}

.table-wrap.compact table {
    min-width: 860px;
    table-layout: fixed;
}

.table-wrap.compact th:nth-child(1),
.table-wrap.compact td:nth-child(1) {
    width: 180px;
}

.table-wrap.compact th:nth-child(2),
.table-wrap.compact td:nth-child(2) {
    width: 130px;
}

.table-wrap.compact th:nth-child(3),
.table-wrap.compact td:nth-child(3) {
    width: 120px;
}

.table-wrap.compact th:nth-child(4),
.table-wrap.compact td:nth-child(4) {
    width: auto;
}

.table-wrap.compact td {
    overflow-wrap: normal;
    word-break: normal;
}

.table-wrap.compact td:last-child {
    overflow-wrap: anywhere;
}

.orders-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    margin: -4px 0 14px;
}

.orders-actions button {
    min-height: 38px;
    padding: 9px 13px;
    border: 1px solid rgba(124, 140, 255, 0.34);
    border-radius: 10px;
    color: #eef2ff;
    background: rgba(124, 140, 255, 0.14);
    font-size: 12px;
    font-weight: 900;
}

.orders-actions button:last-child {
    border-color: rgba(255, 91, 122, 0.45);
    background: rgba(255, 91, 122, 0.12);
}

.orders-actions button:disabled {
    cursor: default;
    opacity: 0.45;
}

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

th,
td {
    padding: 13px 10px;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

td {
    color: #d7ddff;
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

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

.status {
    display: inline-flex;
    padding: 6px 9px;
    border-radius: 999px;
    color: var(--green);
    background: rgba(75, 230, 154, 0.12);
    font-size: 12px;
    font-weight: 900;
}

.delete-order {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: lowercase;
}

.delete-order input {
    width: 16px;
    height: 16px;
    accent-color: var(--red);
}

.terminals-grid,
.terminals-grid-group {
    display: grid;
    gap: 14px;
}

.terminals-grid-group {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.terminal-group {
    display: grid;
    gap: 14px;
}

.terminal-group summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    color: var(--text);
    background: linear-gradient(135deg, rgba(77, 124, 255, 0.16), rgba(62, 231, 255, 0.06));
    cursor: pointer;
    font-size: 16px;
    font-weight: 900;
}

.terminal-group summary::marker {
    color: var(--blue);
}

.terminal-group summary b {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.terminal-group-summary-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.parent-terminal-link {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    color: #ffffff;
    text-decoration: none;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--blue), var(--blue-soft));
    font-size: 13px;
    font-weight: 900;
    box-shadow: 0 10px 24px rgba(77, 124, 255, 0.24);
}

.terminal-card {
    min-height: 198px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    background: rgba(8, 10, 24, 0.46);
}

.terminal-card span {
    display: inline-flex;
    width: fit-content;
    margin-bottom: 14px;
    padding: 6px 9px;
    color: var(--green);
    border-radius: 999px;
    background: rgba(75, 230, 154, 0.12);
    font-size: 12px;
    font-weight: 900;
}

.terminal-card h3 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 20px;
}

.terminal-card p,
.terminal-card small {
    display: block;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.terminal-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.terminal-meta b {
    color: var(--blue);
    font-size: 13px;
}

.terminal-meta a {
    padding: 10px 12px;
    color: #ffffff;
    text-decoration: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--blue), var(--blue-soft));
    font-size: 13px;
    font-weight: 900;
}

.settings-hint {
    margin: -4px 0 16px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.payment-settings-tree {
    display: grid;
    gap: 12px;
}

.payment-settings-group {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    background: rgba(8, 10, 24, 0.28);
}

.payment-settings-group summary {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    color: var(--text);
    cursor: pointer;
    font-size: 16px;
    font-weight: 900;
}

.payment-settings-group summary span {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.payment-settings-group.nested {
    margin-left: 18px;
    background: rgba(77, 124, 255, 0.04);
}

.payment-settings-shops {
    display: grid;
    gap: 10px;
    padding: 0 12px 12px;
}

.payment-settings-shops summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 38px;
    padding: 0 4px;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.payment-settings-shops summary span {
    color: #c2caf0;
}

.payment-settings-children {
    display: grid;
    gap: 10px;
    padding: 0;
}

.payment-settings-row {
    display: grid;
    grid-template-columns: minmax(190px, 1.2fr) 150px 132px minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.035);
}

.payment-settings-row.level-legal {
    border-color: rgba(62, 231, 255, 0.34);
}

.payment-settings-row.level-parent {
    border-color: rgba(139, 125, 255, 0.28);
}

.payment-settings-row strong,
.payment-settings-row small {
    display: block;
}

.payment-settings-row small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.payment-settings-row select,
.payment-settings-row input {
    width: 100%;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 0 10px;
    color: var(--text);
    background: var(--field);
    outline: 0;
    font-weight: 700;
}

.payment-settings-row span {
    color: #c2caf0;
    font-size: 12px;
    font-weight: 800;
}

.payment-settings-row button {
    height: 40px;
    border: 0;
    border-radius: 9px;
    padding: 0 12px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--blue), var(--blue-soft));
    font-size: 12px;
    font-weight: 900;
}

.qr-badges {
    display: flex;
    gap: 5px;
    margin-top: 8px;
}

.qr-badge {
    display: inline-flex;
    width: 23px;
    height: 23px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line-soft);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
    font-size: 11px;
    font-weight: 900;
}

.qr-badge.is-ready {
    color: #bfffe1;
    border-color: rgba(75, 230, 154, 0.34);
    background: rgba(75, 230, 154, 0.12);
}

.user-form {
    display: grid;
    grid-template-columns: minmax(220px, 1.1fr) minmax(230px, 1.2fr) 170px 122px auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 12px;
}

.checkbox-row {
    min-height: 46px;
    display: flex !important;
    align-items: center;
    gap: 9px !important;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--blue);
}

.link-button {
    padding: 0;
    border: 0;
    color: var(--blue);
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-weight: 900;
}

@media (max-width: 1040px) {
    .admin-shell {
        grid-template-columns: 1fr;
        grid-template-areas:
            "sidebar"
            "workspace"
            "session";
    }

    .admin-brand {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .admin-brand .top-actions {
        grid-column: 1 / -1;
        justify-items: stretch;
    }

    .sidebar {
        min-height: auto;
    }

    .side-nav {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .rates-table {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .rates-head {
        display: none;
    }

    .rate-row {
        min-height: 122px;
        grid-template-columns: 1fr;
        align-content: start;
        gap: 10px;
        padding: 14px;
    }

    .rate-row b {
        display: grid;
        gap: 3px;
        text-align: left;
    }

    .rate-row b:first-of-type::before {
        content: "ЦБ";
    }

    .rate-row b:last-of-type::before {
        content: "Рабочий курс";
    }

    .rate-row b::before {
        color: var(--muted);
        font-size: 10px;
        font-weight: 900;
        text-transform: uppercase;
    }

    .stats-grid,
    .charts,
    .terminals-grid-group,
    .payment-settings-row,
    .user-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .payment-settings-row,
    .user-form {
        grid-template-columns: 1fr;
    }
}

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

    .session-card {
        grid-template-columns: 1fr;
    }

    .admin-brand {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .admin-brand .rapay-logo-image {
        width: 116px;
    }

    .topline {
        flex-direction: column;
        min-height: auto;
    }

    .top-actions,
    .sync-panel {
        justify-items: stretch;
        width: 100%;
    }

    .terminal-group summary,
    .terminal-group-summary-meta {
        align-items: flex-start;
        flex-direction: column;
    }

    .live-badge,
    .sync-result {
        max-width: none;
        text-align: left;
    }

    .side-nav {
        grid-template-columns: 1fr;
    }

    .stats-grid,
    .rates-table,
    .charts,
    .terminals-grid-group {
        grid-template-columns: 1fr;
    }

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

    .bar-row strong {
        text-align: left;
    }
}

@media (max-width: 1040px) and (orientation: landscape) {
    .login-screen {
        min-height: 100dvh;
        align-items: start;
        padding: 8px 12px;
    }

    .login-card {
        width: min(500px, 100%);
        gap: 7px;
        padding: 12px 20px;
    }

    .login-card .brand {
        justify-content: center;
    }

    .login-card .rapay-logo-image {
        width: 96px;
    }

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

    .login-card label {
        gap: 4px;
    }

    .login-card input,
    .login-card button {
        height: 36px;
        border-radius: 10px;
        font-size: 12px;
    }

    .admin-shell {
        gap: 10px;
        padding: 8px;
    }

    .sidebar {
        gap: 10px;
        min-height: auto;
        padding: 10px 12px;
    }

    .sidebar .brand {
        justify-content: flex-start;
    }

    .admin-brand {
        grid-template-columns: auto minmax(0, 1fr) minmax(260px, auto);
        gap: 12px;
    }

    .sidebar .rapay-logo-image {
        width: 104px;
    }

    .side-nav {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 8px;
    }

    .side-nav a {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 8px 9px;
        font-size: 13px;
        line-height: 1.12;
    }

    .session-card {
        grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(160px, 2fr);
        align-items: center;
        gap: 10px;
        margin-top: 0;
        padding: 10px 12px;
    }

    .session-card button {
        height: 36px;
    }

    .topline,
    .panel,
    .stat-card {
        padding: 14px;
    }

    .topline {
        min-height: auto;
    }
}
