:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --line: #e5eaf2;
    --primary: #315ee7;
    --primary-dark: #2348bd;
    --green: #15966d;
    --orange: #d97706;
    --red: #dc3545;
    --violet: #7c3aed;
    --sidebar: #111a2e;
    --shadow: 0 12px 34px rgba(32, 50, 87, .08);
    --radius: 16px;
    color-scheme: light;
    font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
}

button,
input,
select,
textarea {
    font: inherit;
}

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

.app-shell {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    width: 250px;
    height: 100vh;
    padding: 26px 18px 20px;
    background:
        radial-gradient(circle at 10% 5%, rgba(58, 101, 233, .3), transparent 28%),
        var(--sidebar);
    color: #fff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px;
    color: #fff;
}

.brand:hover {
    color: #fff;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(145deg, #5d83ff, #315ee7);
    box-shadow: 0 8px 24px rgba(49, 94, 231, .4);
    color: #fff;
    font-size: 19px;
    font-weight: 800;
}

.brand-mark-large {
    width: 56px;
    height: 56px;
    border-radius: 17px;
    font-size: 27px;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 17px;
    letter-spacing: .03em;
}

.brand small {
    margin-top: 1px;
    color: #91a1bf;
    font-size: 10px;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.nav-list {
    display: grid;
    gap: 6px;
    margin-top: 38px;
}

.nav-list a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border-radius: 11px;
    color: #aebbd3;
    font-weight: 600;
    transition: .18s ease;
}

.nav-list a:hover,
.nav-list a.active {
    background: rgba(255, 255, 255, .09);
    color: #fff;
}

.nav-dot {
    width: 7px;
    height: 7px;
    border: 2px solid currentColor;
    border-radius: 999px;
}

.nav-list a.active .nav-dot {
    border-color: #7ca0ff;
    background: #7ca0ff;
    box-shadow: 0 0 0 4px rgba(124, 160, 255, .14);
}

.sidebar-foot {
    display: grid;
    gap: 14px;
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, .1);
}

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

.admin-chip strong,
.admin-chip small {
    display: block;
}

.admin-chip strong {
    font-size: 13px;
}

.admin-chip small {
    color: #8fa0bd;
    font-size: 11px;
}

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .12);
    color: #cbd6eb;
    font-weight: 700;
}

.main-column {
    display: flex;
    min-width: 0;
    min-height: 100vh;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 102px;
    padding: 20px 34px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(12px);
}

.topbar > div {
    flex: 1;
}

.topbar h1 {
    margin: 1px 0 0;
    font-size: 24px;
    letter-spacing: -.03em;
}

.eyebrow {
    margin: 0;
    color: #7b8aa5;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .13em;
    text-transform: uppercase;
}

.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
}

.content {
    flex: 1;
    width: 100%;
    max-width: 1580px;
    margin: 0 auto;
    padding: 28px 34px 40px;
}

.footer {
    display: flex;
    justify-content: space-between;
    padding: 18px 34px 24px;
    color: #8a96aa;
    font-size: 11px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
    line-height: 1.2;
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    background: var(--primary);
    box-shadow: 0 7px 18px rgba(49, 94, 231, .2);
    color: #fff;
}

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

.button-secondary {
    border-color: #cad5eb;
    background: #edf3ff;
    color: #3158c5;
}

.button-ghost {
    border-color: var(--line);
    background: transparent;
    color: #667085;
}

.sidebar .button-ghost {
    border-color: rgba(255, 255, 255, .13);
    color: #aebbd3;
}

.button-warning {
    background: #fff2d9;
    color: #a85d00;
}

.button-success {
    background: #dff8ed;
    color: #0b7954;
}

.button-danger {
    background: #fee7e9;
    color: #b42331;
}

.button-large {
    min-height: 46px;
    padding-inline: 20px;
}

.button-block {
    width: 100%;
}

.button-row,
.action-row,
.form-actions {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
}

.panel {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.panel + .panel {
    margin-top: 22px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--line);
}

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

.panel-head p.subtle {
    margin: 5px 0 0;
}

.panel-head-wrap {
    align-items: flex-end;
    flex-wrap: wrap;
}

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

