:root {
  color-scheme: dark;
  --bg: #061221;
  --bg-accent: #0c294a;
  --card: #102238;
  --card-2: #132a45;
  --line: #24415f;
  --text: #edf6ff;
  --muted: #8fb6de;
  --primary: #4e8cff;
  --primary-2: #75b9ff;
  --green: #22c886;
  --yellow: #ffbf5b;
  --red: #ff667a;
  --shadow: 0 18px 50px rgba(0, 0, 0, .23);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f1e8;
  --bg-accent: #e8f1ed;
  --card: #fffdf7;
  --card-2: #f7f3e9;
  --line: #d8d4ca;
  --text: #263544;
  --muted: #647789;
  --primary: #3777d6;
  --primary-2: #2f6bbb;
  --green: #16885d;
  --yellow: #a36a12;
  --red: #c74255;
  --shadow: 0 18px 50px rgba(66, 69, 61, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: radial-gradient(circle at 8% 0%, var(--bg-accent), transparent 35rem), var(--bg);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
.shell { width: min(1420px, calc(100% - 40px)); margin-inline: auto; }
.page { padding-block: 34px 60px; }
.topbar { height: 72px; border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent); background: color-mix(in srgb, var(--bg) 87%, transparent); backdrop-filter: blur(18px); }
.topbar-inner { height: 100%; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 11px; font-size: 25px; font-weight: 850; letter-spacing: -.6px; }
.brand-dot { width: 15px; height: 15px; border-radius: 5px; background: linear-gradient(135deg, #4ee0d1, #4f8dff); box-shadow: 0 0 22px #4e8cff88; }
.top-actions, .toolbar, .inline-actions, .form-actions, .danger-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-actions form, .row-actions form, .inline-actions form, .danger-actions form { margin: 0; }
.card { background: color-mix(in srgb, var(--card) 96%, transparent); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 22px; }
.stat { min-height: 128px; padding: 25px; display: flex; flex-direction: column; justify-content: center; }
.stat span { color: var(--muted); font-size: 16px; }
.stat strong { margin-top: 5px; font-size: clamp(28px, 3vw, 38px); letter-spacing: -1.2px; }
.panel { padding: 26px; }
.panel-head, .page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.panel-head h1, .page-heading h1, .form-card h1 { margin: 2px 0 3px; font-size: 28px; }
.panel-head p { margin: 0; }
.eyebrow { color: var(--primary-2); font-size: 11px; font-weight: 800; letter-spacing: 1.7px; }
.muted, label small { color: var(--muted); }
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 11px; padding: 8px 15px; color: var(--text); background: var(--card-2); cursor: pointer; font-weight: 700; white-space: nowrap; transition: transform .15s ease, border-color .15s ease, filter .15s ease; }
.button:hover { transform: translateY(-1px); border-color: var(--primary); filter: brightness(1.06); }
.button.primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button.ghost { background: color-mix(in srgb, var(--card-2) 76%, transparent); }
.button.warning { color: #fff; background: #9b651b; border-color: #b77d2b; }
.button.danger { color: #fff; background: #8e3040; border-color: #b64659; }
.button.compact { min-height: 36px; padding: 6px 11px; font-size: 13px; }
.button.full { width: 100%; }
.notice { padding: 12px 15px; border-radius: 12px; margin-bottom: 15px; }
.notice.warning { color: #ffe0aa; background: #6a461b88; border: 1px solid #a56a22; }
.user-list { border-top: 1px solid var(--line); }
.user-row { padding: 20px 0; border-bottom: 1px solid var(--line); }
.user-main { display: grid; grid-template-columns: 1.05fr .9fr 1.05fr .45fr; gap: 24px; align-items: center; }
.identity, .endpoint, .usage { min-width: 0; display: flex; flex-direction: column; }
.identity strong { font-size: 17px; }
.identity span, .endpoint span { color: var(--muted); }
.identity small, .endpoint small, .usage small { color: var(--muted); margin-top: 3px; }
.endpoint strong { overflow-wrap: anywhere; }
.progress { width: 100%; height: 7px; margin: 8px 0 2px; overflow: hidden; border: 0; border-radius: 99px; background: color-mix(in srgb, var(--line) 75%, transparent); appearance: none; }
.progress::-webkit-progress-bar { border-radius: 99px; background: color-mix(in srgb, var(--line) 75%, transparent); }
.progress::-webkit-progress-value { border-radius: 99px; background: linear-gradient(90deg, #4b83f1, #53d0bd); }
.progress::-moz-progress-bar { border-radius: 99px; background: linear-gradient(90deg, #4b83f1, #53d0bd); }
.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 70px; padding: 8px 10px; border-radius: 99px; font-size: 13px; font-weight: 750; }
.pill.active { color: #70f0bb; background: #0b583c; }
.pill.disabled { color: #c6d1dc; background: #3b4652; }
.pill.expired, .pill.limited { color: #ffb3bd; background: #652c37; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-left: calc(1.05 / 3.45 * 100% + 8px); }
.more-actions { flex-basis: 100%; }
.more-actions summary { color: var(--muted); cursor: pointer; width: max-content; padding-block: 7px; }
.detail-box { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 15px; border-radius: 12px; background: color-mix(in srgb, var(--card-2) 80%, transparent); }
.danger-actions { grid-column: 1 / -1; }
.empty { text-align: center; padding: 70px 20px; }
.empty h2 { margin-bottom: 2px; }
.narrow { max-width: 840px; margin: 0 auto; }
.form-card { padding: 26px; }
.form-card h2 { margin-top: 0; }
label { display: grid; gap: 7px; color: var(--text); font-weight: 700; }
label small { font-weight: 500; }
input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; color: var(--text); background: color-mix(in srgb, var(--bg) 72%, transparent); outline: none; }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.form-card > label + label, .form-card > label + .form-grid, .form-grid + .check-row { margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check-row { display: flex; align-items: flex-start; gap: 11px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.check-row input { width: 20px; min-height: 20px; margin-top: 2px; }
.check-row span { display: grid; }
.form-actions { justify-content: flex-end; margin-top: 24px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.info-list { margin: 0 0 22px; }
.info-list div { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; text-align: right; font-weight: 700; }
.log-panel { margin-top: 20px; }
.log-panel h2 { margin-top: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 13px; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 12px 15px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); }
.flash.success { color: #7ef0bd; border-color: #26775a; }
.flash.error { color: #ffb1bc; border-color: #894050; }
.login-wrap { min-height: calc(100vh - 170px); display: grid; place-items: center; }
.login-card { width: min(440px, 100%); padding: 32px; }
.login-card h1 { margin: 3px 0; font-size: 30px; }
.login-card p { margin: 0 0 24px; }
.login-card label + label { margin-top: 16px; }
.login-card .button { margin-top: 22px; }
.qr-dialog { width: min(430px, calc(100% - 30px)); padding: 28px; color: var(--text); text-align: center; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.qr-dialog::backdrop { background: #020a14cc; backdrop-filter: blur(5px); }
.qr-dialog img { width: min(300px, 100%); padding: 10px; border-radius: 12px; background: white; }
.dialog-close { position: absolute; top: 10px; right: 12px; border: 0; color: var(--muted); background: transparent; font-size: 28px; cursor: pointer; }

@media (max-width: 950px) {
  .user-main { grid-template-columns: 1fr 1fr; }
  .state { position: absolute; right: 0; top: 0; }
  .user-row { position: relative; padding-right: 85px; }
  .row-actions { padding-left: 0; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .shell { width: min(100% - 24px, 1420px); }
  .page { padding-top: 20px; }
  .topbar { height: 62px; }
  .brand { font-size: 21px; }
  .desktop-only, [data-theme-toggle] { display: none; }
  .summary-grid { grid-template-columns: 1fr; gap: 10px; }
  .stat { min-height: 96px; padding: 18px; }
  .panel { padding: 17px; }
  .panel-head, .page-heading { align-items: flex-start; }
  .panel-head { flex-direction: column; }
  .user-main, .form-grid, .detail-box { grid-template-columns: 1fr; gap: 13px; }
  .user-row { padding-right: 0; }
  .state { position: static; }
  .detail-box label, .danger-actions { grid-column: auto; }
  .top-actions { gap: 5px; }
  .top-actions .button { padding-inline: 9px; }
}
