:root {
    --bg: #151a21;
    --surface: #1c232d;
    --surface-raised: #222b37;
    --surface-input: #171d25;
    --surface-hover: #26313e;

    --border: #303b49;
    --border-strong: #3b4858;

    --text: #d8dee8;
    --text-strong: #f0f3f7;
    --text-muted: #909baa;

    --accent: #6f9fd1;
    --accent-hover: #83afdc;
    --accent-surface: #24364a;

    --success: #82b99a;
    --success-surface: #21372c;
    --success-border: #365a46;

    --warning: #d0b36b;
    --warning-surface: #3a3321;
    --warning-border: #5b4d29;

    --danger: #d58a8a;
    --danger-surface: #3b2528;
    --danger-border: #654045;

    --info: #8eb5d8;
    --info-surface: #223548;
    --info-border: #36536d;

    --radius-small: 4px;
    --radius: 6px;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.22);

    --font-sans:
        "Segoe UI Variable",
        "Segoe UI",
        Roboto,
        "Noto Sans",
        Ubuntu,
        Arial,
        sans-serif;

    --font-mono:
        "Cascadia Mono",
        "JetBrains Mono",
        "SFMono-Regular",
        Consolas,
        "Liberation Mono",
        monospace;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
dialog:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.app-body {
    padding: 18px;
}

.page {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
}

.page--certificates {
    min-width: 0;
}

.page-title,
.panel-title,
.dialog-title,
.auth-title {
    color: var(--text-strong);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-title {
    margin: 0 0 2px;
    font-size: 25px;
    line-height: 1.2;
}

.panel-title {
    margin: 0 0 12px;
    font-size: 18px;
    line-height: 1.3;
}

.muted {
    color: var(--text-muted);
    font-size: 13px;
}

.text-link {
    color: var(--accent);
    text-decoration: none;
}

.text-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

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

/* Верхняя панель */

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

.topbar__identity {
    min-width: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    white-space: nowrap;
}

.logout-form {
    margin: 0;
}

/* Панели */

.panel {
    padding: 15px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.sync-panel {
    margin-bottom: 16px;
}

.sync-row {
    display: grid;
    grid-template-columns: max-content max-content;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 34px;
}

.sync-row {
    position: relative;
    min-height: 34px;
    padding-right: 540px;
}

.sync-row .message {
    position: absolute;
    top: 0;
    right: 0;
    width: max-content;
    max-width: min(520px, calc(100% - 220px));
    min-height: 34px;
    margin: 0;
    padding: 6px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    line-height: 20px;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
}

.sync-row .message:empty {
    visibility: hidden;
}

/* Сообщения */

.message {
    color: var(--text-muted);
    font-size: 13px;
}

.message--success {
    color: var(--success);
    border-color: var(--success-border) !important;
    background: var(--success-surface);
}

.message--error {
    color: var(--danger);
    border-color: var(--danger-border) !important;
    background: var(--danger-surface);
}

.message--info {
    color: var(--info);
    border-color: var(--info-border) !important;
    background: var(--info-surface);
}

/* Кнопки */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-small);
    color: var(--text);
    background: var(--surface-raised);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        opacity 0.15s ease;
}

.button:hover {
    border-color: #4b596b;
    background: var(--surface-hover);
}

.button:disabled {
    opacity: 0.55;
    cursor: wait;
}

.button--primary {
    color: #eef5fc;
    border-color: #4f79a5;
    background: #355f89;
}

.button--primary:hover {
    border-color: #618db8;
    background: #3e6d99;
}

.button--secondary {
    color: var(--text);
    background: var(--surface-raised);
}

.button--details {
    color: var(--accent);
    border-color: #405873;
    background: var(--accent-surface);
}

.button--details:hover {
    color: #a5c8e8;
    border-color: #526e8b;
    background: #2a4057;
}

.button--danger {
    color: #efc2c2;
    border-color: var(--danger-border);
    background: var(--danger-surface);
}

