:root {
    --fi-primary: #2470bc;
    --fi-primary-variant: #336699;
    --fi-secondary: #eea236;
    --fi-surface: #dadcdf;
    --fi-surface-variant: #76848c;
    --fi-bg: #ffffff;
    --fi-body-bg: #f0f2f5;
    --fi-text: #333e48;
    --fi-text-muted: #76848c;
    --fi-border: #bdc3c6;
    --fi-success: #2e7d32;
    --fi-error: #ff3d00;
    --fi-warning: #f57c00;
    --fi-info: #42a5f5;
    --fi-link: #2470bc;
    --fi-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: Lato, Verdana, Helvetica, Arial, sans-serif;
    background: var(--fi-body-bg);
    color: var(--fi-text);
    display: flex;
    min-height: 100vh;
    font-size: 13px;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar { width: 220px; background: var(--fi-bg); border-right: 1px solid var(--fi-border); position: fixed; top: 0; left: 0; bottom: 0; overflow-y: auto; z-index: 100; display: flex; flex-direction: column; transition: width 0.2s; }
.sidebar-brand { padding: 0 16px; height: 40px; font-size: 15px; font-weight: 700; color: var(--fi-text); border-bottom: 1px solid var(--fi-border); display: flex; align-items: center; gap: 8px; background: var(--fi-bg); text-decoration: none; }
.sidebar-brand .seal { flex: none; width: 26px; height: 26px; border-radius: 6px; background: rgb(36, 112, 188); display: grid; place-items: center; color: #fff; font-family: "Space Mono", monospace; font-weight: 800; font-size: 11px; letter-spacing: 0; box-shadow: 0 2px 8px rgba(21,35,67,0.25); }
.sidebar-brand .dot { color: var(--fi-primary); }
.sidebar-section { padding: 10px 16px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--fi-text-muted); background: #f2f2f2; border-bottom: 1px solid #e7e7e7; font-weight: 700; }
.sidebar a { display: flex; align-items: center; gap: 8px; padding: 8px 16px; color: var(--fi-text); text-decoration: none; font-size: 13px; border-left: 3px solid transparent; transition: background 0.15s; }
.sidebar a:hover { background: #e8edf1; color: var(--fi-primary); }
.sidebar a.active { background: var(--fi-primary); color: #fff; border-left-color: var(--fi-primary-variant); }
.sidebar a.active .icon { color: #fff; }
.sidebar a .icon { display: inline-block; width: 20px; text-align: center; font-size: 16px; line-height: 1; color: var(--fi-text-muted); flex-shrink: 0; }

.sidebar-toggle { display: flex; align-items: center; justify-content: center; width: 100%; height: 32px; border: none; background: transparent; cursor: pointer; color: var(--fi-text-muted); font-size: 18px; border-bottom: 1px solid var(--fi-border); transition: background 0.15s; font-family: inherit; }
.sidebar-toggle:hover { background: #e8edf1; color: var(--fi-primary); }
.toggle-expand { display: none; }
body.sidebar-collapsed .toggle-collapse { display: none; }
body.sidebar-collapsed .toggle-expand { display: inline; }
body.sidebar-collapsed .sidebar { width: 48px; overflow: visible; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; gap: 0; }
body.sidebar-collapsed .sidebar-brand .brand-text { display: none; }
/* Section labels become a thin, uniform-width divider line (no dash glyph) */
body.sidebar-collapsed .sidebar-section { font-size: 0; padding: 0; height: 1px; margin: 6px 14px; background: #e0e2e5; border: none; overflow: hidden; }
body.sidebar-collapsed .sidebar-section::after { content: none; }
/* No leading divider directly under the toggle bar */
body.sidebar-collapsed .sidebar-toggle + .sidebar-section { display: none; }
body.sidebar-collapsed .sidebar a { justify-content: center; padding: 8px 0; gap: 0; font-size: 0; border-left: none; position: relative; }
body.sidebar-collapsed .sidebar a:hover::after { content: attr(data-tooltip); position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 6px; background: #333; color: #fff; padding: 4px 10px; border-radius: 4px; font-size: 12px; white-space: nowrap; z-index: 300; pointer-events: none; }
body.sidebar-collapsed .sidebar a.sidebar-brand:hover::after { content: none; }
body.sidebar-collapsed .sidebar a .icon { width: auto; font-size: 18px; }
body.sidebar-collapsed .sidebar a.active { border-left: none; }
body.sidebar-collapsed .lang-switch { padding: 6px 8px; }
body.sidebar-collapsed .lang-switch form, body.sidebar-collapsed .lang-switch .lang-row { flex-direction: column; align-items: stretch; gap: 4px; }
/* Higher specificity than `body.sidebar-collapsed .sidebar a` so the EN/RU
   anchors keep their text and border (that rule zeroes font-size / border-left) */
body.sidebar-collapsed .lang-switch .lang-btn { width: 100%; padding: 4px 0; font-size: 10px; text-align: center; border: 1px solid var(--fi-border); }
body.sidebar-collapsed .lang-switch .lang-btn.lang-active { border-color: var(--fi-primary); }
body.sidebar-collapsed .lang-switch .lang-btn:hover::after { content: none; }
body.sidebar-collapsed .sidebar-toggle { font-size: 14px; }
body.sidebar-collapsed .sidebar-logout { padding: 8px 0; text-align: center; }
body.sidebar-collapsed .sidebar-logout a { justify-content: center; gap: 0; }
body.sidebar-collapsed .sidebar-text { display: none; }
body.sidebar-collapsed .main { margin-left: 48px; }

/* ── Main / topbar ───────────────────────────────────────── */
.main { margin-left: 220px; flex: 1; min-height: 100vh; transition: margin-left 0.2s; min-width: 0; }
.topbar { background: var(--fi-bg); padding: 0 20px; height: 40px; border-bottom: 1px solid var(--fi-border); display: flex; justify-content: space-between; align-items: center; }
.topbar h1 { font-size: 16px; font-weight: 700; color: var(--fi-text); }
.topbar .meta { font-size: 11px; color: var(--fi-text-muted); }
.content { padding: 20px; }

/* ── Cards ───────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--fi-bg); border: 1px solid var(--fi-border); border-radius: 3px; padding: 14px 16px; box-shadow: var(--fi-shadow); }
.card-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--fi-text-muted); margin-bottom: 6px; font-weight: 700; }
.card-value { font-size: 22px; font-weight: 700; color: var(--fi-text); }
.card-sub { font-size: 11px; color: var(--fi-text-muted); margin-top: 4px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 11px; font-weight: 600; }
.badge-on { background: #d4edda; color: var(--fi-success); }
.badge-off { background: #f8d7da; color: var(--fi-error); }
.badge-warn { background: #fff3cd; color: #856404; }
.badge-info { background: #cce5ff; color: #004085; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { background: var(--fi-bg); border: 1px solid var(--fi-border); border-radius: 3px; box-shadow: var(--fi-shadow); overflow: hidden; margin-bottom: 20px; }
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap th { background: #e7e7e7; padding: 8px 12px; text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--fi-text); border-bottom: 2px solid var(--fi-border); border-right: 1px solid var(--fi-border); font-weight: 700; }
.table-wrap th:last-child { border-right: none; }
.table-wrap td { padding: 7px 12px; border-bottom: 1px solid #eee; border-right: 1px solid #eee; font-size: 13px; vertical-align: middle; }
.table-wrap td:last-child { border-right: none; }
.table-wrap tr:hover td { background: #f5f7fa; }
.table-wrap a { color: var(--fi-link); text-decoration: none; }
.table-wrap a:hover { text-decoration: underline; }
.col-filter-row th { background: #f8f9fa; padding: 4px 6px; border-bottom: 1px solid var(--fi-border); }
.col-filter-input { width: 100%; border: 1px solid #ddd; border-radius: 3px; padding: 2px 6px; font-size: 11px; height: 22px; font-family: inherit; color: var(--fi-text); background: var(--fi-bg); text-align: left; }
.col-filter-input:focus { border-color: var(--fi-primary); outline: none; box-shadow: 0 0 3px rgba(36,112,188,0.25); }
.col-filter-input::placeholder { color: #ccc; text-align: center; }

.dt-info { font-size: 11px; color: var(--fi-text-muted); padding: 8px 12px; display: inline-block; }
.dt-paginate { padding: 8px 12px; font-size: 12px; float: right; }
.dt-paginate button { padding: 3px 10px; border-radius: 3px; font-size: 12px; border: 1px solid var(--fi-border); background: var(--fi-bg); color: var(--fi-text); cursor: pointer; margin-left: 2px; }
.dt-paginate button.current { background: var(--fi-primary); color: #fff; border-color: var(--fi-primary); }
.dt-paginate button:hover:not(.current) { background: #e8edf1; }

/* ── Panels ──────────────────────────────────────────────── */
.panel { background: var(--fi-bg); border: 1px solid var(--fi-border); border-radius: 3px; box-shadow: var(--fi-shadow); margin-bottom: 20px; }
.panel-header { padding: 10px 16px; border-bottom: 1px solid var(--fi-border); font-weight: 700; font-size: 13px; background: #f2f2f2; color: var(--fi-text); display: flex; justify-content: space-between; align-items: center; }
.panel-body { padding: 16px; }
.detail-row { display: flex; padding: 7px 0; border-bottom: 1px solid #f0f0f0; gap: 14px; }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 220px; color: var(--fi-text-muted); font-size: 13px; flex-shrink: 0; }
.detail-value { flex: 1; font-size: 13px; word-break: break-word; }
.detail-value code { font-family: "Space Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: 12px; background: #f5f7fa; padding: 1px 5px; border-radius: 2px; color: var(--fi-text); }

.import-form { background: var(--fi-bg); border: 1px solid var(--fi-border); border-radius: 3px; padding: 20px; box-shadow: var(--fi-shadow); margin-bottom: 20px; }
.import-form h3 { font-size: 14px; margin-bottom: 12px; }
.import-form h4 { font-size: 12px; color: var(--fi-text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 18px 0 8px; }
.form-label { display: block; font-size: 11px; color: var(--fi-text-muted); font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }
.form-input { width: 100%; padding: 6px 10px; border: 1px solid var(--fi-border); border-radius: 3px; font-size: 13px; font-family: inherit; box-sizing: border-box; background: var(--fi-bg); color: var(--fi-text); }
.form-input:focus { border-color: var(--fi-primary); outline: none; box-shadow: 0 0 3px rgba(36,112,188,0.25); }
textarea.form-input { resize: vertical; font-family: "Space Mono", monospace; font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 20px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 16px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { display: inline-block; padding: 6px 16px; border-radius: 3px; border: 1px solid transparent; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; transition: border 0.1s, box-shadow 0.1s, background 0.1s; font-family: inherit; line-height: 1.4; }
.btn-primary { background: var(--fi-primary); color: #fff; border-color: var(--fi-primary-variant); }
.btn-primary:hover { background: var(--fi-primary-variant); }
.btn-default { background: var(--fi-bg); color: var(--fi-text); border-color: var(--fi-border); }
.btn-default:hover { background: #e8edf1; }
.btn-danger { background: var(--fi-error); color: #fff; border-color: var(--fi-error); }
.btn-danger:hover { filter: brightness(0.9); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-sm { padding: 3px 10px; font-size: 11px; }

/* ── Messages / toasts ───────────────────────────────────── */
.messages { margin-bottom: 14px; }
.messages .msg { padding: 8px 14px; border-radius: 3px; margin-bottom: 6px; font-size: 13px; border: 1px solid transparent; }
.messages .msg-success { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.messages .msg-error   { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }
.messages .msg-info    { background: #cce5ff; color: #004085; border-color: #b8daff; }

.toast { position: fixed; top: 20px; right: 20px; z-index: 9999; min-width: 320px; max-width: 460px; padding: 12px 18px; font-size: 13px; font-weight: 600; background: #cce5ff; color: #004085; border: 2px solid #b8daff; border-radius: 3px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); cursor: pointer; }
.toast.toast-success { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.toast.toast-error   { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }

/* ── Language switch ─────────────────────────────────────── */
.lang-switch { padding: 8px 16px; }
.lang-switch form, .lang-switch .lang-row { display: flex; gap: 4px; }
.lang-switch .lang-btn { background: transparent; border: 1px solid var(--fi-border); color: var(--fi-text-muted); padding: 3px 10px; border-radius: 3px; cursor: pointer; font-size: 11px; font-weight: 700; text-decoration: none; display: inline-block; }
.lang-switch .lang-btn:hover { background: #e8edf1; color: var(--fi-text); }
.lang-switch .lang-btn.lang-active { background: var(--fi-primary); border-color: var(--fi-primary); color: #fff; }

/* ── Misc ────────────────────────────────────────────────── */
code, .mono { font-family: "Space Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; }
.pem-block { background: #fafbfc; border: 1px solid #e7e7e7; border-radius: 3px; padding: 14px; font-family: "Space Mono", monospace; font-size: 11px; line-height: 1.5; color: #4a5662; white-space: pre-wrap; word-break: break-all; max-height: 320px; overflow: auto; }
.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 12px; }
.kv-list dt { color: var(--fi-text-muted); font-weight: 700; }
.kv-list dd { font-family: "Space Mono", monospace; word-break: break-all; }

/* Demo banner */
.demo-banner { background: linear-gradient(90deg, #fff7e0, #fff3cd); border-bottom: 1px solid #ffe69c; color: #6b4f00; font-size: 12px; padding: 6px 20px; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.demo-banner a { color: #8a6500; text-decoration: underline; }

/* Steps strip on cert-issue */
.steps-strip { display: flex; gap: 0; margin-bottom: 20px; }
.step { flex: 1; background: var(--fi-bg); border: 1px solid var(--fi-border); border-right: none; padding: 10px 14px; font-size: 12px; color: var(--fi-text-muted); position: relative; cursor: pointer; user-select: none; }
.step:last-child { border-right: 1px solid var(--fi-border); border-radius: 0 3px 3px 0; }
.step:first-child { border-radius: 3px 0 0 3px; }
.step.active { background: var(--fi-primary); color: #fff; border-color: var(--fi-primary-variant); font-weight: 700; }
.step.active::after { content: ''; position: absolute; right: -10px; top: 50%; width: 18px; height: 18px; background: var(--fi-primary); border-top: 1px solid var(--fi-primary-variant); border-right: 1px solid var(--fi-primary-variant); transform: translateY(-50%) rotate(45deg); z-index: 2; }
.step .step-num { display: inline-block; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,0.08); text-align: center; line-height: 18px; font-weight: 700; margin-right: 6px; font-size: 11px; }
.step.active .step-num { background: #fff; color: var(--fi-primary); }
.step.done { color: var(--fi-text); }
.step.done .step-num { background: var(--fi-primary); color: #fff; }

/* Client-side wizard panels (cert-issue) */
.wizard-step { display: none; }
.wizard-step.active { display: block; }
.chk { font-size: 12px; display: flex; gap: 5px; align-items: center; }

/* Status pill in topbar */
.topbar .meta .pill { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #e8edf1; color: var(--fi-text); font-weight: 700; margin-left: 6px; }

@media (max-width: 720px) {
    /* ── Sidebar collapses to a 48px icon rail ── */
    .sidebar { width: 48px; }
    .main { margin-left: 48px; }
    .sidebar .sidebar-text { display: none; }
    /* Brand → just the centered CA seal (full name doesn't fit 48px) */
    .sidebar-brand { justify-content: center; padding: 0; gap: 0; }
    .sidebar-brand .brand-text { display: none; }
    /* Section labels → thin uniform divider, not clipped text */
    .sidebar .sidebar-section { font-size: 0; padding: 0; height: 1px; margin: 6px 14px; background: #e0e2e5; border: none; overflow: hidden; }
    .sidebar .sidebar-section::after { content: none; }
    .sidebar-toggle + .sidebar-section { display: none; }
    .sidebar-toggle { font-size: 14px; }
    /* Nav links centered, icon-only */
    .sidebar a { justify-content: center; padding: 8px 0; gap: 0; border-left: none; position: relative; }
    .sidebar a.active { border-left: none; }
    .sidebar a .icon { width: auto; font-size: 18px; }
    /* Language buttons stack and fill the rail (gh-pages uses .lang-row) */
    .lang-switch { padding: 6px 8px; }
    .lang-switch .lang-row, .lang-switch form { flex-direction: column; align-items: stretch; gap: 4px; }
    .lang-switch .lang-btn { width: 100%; padding: 4px 0; font-size: 10px; text-align: center; }
    .sidebar-logout a { justify-content: center; }

    /* ── Content area ── */
    .content { padding: 14px; }
    /* Demo banner: flow as a paragraph instead of splitting text into flex columns */
    .demo-banner { display: block; line-height: 1.5; }
    /* Detail rows stack (fixed 220px label otherwise crushes the value) */
    .detail-row { flex-direction: column; gap: 2px; }
    .detail-label { width: auto; }
    /* Wide tables scroll horizontally instead of being clipped off-screen */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    /* 3-up key-usage grid would run off-screen → drop to 2 columns */
    .form-grid-3 { grid-template-columns: 1fr 1fr; }
}
