:root {
    color-scheme: light;
    --bg: #f3f5f4;
    --surface: #ffffff;
    --ink: #17201d;
    --muted: #68736e;
    --line: #d8dfdc;
    --accent: #0d766d;
    --accent-dark: #075b54;
    --warn: #9a5b00;
    --danger: #a33a3a;
    --ok: #237452;
    --sidebar: #15201c;
    --sidebar-ink: #d9e3df;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.55 "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

.shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-ink);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.brand { font-size: 19px; font-weight: 700; letter-spacing: 0; }
.brand small { display: block; margin-top: 4px; color: #94aaa1; font-size: 12px; font-weight: 400; }
.nav { display: grid; gap: 4px; }
.nav a {
    color: var(--sidebar-ink);
    padding: 9px 11px;
    border-radius: 6px;
}
.nav a:hover, .nav a.active { background: #26362f; color: #fff; }
.sidebar-footer { margin-top: auto; color: #94aaa1; font-size: 12px; }

.main { min-width: 0; }
.topbar {
    min-height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.page-title { font-size: 18px; font-weight: 700; }
.topbar-meta { display: flex; align-items: center; gap: 14px; color: var(--muted); }
.content { padding: 26px 28px 48px; max-width: 1500px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}
.panel h2, .panel h3 { margin: 0 0 14px; font-size: 16px; }
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value { font-size: 28px; font-weight: 700; margin-top: 4px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-row { display: grid; gap: 6px; }
.form-row.full { grid-column: 1 / -1; }
label { color: #34413c; font-weight: 600; }
input, select, textarea {
    width: 100%;
    border: 1px solid #c8d1cd;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 9px 10px;
    font: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(13, 118, 109, .18);
    border-color: var(--accent);
}
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; }
textarea { min-height: 88px; resize: vertical; }
.hint { color: var(--muted); font-size: 12px; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 9px 14px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.button:hover { background: var(--accent-dark); color: #fff; }
.button.secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.button.secondary:hover { background: #f7f9f8; }
.button.danger { background: var(--danger); }
.button.small { padding: 6px 10px; font-size: 12px; }
.button:disabled { opacity: .55; cursor: not-allowed; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #e5eae7; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: #fafbfa; }
tbody tr:hover { background: #fbfcfb; }
.cell-wrap { white-space: normal; min-width: 180px; }

.badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid currentColor;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
}
.badge.unused { color: #66716c; }
.badge.active { color: var(--ok); }
.badge.expired { color: var(--warn); }
.badge.revoked { color: var(--danger); }
.badge.offline { color: #7d8581; }

.flash { padding: 11px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash.success { background: #e8f4ee; color: #175b3f; border: 1px solid #b8dccb; }
.flash.error { background: #fbecec; color: #812d2d; border: 1px solid #e6b9b9; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.pagination { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.code {
    font-family: Consolas, "SFMono-Regular", monospace;
    background: #f0f3f2;
    padding: 2px 6px;
    border-radius: 4px;
}
.key-reveal {
    font-family: Consolas, monospace;
    font-size: 18px;
    letter-spacing: 0;
    padding: 14px;
    background: #edf5f2;
    border: 1px solid #bcd8ce;
    border-radius: 6px;
    word-break: break-all;
}
.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 2px 4px 2px 0; }
.inline-form input, .inline-form select { width: auto; min-width: 70px; padding: 6px 8px; }
.key-list { min-height: 360px; font-family: Consolas, "SFMono-Regular", monospace; }
.mb-12 { margin-bottom: 12px; }
.mb-14 { margin-bottom: 14px; }
.mb-18 { margin-bottom: 18px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: #edf2ef;
    padding: 24px;
}
.auth-box {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
}
.auth-box h1 { margin: 0 0 6px; font-size: 24px; }
.auth-box p { margin: 0 0 22px; color: var(--muted); }
.auth-stack { display: grid; gap: 14px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (max-width: 980px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { padding: 14px; gap: 12px; }
    .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .sidebar-footer { display: none; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2, .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .topbar, .content { padding-left: 16px; padding-right: 16px; }
    .topbar { align-items: flex-start; padding-top: 14px; padding-bottom: 14px; flex-direction: column; }
    .grid-4 { grid-template-columns: 1fr; }
    .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
