/* ==========================================================================
   KeyServer admin — design system.

   Self-contained: the admin panel deliberately does not load Bootstrap, so
   everything the UI looks like is in this one file. Sections:
     1. tokens          6. panels
     2. reset/base      7. tables
     3. app shell       8. pills & badges
     4. page header     9. stats
     5. buttons        10. forms, alerts, utilities, responsive
   ========================================================================== */

/* -------------------------------------------------- 1. tokens ----------- */
:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --border: #e2e7ef;
    --border-strong: #cfd7e3;

    --text: #16202f;
    --text-muted: #5a6a82;
    --text-faint: #8593a8;

    --brand: #2563eb;
    --brand-dark: #1b4fd0;
    --brand-soft: #eaf1ff;

    --ok: #08694a;
    --ok-soft: #e6f5ee;
    --warn: #91600b;
    --warn-soft: #fcf2e0;
    --bad: #b52626;
    --bad-soft: #fceceb;
    --info: #0d6493;
    --info-soft: #e8f2fa;

    --sidebar-bg: #111c2e;
    --sidebar-bg-2: #0c1524;
    --sidebar-text: #9fb0c9;
    --sidebar-text-strong: #ffffff;
    --sidebar-border: rgba(255, 255, 255, .08);

    --radius: 10px;
    --radius-sm: 7px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(16, 26, 44, .06);
    --shadow: 0 1px 2px rgba(16, 26, 44, .05), 0 10px 26px -14px rgba(16, 26, 44, .28);
    --shadow-lg: 0 4px 10px rgba(16, 26, 44, .06), 0 24px 48px -20px rgba(16, 26, 44, .35);

    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;

    --sidebar-w: 252px;
}

/* -------------------------------------------------- 2. reset/base ------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }

p { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); text-decoration: underline; }

code, .mono { font-family: var(--mono); font-size: .92em; }

hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 3px; }

/* -------------------------------------------------- 3. app shell -------- */
.app { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
    color: var(--sidebar-text-strong);
}
.sidebar-brand:hover { text-decoration: none; color: var(--sidebar-text-strong); }

.sidebar-mark {
    flex: 0 0 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--brand);
    display: grid;
    place-items: center;
    box-shadow: 0 4px 12px -4px rgba(37, 99, 235, .9);
}
.sidebar-mark svg { width: 18px; height: 18px; stroke: #fff; }

.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-name { font-weight: 650; font-size: .98rem; letter-spacing: -.01em; }
.sidebar-brand-sub { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: var(--sidebar-text); opacity: .75; }

.sidebar-section {
    padding: 1.15rem 1.25rem .4rem;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .11em;
    text-transform: uppercase;
    color: #64748b;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 .6rem; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .7rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
    position: relative;
}
.sidebar-link:hover { background: rgba(255, 255, 255, .06); color: #dbe4f0; text-decoration: none; }
.sidebar-link svg { width: 17px; height: 17px; flex: 0 0 17px; stroke: currentColor; opacity: .85; }

.sidebar-link.active {
    background: rgba(37, 99, 235, .18);
    color: var(--sidebar-text-strong);
}
.sidebar-link.active::before {
    content: "";
    position: absolute;
    left: -.6rem;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}
.sidebar-link.active svg { opacity: 1; }

.sidebar-count {
    margin-left: auto;
    min-width: 20px;
    padding: 0 .4rem;
    height: 19px;
    border-radius: var(--radius-pill);
    background: var(--brand);
    color: #fff;
    font-size: .72rem;
    font-weight: 600;
    display: inline-grid;
    place-items: center;
}

.sidebar-foot {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
    font-size: .74rem;
    color: #64748b;
    line-height: 1.6;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 58px;
    padding: 0 1.75rem;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.topbar-crumb { font-size: .82rem; color: var(--text-muted); }
.topbar-crumb b { color: var(--text); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }

.topbar-note {
    font-size: .75rem;
    color: var(--text-faint);
    padding: .2rem .55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface-2);
}

.user-chip { display: flex; align-items: center; gap: .55rem; }
.user-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 650;
    font-size: .78rem;
    display: grid;
    place-items: center;
    text-transform: uppercase;
}
.user-name { font-size: .82rem; font-weight: 550; color: var(--text); }

.content { padding: 1.75rem; width: 100%; max-width: 1320px; }

/* -------------------------------------------------- 4. page header ------ */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.35rem;
}
.page-header-text { min-width: 0; }
.page-title { font-size: 1.4rem; }
.page-title .mono { font-size: 1.3rem; letter-spacing: -.02em; }
.page-sub { margin: .3rem 0 0; color: var(--text-muted); font-size: .875rem; }
.page-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: .5rem;
}
.back-link:hover { color: var(--brand); text-decoration: none; }