.stat-card {
    position: relative;
    overflow: hidden;
    min-height: 150px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.stat-card::after {
    position: absolute;
    right: -24px;
    bottom: -36px;
    width: 110px;
    height: 110px;
    border-radius: 999px;
    background: var(--accent);
    content: "";
    opacity: .1;
}

.stat-card span,
.stat-card small,
.stat-card strong {
    display: block;
}

.stat-card span {
    color: var(--muted);
    font-weight: 700;
}

.stat-card strong {
    margin: 14px 0 7px;
    color: var(--accent);
    font-size: 34px;
    line-height: 1;
}

.stat-card small {
    color: #8a96aa;
}

.accent-blue { --accent: var(--primary); }
.accent-green { --accent: var(--green); }
.accent-violet { --accent: var(--violet); }
.accent-orange { --accent: var(--orange); }

.two-column {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(330px, .75fr);
    gap: 22px;
}

.two-column > .panel {
    margin-top: 0;
}

.detail-columns {
    grid-template-columns: minmax(0, 1.3fr) minmax(340px, .7fr);
    margin-bottom: 22px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

th,
td {
    padding: 13px 18px;
    border-bottom: 1px solid #edf0f5;
    text-align: left;
    vertical-align: middle;
}

th {
    background: #fafbfd;
    color: #77839a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
}

tbody tr:hover {
    background: #fbfcff;
}

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

.code-link,
td code {
    color: #244cb8;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
    font-weight: 700;
}

.note-cell {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-sub {
    display: block;
    margin-top: 2px;
    color: #8a96aa;
    font-size: 10px;
}

.empty-cell,
.empty-state {
    padding: 34px 20px;
    color: #8a96aa;
    text-align: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #eef1f6;
    color: #596579;
    font-size: 11px;
    font-weight: 800;
}

.badge-active,
.badge-device-bound {
    background: #ddf8ed;
    color: #0b7954;
}

.badge-waiting,
.badge-pending {
    background: #e8efff;
    color: #3158c5;
}

.badge-expired {
    background: #fff0dc;
    color: #ae6200;
}

.badge-disabled,
.badge-device-unbound {
    background: #eef1f6;
    color: #596579;
}

.badge-revoked,
.badge-device-blocked {
    background: #fee7e9;
    color: #b42331;
}

.timeline {
    display: grid;
    padding: 14px 22px 20px;
}

.timeline article {
    position: relative;
    display: flex;
    gap: 12px;
    padding: 10px 0 10px 18px;
    border-left: 1px solid #dfe5ef;
}

.timeline-dot {
    position: absolute;
    top: 16px;
    left: -5px;
    width: 9px;
    height: 9px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 0 0 1px #9db4ef;
}

.timeline strong {
    font-size: 12px;
}

.timeline p {
    margin: 2px 0 0;
    color: #8a96aa;
    font-size: 10px;
}

.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #d8dfeb;
    border-radius: 9px;
    outline: none;
    background: #fff;
    color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease;
}

textarea {
    min-height: 82px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #7b9bf1;
    box-shadow: 0 0 0 3px rgba(49, 94, 231, .1);
}

.filter-bar input {
    width: 200px;
}

.filter-bar input[type="number"] {
    width: 120px;
}

.filter-bar select {
    width: 140px;
}

.form-panel {
    max-width: 930px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    padding: 22px;
}

.form-grid > label,
.stack-form label,
.field-group label {
    display: grid;
    align-content: start;
    gap: 7px;
}

label > span {
    font-weight: 700;
}

label small {
    color: #8995a9;
    font-size: 11px;
}

.span-2 {
    grid-column: span 2;
}

.field-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 16px;
    border: 1px dashed #cbd5e5;
    border-radius: 12px;
    background: #f8faff;
}

.is-hidden {
    display: none !important;
}

.alert {
    margin-bottom: 18px;
    padding: 12px 15px;
    border: 1px solid #cfd9ec;
    border-radius: 11px;
    background: #edf3ff;
    color: #3158c5;
    font-weight: 600;
}

.alert-success {
    border-color: #bce9d6;
    background: #e7f9f1;
    color: #08734f;
}

.alert-error {
    border-color: #f4c2c7;
    background: #fff0f1;
    color: #a82e3a;
}

.generated-panel {
    margin-bottom: 22px;
    border-color: #bcd0ff;
}

.code-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-height: 500px;
    padding: 18px 22px 22px;
    overflow-y: auto;
}

.code-grid article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid #e0e6f1;
    border-radius: 10px;
    background: #f9fbff;
}

.code-grid code {
    overflow: hidden;
    color: #244cb8;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
}

