:root {
    color-scheme: light;
    --font-ui: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
    --font-mono: "Cascadia Mono", "Cascadia Code", "Consolas", monospace;
    --bg: #f1eef6;
    --surface: #fffaff;
    --surface-2: #f6f2fb;
    --surface-3: #ece6f5;
    --line: rgba(36, 26, 61, 0.11);
    --line-strong: rgba(36, 26, 61, 0.2);
    --txt: #201833;
    --txt-2: #443858;
    --muted: #675d7c;
    --muted-2: #746a88;
    --accent: #5f7d00;
    --accent-bright: #d8ff3e;
    --accent-soft: rgba(168, 200, 0, 0.16);
    --accent-ink: #263000;
    --green: #0e9f6e;
    --green-soft: rgba(14, 159, 110, 0.12);
    --amber: #b66a00;
    --amber-soft: rgba(199, 119, 0, 0.12);
    --red: #cf3b45;
    --red-soft: rgba(207, 59, 69, 0.11);
    --blue: #2f6fd0;
    --blue-soft: rgba(47, 111, 208, 0.11);
    --radius: 12px;
    --shadow: 0 18px 50px rgba(36, 26, 61, 0.14);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background:
        radial-gradient(circle at 18% 8%, rgba(216, 255, 62, 0.14), transparent 30%),
        radial-gradient(circle at 82% 0%, rgba(74, 57, 112, 0.10), transparent 34%),
        var(--bg);
    color: var(--txt);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
em { font-style: normal; }

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

::selection { background: var(--accent-soft); color: var(--txt); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: var(--line-strong);
    background-clip: padding-box;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 18px;
}

.auth-card {
    width: min(420px, 100%);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 24px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--accent-bright);
    color: var(--accent-ink);
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.brand-sub {
    color: var(--muted-2);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.auth-card h1 {
    font-size: 25px;
    font-weight: 680;
    letter-spacing: -0.02em;
}

.auth-card > p {
    margin-top: 6px;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.6;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 22px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field > span {
    color: var(--txt-2);
    font-size: 11.5px;
    font-weight: 650;
}

.field small {
    color: var(--muted-2);
    font-size: 10.5px;
    line-height: 1.45;
}

.field input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    outline: none;
    background: var(--surface-2);
    color: var(--txt);
    font-size: 13px;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field input:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--accent-bright);
    color: var(--accent-ink);
    font-size: 12.5px;
    font-weight: 650;
    white-space: nowrap;
    transition: filter 0.15s, background 0.15s, border-color 0.15s;
}

.btn:hover { filter: brightness(1.04); }
.btn:disabled { opacity: 0.55; cursor: default; filter: none; }

.btn.secondary {
    border-color: var(--line);
    background: var(--surface);
    color: var(--txt-2);
}

.btn.secondary:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.btn.quiet {
    min-height: 30px;
    padding: 0 10px;
    border-color: var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 550;
}

.btn.quiet:hover { border-color: var(--line-strong); color: var(--txt-2); }

.btn.danger {
    border-color: var(--red-soft);
    background: var(--red-soft);
    color: var(--red);
}

.form-error,
.notice {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.5;
}

.form-error {
    border-color: var(--red-soft);
    background: var(--red-soft);
    color: var(--red);
}

.notice.ok {
    border-color: var(--green-soft);
    background: var(--green-soft);
    color: var(--green);
}

.notice.warn {
    border-color: var(--amber-soft);
    background: var(--amber-soft);
    color: var(--amber);
}

.auth-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 22px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--muted-2);
    font-size: 10.5px;
}

.auth-foot a { color: var(--muted); }
.auth-foot a:hover { color: var(--accent); }

.auth-note {
    margin-top: 12px;
    color: var(--muted-2);
    font-size: 10px;
    line-height: 1.5;
    text-align: center;
}

/* ------------------------------------------------------------ setup page */

.page-shell { min-height: 100vh; }

.page-head {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 250, 255, 0.88);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-head .brand-mark { width: 30px; height: 30px; }