/* -------------------------------------------------- 5. buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    padding: .5rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    font-size: .855rem;
    line-height: 1.25;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease, color .12s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 15px; height: 15px; stroke: currentColor; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, .35); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.btn-default { border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-default:hover { background: var(--surface-2); border-color: #b9c4d4; color: var(--text); }

.btn-success { background: #0a7a56; border-color: #0a7a56; color: #fff; }
.btn-success:hover { background: #086546; border-color: #086546; color: #fff; }

.btn-danger { background: #c92c2c; border-color: #c92c2c; color: #fff; }
.btn-danger:hover { background: #ac2222; border-color: #ac2222; color: #fff; }

.btn-danger-outline { border-color: #e6b7b4; color: var(--bad); background: var(--surface); }
.btn-danger-outline:hover { background: var(--bad-soft); border-color: #d99b97; color: var(--bad); }

.btn-ghost { color: var(--text-muted); background: transparent; }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-sm { padding: .3rem .6rem; font-size: .8rem; border-radius: 6px; }
.btn-lg { padding: .65rem 1.1rem; font-size: .92rem; }
.btn-block { width: 100%; }

.btn-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

/* -------------------------------------------------- 6. panels ----------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
    overflow: hidden;
}
.panel:last-child { margin-bottom: 0; }

.panel-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem 1.15rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.panel-title { font-size: .92rem; font-weight: 600; }
.panel-sub { font-size: .8rem; color: var(--text-muted); margin: .15rem 0 0; }
.panel-head-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.panel-body { padding: 1.15rem; }
.panel-body-tight { padding: 0; }
.panel-foot {
    padding: .85rem 1.15rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* Definition list used across the detail screens. */
.dl { display: grid; grid-template-columns: minmax(9rem, 34%) 1fr; margin: 0; }
.dl dt {
    padding: .5rem 0;
    color: var(--text-muted);
    font-size: .82rem;
    font-weight: 500;
    border-top: 1px solid var(--border);
}
.dl dd {
    padding: .5rem 0;
    margin: 0;
    border-top: 1px solid var(--border);
    min-width: 0;
    overflow-wrap: anywhere;
}
.dl dt:first-of-type, .dl dd:first-of-type { border-top: 0; padding-top: 0; }
.dl dd .sub { display: block; color: var(--text-faint); font-size: .78rem; margin-top: .15rem; }

/* -------------------------------------------------- 7. tables ----------- */
.table-wrap { width: 100%; overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: .865rem; }