.button--danger:hover {
    color: #f5d1d1;
    border-color: #7b4d53;
    background: #4a2d31;
}

.button--link {
    min-height: auto;
    padding: 0;
    border: 0;
    color: var(--accent);
    background: transparent;
    font-weight: 400;
}

.button--link:hover {
    color: var(--accent-hover);
    background: transparent;
    text-decoration: underline;
}

.button--block {
    width: 100%;
}

.button--dialog-close {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border: 0;
    color: var(--text-muted);
    background: transparent;
    font-size: 22px;
    font-weight: 400;
}

.button--dialog-close:hover {
    color: var(--text-strong);
    background: var(--surface-hover);
}

/* Таблица сертификатов */

.certificate-list {
    min-width: 0;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.certificates-table {
    width: 100%;
    min-width: 1240px;
    table-layout: fixed;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.certificates-table th,
.certificates-table td {
    padding: 8px 9px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.certificates-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    color: #cbd3de;
    background: var(--surface-raised);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.certificates-table th:nth-child(2) {
    text-align: left;
}

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

.certificates-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.018);
}

/* Ширина колонок */

.cert-col-id {
    width: 44px;
}

.cert-col-owner {
    width: auto;
}

.cert-col-date {
    width: 145px;
}

.cert-col-status {
    width: 105px;
}

.cert-col-serial {
    width: 185px;
}

.cert-col-thumbprint {
    width: 185px;
}

.cert-col-key {
    width: 62px;
}

.cert-col-details {
    width: 100px;
}

.cert-col-action {
    width: 100px;
}

/* Значения таблицы */

.certificates-table td {
    text-align: center;
}

.cell-id {
    color: var(--text-muted);
}

.cell-owner {
    min-width: 0;
    text-align: left !important;
}

.cell-date,
.cell-status {
    white-space: nowrap;
}

.cell-action {
    text-align: right !important;
}

.owner-name {
    display: block;
    overflow: hidden;
    color: var(--text-strong);
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mono {
    font-family: var(--font-mono);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.cell-code {
    min-width: 0;
}

.cell-code .mono {
    display: block;
    width: 100%;
    overflow: hidden;
    text-align: center;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Статусы */

.status,
.key-badge {
    display: inline-block;
    padding: 3px 6px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
}

.status--normal {
    color: var(--success);
    border-color: var(--success-border);
    background: var(--success-surface);
}

.status--warning {
    color: var(--warning);
    border-color: var(--warning-border);
    background: var(--warning-surface);
}

.status--critical,
.status--expired {
    color: var(--danger);
    border-color: var(--danger-border);
    background: var(--danger-surface);
}

.status--unknown {
    color: var(--text-muted);
    border-color: var(--border-strong);
    background: var(--surface-raised);
}

.key-badge--yes {
    color: var(--success);
    border-color: var(--success-border);
    background: var(--success-surface);
}

.key-badge--no {
    color: var(--danger);
    border-color: var(--danger-border);
    background: var(--danger-surface);
}

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

/* Окно сведений о сертификате */

.certificate-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.certificate-dialog::backdrop {
    background: rgba(8, 11, 15, 0.72);
    backdrop-filter: blur(2px);
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-raised);
}

.dialog-title {
    margin: 0 0 2px;
    font-size: 19px;
}

.dialog-content {
    max-height: calc(100vh - 180px);
    padding: 16px;
    overflow-y: auto;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    padding: 11px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-raised);
}

.certificate-properties {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    margin: 0 0 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--border);
}

.certificate-property {
    min-width: 0;
    padding: 10px 12px;
    background: var(--surface);
}

.certificate-property dt {
    margin-bottom: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

.certificate-property dd {
    margin: 0;
    color: var(--text);
    overflow-wrap: anywhere;
}

.certificate-dn-section {
    margin-top: 14px;
}

.certificate-dn-section h3 {
    margin: 0 0 6px;
    color: var(--text-strong);
    font-size: 14px;
}

.certificate-dn {
    max-height: 230px;
    margin: 0;
    padding: 10px 12px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    color: #c7d0dc;
    background: var(--surface-input);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Авторизация и смена пароля */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 410px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-title {
    margin: 0 0 3px;
    font-size: 24px;
    line-height: 1.25;
}

.auth-subtitle {
    margin: 0 0 21px;
    color: var(--text-muted);
    font-size: 13px;
}

.auth-form {
    margin-top: 16px;
}

.auth-card .message {
    margin-bottom: 16px;
    padding: 9px 11px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
}

.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    color: #c2cad5;
    font-size: 13px;
}

.form-input {
    width: 100%;
    height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-small);
    outline: none;
    color: var(--text-strong);
    background: var(--surface-input);
}

.form-input:hover {
    border-color: #49586a;
}

.form-input:focus,
.form-input:focus-visible {
    outline: none;
    border-color: var(--border-strong);
    box-shadow: none;
}

.form-hint {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 11px;
}

.auth-footer {
    margin: 17px 0 0;
    color: #788493;
    font-size: 11px;
    text-align: center;
}

.auth-back-link {
    display: block;
    margin-top: 17px;
    font-size: 13px;
    text-align: center;
}

.topbar-actions .text-link,
.topbar-actions .button--link {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.45;
    letter-spacing: normal;
}

.topbar-actions .button--link {
    appearance: none;
}

/* Прокрутка окна сведений о сертификате */

.dialog-content {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) var(--surface);
    scrollbar-gutter: stable;
}