.page-head .head-title {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.page-head .head-title b {
    font-size: 13px;
    font-weight: 680;
    letter-spacing: 0.01em;
}

.page-head .head-title span {
    color: var(--muted-2);
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.08em;
}

.page-head .head-spacer { flex: 1; }

.head-link {
    color: var(--muted);
    font-size: 11px;
}

.head-link:hover { color: var(--accent); }

.setup-wrap {
    width: min(760px, calc(100% - 32px));
    margin: 34px auto 60px;
}

.eyebrow {
    color: var(--accent);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.panel {
    margin-bottom: 16px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(36, 26, 61, 0.04);
}

.panel-head {
    margin-bottom: 18px;
}

.panel-head h1,
.panel-head h2 {
    margin-top: 4px;
    font-size: 22px;
    font-weight: 680;
    letter-spacing: -0.02em;
}

.panel-head p {
    max-width: 620px;
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

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

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
}

.form-actions .push { margin-left: auto; }

.setup-steps {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    color: var(--muted-2);
    font-size: 10.5px;
}

.step-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 1px solid var(--line);
    border-radius: 50%;
    font-family: var(--font-mono);
    font-size: 9px;
}

.step-dot.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.step-line {
    width: 28px;
    height: 1px;
    background: var(--line);
}

/* ------------------------------------------------------------ admin */

.admin-shell { min-height: 100vh; }

.admin-head {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 250, 255, 0.9);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.admin-head .head-title b { font-size: 13px; }

.admin-head .head-spacer { flex: 1; }

.admin-user {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 11px;
}

.admin-user b {
    color: var(--txt-2);
    font-weight: 650;
}

.admin-main {
    width: min(1400px, calc(100% - 40px));
    margin: 24px auto 60px;
}

.admin-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.admin-hero h1 {
    margin-top: 4px;
    font-size: 26px;
    font-weight: 680;
    letter-spacing: -0.025em;
}

.admin-hero p {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.refresh-state {
    color: var(--muted-2);
    font-family: var(--font-mono);
    font-size: 10px;
    white-space: nowrap;
}

.metric-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.metric {
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.metric b {
    display: block;
    color: var(--txt);
    font-size: 24px;
    font-weight: 680;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.metric span {
    display: block;
    margin-top: 3px;
    color: var(--muted-2);
    font-size: 10.5px;
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(340px, 0.9fr);
    gap: 16px;
    align-items: start;
}

.admin-panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.panel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.panel-bar h2 {
    font-size: 13px;
    font-weight: 680;
}

.panel-bar span {
    color: var(--muted-2);
    font-size: 10.5px;
}

.table-wrap { overflow: auto; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
    white-space: nowrap;
}

.admin-table th {
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--muted-2);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-align: left;
    text-transform: uppercase;
}

.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--txt-2);
    vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: var(--surface-2); }

.card-key {
    display: block;
    max-width: 230px;
    overflow: hidden;
    color: var(--txt);
    font-family: var(--font-mono);
    font-size: 10.5px;
    text-overflow: ellipsis;
}

.subline {
    display: block;
    margin-top: 2px;
    color: var(--muted-2);
    font-size: 9.5px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 9.5px;
    white-space: nowrap;
}

.badge.online { background: var(--green-soft); color: var(--green); }
.badge.offline { background: var(--surface-3); color: var(--muted-2); }
.badge.active { background: var(--green-soft); color: var(--green); }
.badge.disabled { background: var(--amber-soft); color: var(--amber); }
.badge.revoked { background: var(--red-soft); color: var(--red); }
.badge.neutral { background: var(--surface-3); color: var(--muted); }

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.actions .btn {
    min-height: 26px;
    padding: 0 8px;
    font-size: 9.5px;
}

.log-list {
    display: flex;
    flex-direction: column;
    max-height: 720px;
    overflow: auto;
}

.log-row {
    display: grid;
    grid-template-columns: 64px 74px minmax(0, 1fr) 88px;
    gap: 8px;
    align-items: start;
    padding: 9px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 10.5px;
}

.log-row:last-child { border-bottom: 0; }

.log-time {
    color: var(--muted-2);
    font-family: var(--font-mono);
    font-size: 9.5px;
    white-space: nowrap;
}

.log-actor {
    overflow: hidden;
    color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.log-action {
    color: var(--txt-2);
    overflow: hidden;
    text-overflow: ellipsis;
}

.log-action b {
    display: block;
    color: var(--txt);
    font-size: 10.5px;
    font-weight: 650;
}

.log-action small {
    display: block;
    margin-top: 1px;
    overflow: hidden;
    color: var(--muted-2);
    font-size: 9.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.log-ip {
    color: var(--muted-2);
    font-family: var(--font-mono);
    font-size: 9px;
    text-align: right;
}

.empty-state {
    padding: 34px 16px;
    color: var(--muted-2);
    font-size: 11px;
    text-align: center;
}

.server-info {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-top: 14px;
    color: var(--muted-2);
    font-family: var(--font-mono);
    font-size: 9.5px;
}

.server-info b { color: var(--muted); font-weight: 500; }

@media (max-width: 1040px) {
    .admin-grid { grid-template-columns: 1fr; }
    .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .auth-card { padding: 22px; }
    .page-head, .admin-head { padding: 0 14px; }
    .admin-main { width: calc(100% - 24px); margin-top: 16px; }
    .admin-hero { align-items: flex-start; flex-direction: column; gap: 6px; }
    .metric-strip { grid-template-columns: 1fr 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .panel { padding: 17px; }
    .admin-head .head-link { display: none; }
    .admin-user span { display: none; }
    .log-row { grid-template-columns: 54px 60px minmax(0, 1fr); }
    .log-ip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