.table thead th {
    position: sticky;
    top: 0;
    text-align: left;
    font-size: .715rem;
    font-weight: 600;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table tbody td {
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f9fbfe; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }

.cell-strong { font-weight: 600; color: var(--text); }
.cell-sub { display: block; color: var(--text-faint); font-size: .78rem; margin-top: .1rem; }

.key-link { font-family: var(--mono); font-weight: 600; letter-spacing: .01em; }

.empty {
    padding: 2.5rem 1.25rem;
    text-align: center;
    color: var(--text-muted);
}
.empty-title { font-weight: 600; color: var(--text); margin-bottom: .25rem; }
.empty svg { width: 26px; height: 26px; stroke: var(--text-faint); margin-bottom: .5rem; }

/* -------------------------------------------------- 8. pills ------------ */
.pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .16rem .55rem;
    border-radius: var(--radius-pill);
    font-size: .745rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-plain::before { display: none; }

.pill-ok { background: var(--ok-soft); color: var(--ok); border-color: #c9e7d9; }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dcb6; }
.pill-bad { background: var(--bad-soft); color: var(--bad); border-color: #f0cbc8; }
.pill-info { background: var(--info-soft); color: var(--info); border-color: #c8e0f1; }
.pill-muted { background: var(--surface-3); color: var(--text-muted); border-color: var(--border-strong); }
.pill-off { background: var(--surface-2); color: var(--text-faint); border-color: var(--border); }

.pill-group { display: flex; flex-wrap: wrap; gap: .35rem; }

/* -------------------------------------------------- 9. stats ------------ */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.35rem;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .95rem 1.1rem;
    box-shadow: var(--shadow-sm);
    display: block;
    position: relative;
    overflow: hidden;
}
a.stat:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow); }

.stat::after {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--border-strong);
}
.stat-ok::after { background: #10996c; }
.stat-warn::after { background: #d69412; }
.stat-bad::after { background: #d63c3c; }
.stat-brand::after { background: var(--brand); }

.stat-label {
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.stat-value {
    font-size: 1.7rem;
    font-weight: 650;
    letter-spacing: -.02em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    margin-top: .25rem;
}
.stat-meta { font-size: .78rem; color: var(--text-faint); margin-top: .1rem; }

/* -------------------------------------------------- 10. forms ----------- */
.form-grid { display: grid; gap: 1rem 1.25rem; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }

.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label { font-size: .8rem; font-weight: 550; color: var(--text-muted); }
.field-hint { font-size: .76rem; color: var(--text-faint); }

.input, .select {
    width: 100%;
    padding: .48rem .65rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .875rem;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.input::placeholder { color: #9aa7ba; }
.input:hover, .select:hover { border-color: #b7c2d2; }
.input:focus, .select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.input[readonly], .input:disabled { background: var(--surface-3); color: var(--text-muted); }

.check { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; }
.check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
.check label { font-size: .855rem; color: var(--text); font-weight: 500; margin: 0; }

.form-section-title {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: .85rem;
}

.search {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0 .65rem;
    min-width: 320px;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.search svg { width: 15px; height: 15px; stroke: var(--text-faint); flex: 0 0 15px; }
.search input {
    flex: 1 1 auto;
    border: 0;
    background: transparent;
    padding: .48rem 0;
    font: inherit;
    font-size: .875rem;
    color: var(--text);
    min-width: 0;
}
.search input:focus { outline: none; }

.toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

/* Segmented filter control */
.tabs {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    max-width: 100%;
}
.tab {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .32rem .7rem;
    border-radius: 5px;
    font-size: .82rem;
    font-weight: 550;
    color: var(--text-muted);
    white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; background: rgba(255, 255, 255, .6); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.tab-count {
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-faint);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 0 .35rem;
    font-variant-numeric: tabular-nums;
}
.tab.active .tab-count { color: var(--brand-dark); background: var(--brand-soft); border-color: #cfe0ff; }

/* pagination */
.pager-bar { gap: 1rem; }
.pager-info { font-size: .82rem; color: var(--text-muted); }
.pager-info b { color: var(--text); font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; gap: 2px; margin: 0 auto; flex-wrap: wrap; }

.pager-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    padding: .3rem .55rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: .83rem;
    font-weight: 550;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.pager-link:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); text-decoration: none; }
.pager-link.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    cursor: default;
}
.pager-link.active:hover { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager-link.disabled { color: var(--text-faint); opacity: .55; cursor: default; }
.pager-link.disabled:hover { background: transparent; border-color: transparent; color: var(--text-faint); }
.pager-gap { color: var(--text-faint); padding: 0 .15rem; }

.pager-size { display: flex; align-items: center; gap: .45rem; font-size: .82rem; color: var(--text-muted); }
.pager-size .select { width: auto; padding: .28rem 1.6rem .28rem .5rem; font-size: .82rem; }

/* jquery-validation-unobtrusive hooks */
.input-validation-error { border-color: #d99b97; }
.input-validation-error:focus { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(181, 38, 38, .13); }
.field-validation-error { color: var(--bad); font-size: .78rem; }
.validation-summary-valid { display: none; }

/* alerts */
.alert {
    display: flex;
    gap: .6rem;
    padding: .7rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: .865rem;
    margin-bottom: 1.25rem;
}
.alert svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: .1rem; stroke: currentColor; }
.alert-info { background: var(--info-soft); border-color: #c8e0f1; color: #0b4f74; }
.alert-error { background: var(--bad-soft); border-color: #f0cbc8; color: #8f1f1f; }
.alert-warn { background: var(--warn-soft); border-color: #f0dcb6; color: #7a5108; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert:empty { display: none; }

/* sign-in screen */
.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(900px 500px at 15% -10%, rgba(37, 99, 235, .14), transparent 60%),
        radial-gradient(700px 500px at 95% 110%, rgba(16, 153, 108, .1), transparent 55%),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 1.75rem;
}
.auth-brand { display: flex; align-items: center; gap: .65rem; margin-bottom: 1.25rem; }
.auth-brand .sidebar-mark { flex-basis: 36px; height: 36px; }
.auth-title { font-size: 1.1rem; }
.auth-sub { color: var(--text-muted); font-size: .85rem; margin: .2rem 0 1.25rem; }
.auth-foot { text-align: center; color: var(--text-faint); font-size: .76rem; margin-top: 1.5rem; }

/* utilities */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .8rem; }
.strong { font-weight: 600; }
.tabular { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.ml-auto { margin-left: auto; }
.flex { display: flex; align-items: center; gap: .5rem; }
.flex-wrap { flex-wrap: wrap; }
.inline-form { display: inline; }

.code-box {
    display: inline-block;
    font-family: var(--mono);
    font-size: .84rem;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .18rem .45rem;
    overflow-wrap: anywhere;
}

/* -------------------------------------------------- responsive ----------
   Three steps down from the desktop layout:
     <=1200px  the six-tile dashboard row folds to three
     <=1100px  two-column page grids become one
     <=860px   the sidebar becomes a top bar and the shell goes single-column
     <=700px   data tables restack as labelled cards (a phone cannot show 8 columns)
   ------------------------------------------------------------------------ */
@media (min-width: 1200px) {
    .stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .form-grid > [class^="col-"] { grid-column: span 6; }
    .col-12 { grid-column: span 12; }
}

@media (max-width: 860px) {
    .app { flex-direction: column; }
    .sidebar {
        flex-basis: auto;
        width: 100%;
        height: auto;
        position: static;
    }
    .sidebar-brand { padding: .8rem 1rem; }
    .sidebar-section, .sidebar-foot { display: none; }
    .sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: .5rem .75rem .65rem;
        gap: .3rem;
    }
    .sidebar-link { white-space: nowrap; padding: .5rem .7rem; font-size: .875rem; }
    .sidebar-link.active::before { display: none; }

    .topbar { padding: 0 1rem; height: 52px; }
    .topbar-note, .user-name { display: none; }
    .content { padding: 1.1rem; }

    .form-grid > [class^="col-"] { grid-column: span 12; }
    .search { min-width: 0; width: 100%; }
    .toolbar form { width: 100%; }
    .toolbar-right { margin-left: 0; width: 100%; }
    .tabs { width: 100%; }

    .dl { grid-template-columns: minmax(0, 1fr); }
    .dl dt { padding-bottom: 0; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; }
    .dl dd { border-top: 0; padding-top: .1rem; padding-bottom: .7rem; }
    .dl dt:first-of-type { padding-top: 0; }

    .page-actions { margin-left: 0; width: 100%; }
    .panel-head { flex-wrap: wrap; }
    .panel-head-actions { margin-left: 0; }
}

@media (max-width: 700px) {
    /* Rows become cards: the header row is dropped and every cell carries its own label.
       Views supply that label with data-label on each <td>. */
    .table-wrap { overflow-x: visible; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }

    .table tbody tr { padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
    .table tbody tr:hover { background: transparent; }
    .table tbody td { border: 0; padding: .3rem 0; }
    .table tbody td:empty { display: none; }
    .table tbody td::before {
        content: attr(data-label);
        display: block;
        font-size: .7rem;
        font-weight: 600;
        letter-spacing: .07em;
        text-transform: uppercase;
        color: var(--text-faint);
        margin-bottom: .1rem;
    }
    .table tbody td[data-label=""]::before { content: none; }
    .table tbody td.actions { text-align: left; padding-top: .7rem; }
    .table tbody td.actions::before { content: none; }
    .table tbody td.actions .btn { width: 100%; }
    .table .num { text-align: left; }
    .table .nowrap { white-space: normal; }

    /* Two stat tiles per row keeps the numbers above the fold on a phone. */
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
    .stat { padding: .8rem .9rem; }
    .stat-value { font-size: 1.4rem; }
    .stat-meta { display: none; }

    .page-title { font-size: 1.2rem; }
    .page-actions .btn { flex: 1 1 auto; }
    .page-actions form { flex: 1 1 auto; display: flex; }
    .page-actions form .btn { width: 100%; }

    /* Comfortable thumb targets, and footers that stack instead of squeezing. */
    .btn { padding: .58rem 1rem; }
    .btn-sm { padding: .42rem .8rem; font-size: .82rem; }
    .panel-foot { flex-direction: column; align-items: stretch; }
    .panel-foot .btn { width: 100%; }
    .panel-foot .ml-auto { margin-left: 0; text-align: center; }

    .pager-bar { align-items: center; gap: .75rem; }
    .pager-info, .pager-size { justify-content: center; }
    .pager { justify-content: center; }
    .pager-size .btn { width: auto; }

    .content { padding: .9rem; }
    .panel { border-radius: 9px; }
    .code-box { display: block; }
    .input, .select { font-size: 16px; }  /* stops iOS zooming the page on focus */
}

/* Only the narrowest phones drop to a single column — two tiles still read fine at 390px. */
@media (max-width: 360px) {
    .stats { grid-template-columns: minmax(0, 1fr); }
    .stat-meta { display: block; }
}
