:root {
    color-scheme: light;
    --bg: #f3f5f7;
    --surface: #ffffff;
    --surface-alt: #f8fafb;
    --text: #1f252b;
    --muted: #65717c;
    --line: #d9e0e5;
    --primary: #1267a8;
    --primary-hover: #0d548d;
    --danger: #b4232a;
    --success: #177245;
    --warning: #9a5b00;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
    font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 0 28px;
    background: #17212a;
    color: #fff;
    border-bottom: 1px solid #0e171e;
}
.brand { font-size: 17px; font-weight: 650; color: #fff; white-space: nowrap; }
.nav { display: flex; height: 100%; align-items: center; gap: 8px; }
.nav a { color: #c9d3db; padding: 17px 12px 15px; border-bottom: 3px solid transparent; }
.nav a.active { color: #fff; border-bottom-color: #4ba3e3; }
.account { margin-left: auto; color: #c9d3db; }
.page { max-width: 1440px; margin: 0 auto; padding: 24px 28px 48px; }
.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.page-header h1 { font-size: 24px; margin: 0; letter-spacing: 0; }
.page-header .actions { margin-left: auto; display: flex; gap: 8px; }
.band { background: var(--surface); border: 1px solid var(--line); margin-bottom: 18px; }
.band-header { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 650; }
.band-body { padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); border: 1px solid var(--line); background: var(--surface); margin-bottom: 18px; }
.stat { padding: 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font-size: 25px; margin-bottom: 3px; }
.stat span { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px 16px; }
.field { min-width: 0; }
.field.wide { grid-column: span 2; }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
input, select, textarea {
    width: 100%;
    min-height: 36px;
    border: 1px solid #bdc8d0;
    background: #fff;
    color: var(--text);
    padding: 7px 9px;
    font: inherit;
    border-radius: 3px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #8ac4ed; border-color: var(--primary); }
button, .button {
    min-height: 36px;
    border: 1px solid var(--primary);
    border-radius: 3px;
    padding: 7px 13px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
button:hover, .button:hover { background: var(--primary-hover); text-decoration: none; }
button.secondary, .button.secondary { background: #fff; color: var(--text); border-color: #aebbc4; }
button.danger { background: #fff; color: var(--danger); border-color: #d59da1; }
button.small, .button.small { min-height: 28px; padding: 3px 8px; font-size: 12px; }
.inline { display: inline; }
.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.toolbar .field { min-width: 220px; }
.toolbar .field.compact { min-width: 150px; }
.filter-toolbar { margin-bottom: 14px; }
.list-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.bulk-toolbar { display: flex; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.bulk-spacer { flex: 1; }
.check-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 13px; }
.check-input { width: 16px; min-height: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--primary); }
.select-cell { width: 42px; text-align: center; vertical-align: middle; }
.empty-cell { padding: 36px 16px; text-align: center; color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-alt); color: #4c5963; font-size: 12px; font-weight: 650; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.actions-cell { display: flex; gap: 6px; white-space: nowrap; }
.mono { font-family: Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.status { font-size: 12px; font-weight: 650; }
.status.active, .status.ready { color: var(--success); }
.status.revoked, .status.failed { color: var(--danger); }
.status.pending { color: var(--warning); }
.flash { border: 1px solid #a6c8df; background: #edf7fd; padding: 12px 14px; margin-bottom: 16px; white-space: pre-wrap; }
.flash.error { border-color: #e1a7aa; background: #fff1f1; color: #8f1d24; }
.generated { width: 100%; min-height: 160px; font-family: Consolas, monospace; resize: vertical; }
.update-notes { grid-column: 1 / -1; }
.update-notes textarea { min-height: 230px; resize: vertical; line-height: 1.65; }
.update-toggle { min-height: 36px; padding: 7px 0; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); padding: 28px; }
.login-panel h1 { margin: 0 0 6px; font-size: 22px; }
.login-panel p { color: var(--muted); margin: 0 0 22px; }
.login-panel .field { margin-bottom: 14px; }
.login-panel button { width: 100%; }
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.page-summary { color: var(--muted); font-size: 13px; min-width: 180px; text-align: center; }
.page-jump { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; }
.page-jump label { margin: 0; white-space: nowrap; }
.page-input { width: 82px; min-height: 28px; height: 28px; padding: 3px 7px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.6; }
.nowrap { white-space: nowrap; }
.ticket-table { min-width: 1180px; }
.ticket-cell { min-width: 260px; max-width: 340px; }
.ticket-detail summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    list-style-position: outside;
}
.ticket-detail summary::marker { color: var(--primary); }
.ticket-length { margin-left: auto; white-space: nowrap; font-size: 11px; }
.ticket-full {
    margin-top: 9px;
    padding: 9px;
    max-height: 150px;
    overflow: auto;
    overflow-wrap: anywhere;
    white-space: normal;
    line-height: 1.55;
    color: #37434d;
    background: var(--surface-alt);
    border: 1px solid var(--line);
}
.request-log-band { margin-top: 24px; }
.error-code { white-space: nowrap; }

@media (max-width: 900px) {
    .topbar { height: auto; min-height: 56px; padding: 10px 16px; flex-wrap: wrap; gap: 10px; }
    .nav { order: 3; width: 100%; overflow-x: auto; }
    .nav a { padding: 8px 10px; }
    .page { padding: 18px 14px 36px; }
    .stats, .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat:nth-child(2) { border-right: 0; }
    .stat { border-bottom: 1px solid var(--line); }
}

@media (max-width: 560px) {
    .stats, .grid { grid-template-columns: 1fr; }
    .stat, .stat:nth-child(2) { border-right: 0; }
    .field.wide { grid-column: span 1; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .page-header .actions { margin-left: 0; }
    .bulk-toolbar { align-items: stretch; flex-wrap: wrap; }
    .bulk-spacer { display: none; }
    .page-jump { width: 100%; justify-content: center; margin-left: 0; }
}
