:root {
    --bg: #f4f6f7;
    --panel: #ffffff;
    --text: #202a2f;
    --muted: #68767d;
    --line: #dce2e5;
    --primary: #087f78;
    --primary-dark: #056a64;
    --danger: #bd2c2c;
    --warning: #a35c00;
    --success: #147a42;
    --shadow: 0 1px 3px rgba(22, 34, 40, .08);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.topbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 28px;
    color: #fff;
    background: #26343a;
    border-bottom: 3px solid var(--primary);
}
.brand { color: #fff; font-size: 17px; font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-self: stretch; }
.nav a { display: flex; align-items: center; padding: 0 16px; color: #dbe3e6; }
.nav a:hover, .nav a.active { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.account { margin-left: auto; display: flex; gap: 14px; align-items: center; color: #bfcbd0; white-space: nowrap; }
.account a { color: #fff; }
.nav-toggle { display: none; border: 0; color: #fff; background: transparent; font-size: 22px; cursor: pointer; }

.page { width: min(1180px, calc(100% - 32px)); margin: 26px auto 50px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
h1 { margin: 0; font-size: 24px; line-height: 1.3; }
h2 { margin: 0 0 16px; font-size: 17px; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Courier New", monospace; }
.nowrap { white-space: nowrap; }

.panel {
    margin-bottom: 18px;
    padding: 20px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: var(--shadow);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel-header h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { min-height: 104px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-top: 3px solid #8b989e; border-radius: 6px; box-shadow: var(--shadow); }
.stat strong { display: block; margin-top: 6px; font-size: 28px; line-height: 1.15; }
.stat-active { border-top-color: var(--success); }
.stat-unused { border-top-color: #477cba; }
.stat-expired { border-top-color: var(--warning); }
.stat-revoked { border-top-color: var(--danger); }
.stat-online { border-top-color: var(--primary); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-full { grid-column: 1 / -1; }
label { font-weight: 600; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    color: var(--text);
    background: #fff;
    border: 1px solid #bfc9cd;
    border-radius: 4px;
    outline: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(8,127,120,.12); }
textarea { min-height: 180px; resize: vertical; }
.help { margin: 0; color: var(--muted); font-size: 13px; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.btn {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    color: #fff;
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.2;
}
.btn:hover { color: #fff; background: var(--primary-dark); text-decoration: none; }
.btn-secondary { color: var(--text); background: #fff; border-color: #b9c4c8; }
.btn-secondary:hover { color: var(--text); background: #eef2f3; }
.btn-danger { background: #fff; border-color: #d6a0a0; color: var(--danger); }
.btn-danger:hover { background: #fff1f1; color: #9e1e1e; }
.btn-small { min-height: 30px; padding: 5px 9px; font-size: 13px; }

.notice { margin-bottom: 18px; padding: 12px 14px; border-left: 4px solid #477cba; background: #eaf2fb; }
.notice-success { border-color: var(--success); background: #eaf7f0; }
.notice-error { border-color: var(--danger); background: #fff0f0; }
.notice-warning { border-color: var(--warning); background: #fff6e8; }

.filters { display: grid; grid-template-columns: minmax(220px, 1fr) 180px auto; gap: 10px; margin-bottom: 14px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: #536168; background: #f7f9fa; font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: #fafcfc; }
.badge { display: inline-block; min-width: 58px; padding: 3px 7px; text-align: center; border-radius: 3px; font-size: 12px; }
.badge-unused { color: #315f91; background: #e9f2fb; }
.badge-active { color: #0e6635; background: #e6f5ec; }
.badge-expired { color: #895000; background: #fff2d8; }
.badge-revoked { color: #992525; background: #fce8e8; }
.online-dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: #9ba5aa; }
.online-dot.yes { background: #20a45b; box-shadow: 0 0 0 3px rgba(32,164,91,.13); }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.empty { padding: 34px 15px; text-align: center; color: var(--muted); }
.secret { word-break: break-all; padding: 10px; background: #f1f4f5; border: 1px solid var(--line); border-radius: 4px; }
.code-block { padding: 14px; overflow-x: auto; color: #e7edf0; background: #26343a; border-radius: 4px; white-space: pre-wrap; word-break: break-all; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-box { width: min(440px, 100%); padding: 28px; background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--primary); border-radius: 6px; box-shadow: 0 8px 28px rgba(29,48,56,.12); }
.auth-box h1 { margin-bottom: 8px; }
.auth-box .field { margin-top: 16px; }
.auth-box .btn { width: 100%; margin-top: 20px; }
.installer-shell { align-items: start; }
.installer-box { width: min(780px, 100%); margin: 18px 0; }
.installer-section { margin: 22px 0 0; padding: 18px; border: 1px solid var(--line); border-radius: 5px; }
.installer-section legend { padding: 0 8px; font-size: 16px; font-weight: 700; }
.installer-section .field { margin-top: 0; }
.installer-submit { min-height: 44px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }

@media (max-width: 900px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
    .nav-toggle { display: block; margin-left: auto; }
    .nav { display: none; order: 4; width: 100%; flex-direction: column; }
    .nav.open { display: flex; }
    .nav a { min-height: 42px; padding: 0 10px; }
    .account { margin-left: 0; }
}
@media (max-width: 650px) {
    .page { width: min(100% - 20px, 1180px); margin-top: 16px; }
    .stats, .form-grid, .filters { grid-template-columns: 1fr; }
    .field-full { grid-column: auto; }
    .panel { padding: 15px; }
    .stat { min-height: 88px; }
    .stat strong { font-size: 24px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .installer-box { padding: 18px 14px; }
    .installer-section { padding: 14px 10px; }
    .result-grid { grid-template-columns: 1fr; }
}