.dialog-content::-webkit-scrollbar {
    width: 10px;
}

.dialog-content::-webkit-scrollbar-track {
    background: var(--surface);
}

.dialog-content::-webkit-scrollbar-thumb {
    border: 2px solid var(--surface);
    border-radius: 10px;
    background: var(--border-strong);
}

.dialog-content::-webkit-scrollbar-thumb:hover {
    background: #526174;
}

/* Прокрутка полей «Издатель» и «Subject» */

.certificate-dn {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) var(--surface-input);
    scrollbar-gutter: stable;
}

.certificate-dn::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

.certificate-dn::-webkit-scrollbar-track {
    background: var(--surface-input);
}

.certificate-dn::-webkit-scrollbar-thumb {
    border: 2px solid var(--surface-input);
    border-radius: 9px;
    background: var(--border-strong);
}

.certificate-dn::-webkit-scrollbar-thumb:hover {
    background: #526174;
}

/* Адаптивность */

@media (max-width: 900px) {
    .sync-row {
        display: grid;
        gap: 10px;
        padding-right: 0;
    }

    .sync-row .message {
        position: static;
        width: 100%;
        max-width: 100%;
        max-height: none;
    }
}

@media (max-width: 760px) {
    .app-body {
        padding: 12px;
    }

    .topbar {
        align-items: flex-start;
    }

    .topbar-actions {
        gap: 10px;
    }

    .sync-panel {
        display: none;
    }

    .certificate-properties {
        grid-template-columns: 1fr;
    }

    .dialog-content {
        max-height: calc(100vh - 165px);
        padding: 13px;
    }

    .table-wrapper {
        scrollbar-width: thin;
        scrollbar-color: var(--border-strong) var(--bg);
    }

    .table-wrapper::-webkit-scrollbar {
        height: 8px;
        background: var(--bg);
    }

    .table-wrapper::-webkit-scrollbar-track {
        background: var(--bg);
    }

    .table-wrapper::-webkit-scrollbar-thumb {
        border: 2px solid var(--bg);
        border-radius: 8px;
        background: var(--border-strong);
    }
}

@media (max-width: 520px) {
    .topbar {
        flex-direction: column;
        gap: 10px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .auth-page {
        padding: 12px;
    }

    .auth-card {
        padding: 20px 17px;
    }

    .certificate-dialog {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
    }
}