:root {
  color-scheme: dark;
  --background: #0f172a;
  --surface: #151f34;
  --surface-raised: #1c2941;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f8fafc;
  --muted: #a8b3c5;
  --accent: #34d399;
  --accent-dark: #064e3b;
  --danger: #f87171;
  --warning: #fbbf24;
  --radius: 18px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--background); }
body { min-height: 100dvh; margin: 0; color: var(--text); background: radial-gradient(circle at 85% 0%, #1e3a5f 0, transparent 36%), var(--background); }
button, input, select { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(52, 211, 153, 0.4); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-shell { display: grid; min-height: 100dvh; place-items: center; padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); }
.login-card { width: min(100%, 420px); padding: 28px 24px; border: 1px solid var(--border); border-radius: 24px; background: rgba(21, 31, 52, 0.92); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3); }
.brand-mark { display: grid; width: 48px; height: 48px; margin-bottom: 24px; place-items: center; border-radius: 15px; background: var(--accent); }
.brand-mark span { width: 18px; height: 18px; border: 4px solid var(--background); border-left-width: 8px; transform: skew(-8deg); }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0.14em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 28px; }
h2 { margin-bottom: 0; font-size: 24px; }
h3 { margin-bottom: 8px; font-size: 17px; }
.intro, .notice-card p, .dialog-body > p, .page-description { color: var(--muted); line-height: 1.6; }
.page-description { margin: -8px 0 16px; font-size: 14px; }
label { display: grid; gap: 8px; margin-top: 22px; color: var(--muted); font-size: 14px; font-weight: 600; }
input, select { width: 100%; min-height: 50px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: #0d1628; font-size: 16px; }
input:focus, select:focus { border-color: var(--accent); }

.button, .text-button, .refresh-button { min-height: 48px; border: 0; border-radius: 12px; color: var(--text); cursor: pointer; }
.button { width: 100%; padding: 0 18px; font-weight: 700; }
.button-primary { color: #052e25; background: var(--accent); }
.button-secondary { border: 1px solid var(--border); background: var(--surface-raised); }
.button.compact { width: auto; padding-inline: 16px; }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.login-card .button { margin-top: 8px; }
.text-button, .refresh-button { min-width: 56px; padding: 0 10px; color: var(--muted); background: transparent; }
.form-error { min-height: 22px; margin: 10px 0 0; color: #fecaca; font-size: 14px; line-height: 1.45; }

.app-shell { min-height: 100dvh; padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; padding: max(18px, env(safe-area-inset-top)) 18px 14px; border-bottom: 1px solid var(--border); background: rgba(15, 23, 42, 0.92); backdrop-filter: blur(18px); }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .eyebrow { font-size: 10px; }
.content { width: min(100%, 720px); margin: 0 auto; padding: 22px 16px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.summary-card, .notice-card, .list-card { border: 1px solid var(--border); border-radius: var(--radius); background: rgba(21, 31, 52, 0.92); }
.summary-card { min-height: 118px; padding: 18px 16px; }
.summary-card.accent { background: linear-gradient(145deg, var(--accent-dark), #0f3c39); }
.summary-card span { display: block; margin-bottom: 13px; color: var(--muted); font-size: 13px; }
.summary-card strong { font-variant-numeric: tabular-nums; font-size: clamp(24px, 8vw, 34px); line-height: 1; overflow-wrap: anywhere; }
.overview-users-panel { margin-top: 14px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(21, 31, 52, 0.92); }
.overview-users-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 16px 13px; border-bottom: 1px solid var(--border); }
.overview-users-heading .eyebrow { margin-bottom: 3px; font-size: 10px; }
.overview-users-heading h3 { margin: 0; font-size: 16px; }
.overview-users-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.overview-users-list { display: grid; }
.overview-user-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(88px, auto); align-items: center; gap: 10px; min-height: 66px; padding: 10px 16px; }
.overview-user-row + .overview-user-row { border-top: 1px solid var(--border); }
.overview-user-identity { display: grid; min-width: 0; gap: 3px; }
.overview-user-identity strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.overview-user-identity span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.overview-user-balance { display: grid; justify-items: end; gap: 2px; }
.overview-user-balance span { color: var(--muted); font-size: 10px; }
.overview-user-balance strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.overview-users-empty { padding: 24px 16px; color: var(--muted); text-align: center; }
.notice-card { margin-top: 14px; padding: 18px; }
.notice-card p { margin-bottom: 0; font-size: 14px; }
.search-field { margin: 0 0 16px; }
.session-filter { margin: 0 0 16px; }
.card-list { display: grid; gap: 12px; }
.list-card { padding: 16px; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title-row h3 { margin-bottom: 2px; }
.key-prefix { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.key-prefix-button { min-height: 44px; margin: 0 0 0 -8px; padding: 0 8px; border: 0; border-radius: 8px; color: var(--accent); background: transparent; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; text-align: left; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; touch-action: manipulation; }
.key-prefix-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.status-badge { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; color: #a7f3d0; background: rgba(6, 95, 70, 0.8); font-size: 12px; font-weight: 700; }
.status-badge.revoked, .status-badge.exhausted { color: #fecaca; background: rgba(127, 29, 29, 0.75); }
.status-badge.running { color: #052e25; background: #34d399; }
.status-badge.online { color: #d9f99d; background: rgba(63, 98, 18, 0.78); }
.status-badge.offline { color: #cbd5e1; background: #334155; }
.status-badge.ended, .status-badge.expired { color: #cbd5e1; background: #334155; }
.status-badge.prepared { color: #fde68a; background: #713f12; }
.user-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 15px 0; }
.user-metrics div { padding: 10px 12px; border-radius: 12px; background: #0d1628; }
.user-metrics span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 12px; }
.user-metrics strong { font-variant-numeric: tabular-nums; }
.card-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.card-actions button { min-height: 44px; padding: 0 8px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: var(--surface-raised); font-size: 13px; }
.card-actions .danger { color: #fecaca; border-color: rgba(248, 113, 113, 0.35); }
.session-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.user-time-meta { display: grid; gap: 4px; margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.pagination { display: grid; grid-template-columns: minmax(92px, 1fr) auto minmax(92px, 1fr); align-items: center; gap: 10px; margin-top: 16px; }
.pagination button { min-height: 46px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: var(--surface-raised); }
.pagination button:disabled { opacity: 0.4; }
.pagination span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; }
.provider-card { display: grid; gap: 14px; }
.provider-card .card-title-row { align-items: center; }
.provider-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.provider-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.provider-actions .button { min-width: 0; }
.provider-actions .danger-button { min-width: 76px; min-height: 48px; padding: 0 12px; border: 1px solid rgba(248, 113, 113, 0.35); border-radius: 12px; color: #fecaca; background: transparent; }
.empty-state { padding: 32px 20px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); text-align: center; }

.bottom-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 8px max(6px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: rgba(15, 23, 42, 0.96); backdrop-filter: blur(18px); }
.bottom-nav button { display: grid; min-height: 58px; place-items: center; align-content: center; gap: 2px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-size: 12px; }
.bottom-nav button[aria-current="page"] { color: var(--accent); background: rgba(52, 211, 153, 0.09); }
.nav-icon { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.bottom-nav button:first-child .nav-icon { fill: currentColor; stroke: none; }

dialog { width: min(calc(100% - 20px), 520px); max-height: calc(100dvh - 20px); margin: auto auto 0; padding: 0; border: 1px solid var(--border); border-radius: 24px 24px 0 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(4px); }
dialog form, .dialog-body { padding: 12px 20px max(22px, env(safe-area-inset-bottom)); }
.dialog-handle { width: 42px; height: 5px; margin: 0 auto 22px; border-radius: 99px; background: #475569; }
#dialog-fields label { margin-top: 16px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 16px; }
.generated-key { display: block; margin: 18px 0; padding: 16px; border: 1px solid rgba(52, 211, 153, 0.3); border-radius: 12px; color: #a7f3d0; background: #081a18; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 1.6; overflow-wrap: anywhere; user-select: all; }
.dialog-body .button + .button { margin-top: 10px; }
.toast { position: fixed; z-index: 40; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); left: 16px; padding: 13px 16px; border: 1px solid var(--border); border-radius: 13px; color: var(--text); background: #26344e; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); text-align: center; }

@media (min-width: 600px) {
  .content { padding-inline: 24px; }
  dialog { margin: auto; border-radius: 24px; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .topbar { position: static; }
  .content { padding-top: 14px; }
  dialog { max-height: calc(100dvh - 12px); overflow: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .button, .bottom-nav button, .card-actions button { transition: background-color 180ms ease, color 180ms ease, opacity 180ms ease; }
}