.code-grid a {
    flex: 0 0 auto;
    font-size: 11px;
}

.detail-heading {
    display: flex;
    justify-content: space-between;
    margin-bottom: 18px;
}

.back-link {
    display: inline-block;
    margin-bottom: 9px;
    color: #728099;
    font-size: 12px;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.title-row h2 {
    margin: 0;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 22px;
}

.subtle {
    color: #7d899d;
    font-size: 12px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.info-grid article {
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.info-grid span,
.info-grid strong {
    display: block;
}

.info-grid span {
    margin-bottom: 5px;
    color: #7d899d;
    font-size: 11px;
}

.info-grid strong {
    font-size: 13px;
}

.state-summary,
.inline-action,
.revoke-box {
    margin: 18px 20px;
}

.state-summary p {
    margin: 10px 0 0;
    color: var(--muted);
}

.inline-action {
    display: grid;
    gap: 10px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.revoke-box {
    display: grid;
    gap: 10px;
    padding: 16px;
    border: 1px solid #f2c4c9;
    border-radius: 12px;
    background: #fff7f7;
}

.revoke-box p {
    margin: 0;
    color: #84525a;
    font-size: 12px;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #84525a;
    font-size: 12px;
}

.check-label input {
    width: 16px;
    min-height: 16px;
}

.text-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-weight: 700;
}

.danger-text {
    color: var(--red);
}

details summary {
    color: var(--primary);
    cursor: pointer;
    font-size: 11px;
}

details pre {
    max-width: 520px;
    max-height: 180px;
    margin: 8px 0 0;
    padding: 10px;
    overflow: auto;
    border-radius: 8px;
    background: #111827;
    color: #d9e2f1;
    font-size: 10px;
    white-space: pre-wrap;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 18px 20px;
    border-top: 1px solid var(--line);
}

.pagination a {
    display: grid;
    min-width: 32px;
    height: 32px;
    place-items: center;
    padding-inline: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: #657187;
    font-size: 11px;
}

.pagination a.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.pagination a.disabled {
    pointer-events: none;
    opacity: .45;
}

.pagination span {
    margin-left: 7px;
    color: #8a96aa;
    font-size: 11px;
}

.narrow-panel {
    max-width: 620px;
}

.stack-form {
    display: grid;
    gap: 17px;
    padding: 22px;
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(67, 107, 235, .18), transparent 32%),
        radial-gradient(circle at 80% 80%, rgba(124, 58, 237, .12), transparent 30%),
        #eef3fb;
}

.login-card {
    width: min(100%, 440px);
    padding: 30px;
    border: 1px solid rgba(211, 220, 235, .9);
    border-radius: 22px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 24px 70px rgba(29, 47, 82, .16);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
}

.login-brand h1 {
    margin: 2px 0;
    font-size: 24px;
}

.login-brand p:last-child {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.login-card .stack-form {
    padding: 0;
}

.login-help {
    margin: 20px 0 0;
    color: #8a96aa;
    font-size: 11px;
    text-align: center;
}

.login-help code {
    color: #5d6b82;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 100;
    padding: 12px 17px;
    border-radius: 10px;
    background: #172033;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .18);
    color: #fff;
    opacity: 0;
    transform: translateY(10px);
    transition: .2s ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.clipboard-helper {
    position: fixed;
    left: -9999px;
    top: 0;
}

@media (max-width: 1180px) {
    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-column,
    .detail-columns {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 780px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        z-index: 50;
        left: 0;
        top: 0;
        transform: translateX(-105%);
        transition: transform .2s ease;
    }

    .nav-open .sidebar {
        transform: translateX(0);
    }

    .menu-toggle {
        display: inline-grid;
        place-items: center;
    }

    .topbar {
        min-height: 86px;
        padding: 16px 18px;
    }

    .topbar .button-primary {
        display: none;
    }

    .topbar h1 {
        font-size: 20px;
    }

    .content {
        padding: 20px 16px 32px;
    }

    .footer {
        gap: 8px;
        padding-inline: 16px;
    }

    .panel-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .filter-bar,
    .filter-bar input,
    .filter-bar select,
    .filter-bar input[type="number"] {
        width: 100%;
    }

    .code-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .stat-grid,
    .info-grid,
    .form-grid,
    .field-group {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .stat-card {
        min-height: 132px;
    }

    .footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .login-card {
        padding: 23px;
    }
}
