@font-face {
    font-family: "Manrope";
    src: url("/static/fonts/Manrope-wght.ttf") format("truetype");
    font-weight: 200 800;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #1d2433;
    --muted: #677085;
    --line: #dde3ee;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #15803d;
    --warning: #b7791f;
    --danger: #c2410c;
    --shadow: 0 10px 28px rgba(20, 31, 53, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: "Manrope", "Segoe UI", sans-serif;
    font-size: 15px;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 14px 28px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 700;
    font-size: 20px;
}

.nav {
    display: flex;
    gap: 18px;
    color: var(--muted);
    flex: 1;
}

.nav a:hover {
    color: var(--text);
}

.logout {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
}

.logout button,
.button,
.form-panel button,
.login-panel button {
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

.logout button {
    padding: 8px 12px;
    background: #f0f3f8;
    color: var(--text);
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 48px;
}

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

.page-head.compact {
    margin-bottom: 14px;
}

.page-head h1 {
    margin: 0;
    font-size: 30px;
}

.page-head p,
.panel-head p {
    margin: 6px 0 0;
    color: var(--muted);
}

.toolbar,
.panel,
.table-panel,
.form-panel,
.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.toolbar {
    display: flex;
    gap: 10px;
    padding: 14px;
    margin-bottom: 18px;
}

.panel {
    padding: 22px;
    margin-bottom: 18px;
}

.panel-head {
    margin-bottom: 18px;
}

.balance-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.panel-head .payment-details {
    margin: 2px 0 0;
    color: var(--text);
    font-size: 14px;
    text-align: right;
    white-space: nowrap;
}

.panel-head.inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 0;
    margin-bottom: 12px;
}

.panel-head h2 {
    margin: 0;
    font-size: 18px;
}

.cabinet-info {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.cabinet-info h2 {
    margin: 7px 0 8px;
    font-size: 20px;
}

.cabinet-info p {
    margin: 0 0 8px;
    color: var(--muted);
}

.eyebrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.cabinet-url {
    display: block;
    color: var(--muted);
    overflow-wrap: anywhere;
}

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

.stat {
    min-height: 112px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcff;
}

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

.stat strong {
    display: block;
    margin-top: 10px;
    font-size: 30px;
}

.stat small {
    color: var(--muted);
}

.stat.good strong,
.balance.ok {
    color: var(--success);
}

.stat.warn strong,
.balance.warning {
    color: var(--warning);
}

.stat.bad strong,
.balance.error {
    color: var(--danger);
}

.table-panel {
    overflow: hidden;
}

.table-panel.spaced {
    margin-bottom: 18px;
}

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

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    background: #f0f3f8;
    color: #3a4458;
    font-size: 12px;
    text-transform: uppercase;
}

tbody tr:last-child td {
    border-bottom: 0;
}

code {
    padding: 3px 6px;
    border-radius: 6px;
    background: #eef2f7;
}

.right {
    text-align: right;
}

.muted,
.cell-note,
.empty {
    color: var(--muted);
}

.cell-title {
    font-weight: 700;
}

.cell-note {
    margin-top: 4px;
    font-size: 13px;
}

.balance {
    font-weight: 800;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge.ok {
    color: #0f5132;
    background: #dcfce7;
}

.badge.warning {
    color: #7c4a03;
    background: #fef3c7;
}

.badge.error {
    color: #7c2d12;
    background: #ffedd5;
}

.badge.admin {
    color: #3730a3;
    background: #e0e7ff;
}

.tag {
    display: inline-flex;
    padding: 4px 8px;
    margin: 2px 3px 2px 0;
    border-radius: 999px;
    color: #344054;
    background: #eef2f7;
    font-size: 12px;
    font-weight: 700;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
}

.button.primary {
    color: #ffffff;
    background: var(--primary);
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.secondary {
    color: var(--text);
    background: #ffffff;
    border-color: var(--line);
}

.button.small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.alert {
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 16px;
}

.alert-info {
    background: #eff6ff;
    color: #1e3a8a;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
}

.alert-error {
    background: #fff1f2;
    color: #9f1239;
}

.narrow {
    max-width: 760px;
}

.form-panel {
    display: grid;
    gap: 16px;
    padding: 22px;
}

.form-panel label,
.login-panel label {
    display: grid;
    gap: 7px;
    color: #344054;
    font-weight: 700;
}

input,
textarea,
select {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid #cfd7e6;
    border-radius: 8px;
    color: var(--text);
    background: #ffffff;
    font: inherit;
}

input:focus,
textarea:focus,
select:focus {
    outline: 3px solid rgba(37, 99, 235, 0.18);
    border-color: var(--primary);
}

.checkline {
    display: flex !important;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px !important;
}

.checkline input {
    width: auto;
    min-height: auto;
}

.field-group {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcff;
}

.field-group-title {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.field-preview {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.field-preview span {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
}

.field-preview code {
    width: fit-content;
    font-size: 20px;
}

.office-summary-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.office-summary-grid .stat { min-height: 0; }
/* money values in the office module are long: smaller, one-line figures */
.office-summary-grid .stat strong { font-size: 20px; white-space: nowrap; overflow-wrap: normal; font-variant-numeric: tabular-nums; }
.office-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-span-2 { grid-column: 1 / -1; }
.doc-link { color: var(--primary); overflow-wrap: anywhere; }
/* access registry */
.form-panel.spaced { margin-bottom: 18px; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.row-actions form { margin: 0; }
.row-actions .button { white-space: nowrap; }
.access-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.access-search { display: flex; gap: 8px; flex: 1 1 auto; min-width: 0; }
.access-search input { flex: 1 1 auto; min-width: 0; }
/* access tables: light header instead of the site-wide grey one, rows centred vertically */
.stack-table th { background: transparent; color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }
.stack-table td { vertical-align: middle; }
/* search results: one card per person, services as a list with actions */
.search-count { margin: 0 0 10px; }
.person-card { padding: 0; overflow: hidden; }
.person-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.person-head h2 { margin: 0; font-size: 18px; }
.person-head h2 a { color: inherit; }
.person-head p { margin: 4px 0 0; }
.service-list { list-style: none; margin: 0; padding: 0; }
.service-row { display: grid; grid-template-columns: minmax(180px, 1.4fr) 110px minmax(0, 2fr); gap: 12px; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--line); }
.service-row:last-child { border-bottom: 0; }
.service-row:hover { background: #fafbfd; }
.service-name { display: flex; flex-direction: column; gap: 2px; font-weight: 700; }
.service-name a { color: inherit; }
.service-row .row-actions { justify-content: flex-end; }
.button.ghost { color: var(--primary); background: transparent; border-color: transparent; }
.checkline { flex-wrap: wrap; }
label .field-hint { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }
.checkline .field-hint { display: block; flex-basis: 100%; margin-left: 26px; color: var(--muted); font-size: 13px; font-weight: 400; }
/* modal (native <dialog>) */
.modal { width: min(560px, calc(100% - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 24px 60px rgba(20, 31, 53, 0.25); color: var(--text); }
.modal::backdrop { background: rgba(20, 31, 53, 0.45); }
.modal-body { display: grid; gap: 16px; padding: 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-close { border: 0; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal-note { margin: 0; font-size: 13px; }
/* one-time secret after creating an ОВК.ID user */
.created-card { display: grid; gap: 14px; }
.created-card .alert { margin: 0; }
.created-facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 0; align-items: center; }
.created-facts dt { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.created-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.reset-fallback { margin-top: 14px; }
.reset-fallback summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.reset-fallback[open] summary { margin-bottom: 8px; }
.secret-fallback { margin-top: 8px; }
.secret-fallback summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.secret-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.secret { padding: 8px 12px; border-radius: 8px; background: #f0f3f8; font-size: 18px; letter-spacing: 0.04em; user-select: all; }
.link-slot { display: inline-flex; justify-content: flex-end; min-width: 76px; }
.button.ghost:hover { background: #eef3fe; }
.access-tabs { display: flex; flex-wrap: wrap; gap: 0 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.access-tabs a { padding: 10px 14px; color: var(--muted); font-weight: 700; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.access-tabs a:hover { color: var(--text); }
.access-tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.access-tabs .tab-note { font-weight: 600; font-size: 12px; color: var(--muted); }
.access-stats .stat { min-height: 0; min-width: 0; }
.access-stats .stat strong { font-size: 18px; overflow-wrap: anywhere; }
.access-stats .stat.good strong, .access-stats .stat.warn strong { font-size: 22px; }
.button.danger { color: var(--danger); background: #ffffff; border-color: #f3c3ac; }
.button.danger:hover { background: #fff4ee; }
.button.danger.solid { color: #ffffff; background: var(--danger); border-color: var(--danger); }
.button.danger.solid:hover { background: #9a3412; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.inline-form label { display: grid; gap: 6px; }
.sync-card { display: grid; gap: 6px; }
.sync-card .sync-meta { color: var(--muted); font-size: 13px; }
.setup-list { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.cell-mono { font-variant-numeric: tabular-nums; }
.cell-num { white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot .totals-row td { border-top: 2px solid var(--line); border-bottom: 0; background: #f0f3f8; font-weight: 700; }
.stack-table .badge, .access-stats .badge { white-space: nowrap; }
.action-row form { margin: 0; }
.service-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.service-head h2 { margin: 0; }
.add-person summary { cursor: pointer; font-weight: 700; color: var(--muted); }
.add-person[open] summary { margin-bottom: 14px; color: var(--text); }
.add-person summary { color: var(--primary); }
.inline-edit { display: flex; gap: 6px; align-items: center; margin: 0; }
.inline-edit input { min-width: 0; width: 170px; padding: 6px 8px; flex: 1 1 auto; }
.inline-edit button { white-space: nowrap; flex: 0 0 auto; }
.number-list { display: grid; gap: 6px; }
.number-item { display: flex; gap: 6px; align-items: center; }
.number-item .inline-edit { flex: 1 1 auto; }
.number-item form { margin: 0; }
.number-remove { padding-inline: 10px; }
.add-number summary { cursor: pointer; color: var(--primary); font-size: 13px; font-weight: 600; }
.add-number[open] summary { margin-bottom: 6px; }
.inline-edit input.number-note { width: 110px; flex: 0 1 110px; }
.extra-numbers summary { cursor: pointer; color: var(--primary); font-size: 13px; font-weight: 600; }
.extra-numbers summary .cell-note { font-weight: 400; }
.extra-numbers[open] summary { margin-bottom: 6px; }
.extra-numbers[open] summary .cell-note { display: none; }
.service-head p { margin: 6px 0 0; }

.login-shell {
    min-height: calc(100vh - 76px);
    display: grid;
    place-items: center;
    padding: 48px 0;
}

.login-panel {
    width: min(480px, 100%);
    display: grid;
    gap: 16px;
    padding: 40px;
    border-color: #dbe3f0;
    border-radius: 18px;
    box-shadow: 0 24px 56px rgba(27, 43, 72, 0.12);
}

.login-brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: #334155;
    font-size: 14px;
    font-weight: 800;
}

.login-brand-mark {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 10px;
    color: #ffffff;
    background: #2864ee;
    font-size: 10px;
    letter-spacing: -0.4px;
}

.login-intro {
    margin-top: 12px;
}

.login-eyebrow {
    display: block;
    margin-bottom: 13px;
    color: #2563eb;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.login-panel h1 {
    margin: 0;
    color: #202939;
    font-size: clamp(30px, 5vw, 36px);
    line-height: 1.15;
    letter-spacing: -0.045em;
}

.login-panel p {
    max-width: 340px;
    margin: 12px 0 0;
    color: #66748d;
    font-size: 15px;
    line-height: 1.55;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0 2px;
    color: #94a3b8;
    font-size: 12px;
    white-space: nowrap;
}

.login-divider::before,
.login-divider::after {
    height: 1px;
    flex: 1;
    content: "";
    background: #dbe3f0;
}

.login-panel label {
    gap: 8px;
    color: #334155;
    font-size: 13px;
}

.login-panel input {
    min-height: 48px;
    padding: 11px 13px;
    border-color: #cbd5e1;
    border-radius: 10px;
    font-size: 14px;
}

.login-panel input::placeholder {
    color: #94a3b8;
}

.login-panel input:focus {
    outline-width: 3px;
}

.login-panel button,
.form-panel button {
    min-height: 42px;
    color: #ffffff;
    background: var(--primary);
}

.login-panel button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 50px;
    margin-top: 2px;
    border-radius: 10px;
    background: #2864ee;
    font-size: 15px;
    transition: background 160ms ease, transform 160ms ease;
}

.login-panel button:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.auth-keycloak-button {
    width: 100%;
    min-height: 50px;
    margin-top: 2px;
    border-radius: 10px;
    color: #ffffff;
    background: #2864ee;
    font-size: 15px;
    transition: background 160ms ease, transform 160ms ease;
}

.auth-keycloak-button:hover {
    color: #ffffff;
    background: #1d4ed8;
    transform: translateY(-1px);
}

.auth-keycloak-button span {
    margin-left: 2px;
    font-size: 20px;
    font-weight: 500;
    line-height: 1;
}

.login-panel button span {
    font-size: 20px;
    font-weight: 500;
    line-height: 1;
}

.login-panel .login-help a {
    color: inherit;
    text-decoration: underline;
}

.login-panel .login-help {
    max-width: none;
    margin: 4px 0 0;
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
}

@media (max-width: 780px) {
    .topbar,
    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .logout {
        justify-content: space-between;
    }

    .balance-panel-head {
        flex-direction: column;
        gap: 8px;
    }

    .panel-head .payment-details {
        text-align: left;
        white-space: normal;
    }

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

    .office-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .office-detail-grid,
    .form-grid { grid-template-columns: 1fr; }
    .form-span-2 { grid-column: auto; }

    .cabinet-info {
        flex-direction: column;
    }

    .table-panel {
        overflow-x: auto;
    }

    th,
    td {
        white-space: nowrap;
    }

    /* access registry tables turn into cards instead of scrolling sideways */
    .stack-table thead { display: none; }
    .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
    .stack-table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
    .stack-table td { padding: 4px 0; border: 0; white-space: normal; text-align: left; }
    .stack-table td[data-label] { display: flex; gap: 12px; align-items: baseline; }
    .stack-table td[data-label]::before { content: attr(data-label); flex: 0 0 38%; font-size: 11px; font-weight: 800; text-transform: uppercase; color: var(--muted); }
    .stack-table td[data-label] > * { min-width: 0; overflow-wrap: anywhere; }
    .stack-table td.right .row-actions { justify-content: flex-start; margin-top: 6px; }
    .stack-table td.empty { text-align: center; }
    .toolbar { flex-wrap: wrap; }
    .toolbar > input, .toolbar > select { flex: 1 1 100%; }
    .inline-form { flex-direction: column; align-items: stretch; }
    /* The stacked cell keeps a 38% label column, so the number editor has to wrap and shrink: the
       fixed 170/110 px field widths overflowed the remaining space at 360–390 px (QA B-1). */
    .number-list, .number-item { min-width: 0; }
    .number-item { flex-wrap: wrap; }
    .inline-edit { flex-wrap: wrap; min-width: 0; }
    .inline-edit input, .inline-edit input.number-note { width: auto; flex: 1 1 100%; }
    .nav { overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
    /* nine service tabs never fit a phone: wrap them so every service stays visible instead of
       hiding them behind a horizontal scroll with no affordance (QA B-3) */
    .access-tabs { flex-wrap: wrap; }
    .access-toolbar { flex-direction: column; align-items: stretch; }
    .person-head { flex-direction: column; align-items: flex-start; padding: 14px 16px; }
    .service-row { grid-template-columns: 1fr auto; padding: 10px 16px; }
    .service-row .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
    .link-slot { min-width: 0; }
    .created-facts { grid-template-columns: 1fr; gap: 4px; }
    .created-facts dd { margin-bottom: 8px; }
    /* the three-row header would eat a sixth of a phone screen if it stayed sticky */
    .topbar { position: static; gap: 10px; padding: 12px 16px; }
    .access-stats .stat { padding: 12px; }
}

@media (max-width: 520px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .office-summary-grid { grid-template-columns: 1fr; }

    .page {
        width: min(100% - 20px, 1180px);
        margin-top: 18px;
    }

    .login-shell {
        min-height: calc(100vh - 36px);
        padding: 18px 0;
    }

    .login-panel {
        padding: 28px 22px;
        border-radius: 14px;
    }
}
