:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #182230;
  --muted: #667085;
  --line: #dfe5ec;
  --primary: #1677ff;
  --primary-hover: #095fd1;
  --success: #14804a;
  --warning: #b54708;
  --danger: #c4320a;
  --sidebar: #111827;
  --sidebar-text: #d1d5db;
  --shadow: 0 12px 30px rgba(17, 24, 39, .08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101318;
  --surface: #181d24;
  --surface-soft: #202630;
  --text: #edf1f7;
  --muted: #a6b0bf;
  --line: #303846;
  --primary: #4d9cff;
  --primary-hover: #77b3ff;
  --success: #56c58a;
  --warning: #f7b955;
  --danger: #ff7b64;
  --sidebar: #0b0e13;
  --sidebar-text: #c9d1dc;
  --shadow: 0 16px 36px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }

.topbar { height: 64px; display: flex; align-items: center; gap: 16px; padding: 0 24px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); position: sticky; top: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 11px; font-weight: 750; white-space: nowrap; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: white; background: var(--primary); border-radius: 7px; font-weight: 800; }
.topbar-spacer { flex: 1; }
.topbar-user { color: var(--muted); font-size: 14px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--surface); display: inline-grid; place-items: center; }
.icon-button:hover { border-color: var(--primary); color: var(--primary); }

.app-shell { display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: calc(100vh - 64px); transition: grid-template-columns .2s ease; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 20px 12px; overflow: hidden; }
.sidebar-section { margin: 18px 10px 8px; color: #7f8a99; font-size: 11px; text-transform: uppercase; }
.sidebar a { display: flex; align-items: center; gap: 12px; min-height: 42px; margin: 3px 0; padding: 0 12px; border-radius: 6px; font-size: 14px; white-space: nowrap; }
.sidebar a:hover, .sidebar a.active { color: white; background: #263142; }
.nav-icon { width: 20px; flex: 0 0 20px; text-align: center; font-size: 16px; }
.sidebar-collapsed .app-shell { grid-template-columns: 68px minmax(0, 1fr); }
.sidebar-collapsed .sidebar .nav-label, .sidebar-collapsed .sidebar-section { display: none; }
.sidebar-collapsed .sidebar a { justify-content: center; padding: 0; }
.content { padding: 28px; min-width: 0; }
.content-inner { width: min(1180px, 100%); margin: 0 auto; }

.page-header { display: flex; align-items: flex-start; gap: 20px; justify-content: space-between; margin-bottom: 22px; }
.page-header h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.3; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.button { min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 650; }
.button:hover { border-color: var(--primary); }
.button.primary { color: white; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.button.small { min-height: 34px; padding: 0 11px; font-size: 13px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 1px 2px rgba(17, 24, 39, .03); }
.card-header { padding: 17px 19px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header h2 { margin: 0; font-size: 16px; }
.card-body { padding: 19px; }
.stat { padding: 18px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 8px; font-size: 28px; line-height: 1; font-weight: 760; }
.stat-meta { margin-top: 9px; color: var(--muted); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 650; }
.field small { color: var(--muted); line-height: 1.5; }
.input, .select, .textarea { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; color: var(--text); background: var(--surface); outline: none; }
.textarea { min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent); }
.password-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 42px; }
.password-wrap .input { border-radius: 6px 0 0 6px; }
.password-wrap .icon-button { border-radius: 0 6px 6px 0; border-left: 0; height: 42px; }

.alert { padding: 12px 14px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; line-height: 1.5; }
.alert.success { color: var(--success); background: color-mix(in srgb, var(--success) 8%, var(--surface)); border-color: color-mix(in srgb, var(--success) 28%, var(--line)); }
.alert.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 28%, var(--line)); }
.alert.warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 8%, var(--surface)); border-color: color-mix(in srgb, var(--warning) 28%, var(--line)); }
.badge { display: inline-flex; min-height: 24px; align-items: center; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 650; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); }
.badge.success { color: var(--success); }
.badge.danger { color: var(--danger); }
.badge.warning { color: var(--warning); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { min-height: 48px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table th { color: var(--muted); background: var(--surface-soft); font-weight: 650; }
.table tr:last-child td { border-bottom: 0; }
.empty { padding: 42px 20px; color: var(--muted); text-align: center; }
.code-box { padding: 16px; border: 1px dashed var(--primary); border-radius: 6px; background: color-mix(in srgb, var(--primary) 6%, var(--surface)); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

.install-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, .82fr) minmax(520px, 1.18fr); }
.install-aside { padding: 54px; background: #121a27; color: white; display: flex; flex-direction: column; justify-content: space-between; }
.install-aside h1 { margin: 26px 0 12px; font-size: 34px; }
.install-aside p { color: #aeb9c8; line-height: 1.8; }
.install-points { display: grid; gap: 15px; margin-top: 36px; }
.install-point { display: flex; gap: 12px; align-items: flex-start; }
.install-check { width: 22px; height: 22px; flex: 0 0 22px; display: grid; place-items: center; border-radius: 50%; background: #1c7c4d; font-size: 12px; }
.install-main { padding: 36px; display: grid; place-items: center; background: var(--bg); }
.install-panel { width: min(760px, 100%); }
.install-panel .card { box-shadow: var(--shadow); }
.requirements { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.requirement { padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); font-size: 12px; display: flex; gap: 7px; align-items: center; }
.requirement.ok { color: var(--success); }
.requirement.bad { color: var(--danger); }
.auth-shell { min-height: calc(100vh - 64px); padding: 42px 20px; display: grid; place-items: center; }
.auth-card { width: min(440px, 100%); box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 8px; font-size: 25px; }
.auth-card .subtitle { color: var(--muted); margin: 0 0 24px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 15px; color: var(--primary); font-size: 13px; }
.hero { min-height: calc(100vh - 64px); padding: 72px 28px; display: grid; align-items: center; border-bottom: 1px solid var(--line); background: var(--surface); }
.hero-inner { width: min(1120px, 100%); margin: auto; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr); gap: 64px; align-items: center; }
.hero h1 { margin: 0 0 18px; font-size: 50px; line-height: 1.14; }
.hero p { margin: 0 0 28px; max-width: 650px; color: var(--muted); font-size: 18px; line-height: 1.8; }
.hero-console { border: 1px solid var(--line); background: var(--surface-soft); border-radius: 8px; padding: 22px; box-shadow: var(--shadow); }
.hero-console-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hero-console-row:last-child { border-bottom: 0; }
.public-flash { width: min(760px, calc(100% - 32px)); margin: 16px auto 0; }
.auth-form { display: grid; gap: 14px; margin-top: 16px; }
.auth-gap { margin-top: 15px; }
.auth-submit { width: 100%; margin-top: 18px; }
.email-code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.section-gap { margin-top: 18px; }
.muted, small { color: var(--muted); }
.link { color: var(--primary); font-weight: 650; }
.account-list { display: grid; gap: 16px; }
.account-card .card-header small { display: block; margin-top: 5px; color: var(--muted); }
.account-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.account-meta div { display: grid; gap: 5px; min-width: 0; }
.account-meta span { color: var(--muted); font-size: 12px; }
.account-meta b { overflow-wrap: anywhere; }
.code-inline { margin: 10px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 19px; }
.card-codes { white-space: pre-wrap; max-height: 260px; overflow: auto; margin: 12px 0; }
.qr-panel { min-height: 330px; display: grid; place-items: center; text-align: center; }
.qr-panel img { display: block; width: min(300px, 100%); aspect-ratio: 1; object-fit: contain; background: white; border: 1px solid var(--line); }
.json-view { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.quick-link { padding: 22px; display: grid; gap: 8px; }
.quick-link:hover { border-color: var(--primary); }
.quick-link span { color: var(--muted); font-size: 13px; }
.inline-form { display: flex; align-items: center; gap: 7px; }
.select.compact { min-height: 34px; width: 118px; padding: 5px 8px; }
.check-list { display: grid; gap: 8px; }
.check-list > div { display: grid; grid-template-columns: 42px minmax(100px, .6fr) minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.check-list > div > span { color: var(--primary); }
.check-list small { overflow-wrap: anywhere; }
.button:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 900px) {
  .install-shell { grid-template-columns: 1fr; }
  .install-aside { padding: 28px; }
  .install-points { display: none; }
  .hero-inner { grid-template-columns: 1fr; gap: 36px; }
  .hero h1 { font-size: 38px; }
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .topbar { padding: 0 12px; }
  .topbar-user { display: none; }
  .app-shell, .sidebar-collapsed .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: flex; overflow-x: auto; padding: 8px; position: sticky; top: 64px; z-index: 20; }
  .sidebar-section { display: none; }
  .sidebar a { flex: 0 0 auto; padding: 0 12px; }
  .sidebar .nav-label { display: inline; }
  [data-sidebar-toggle] { display: none; }
  .content { padding: 18px 12px; }
  .page-header { display: grid; }
  .form-grid, .grid.cols-2, .grid.cols-3, .grid.cols-4, .requirements { grid-template-columns: 1fr; }
  .install-main { padding: 18px 12px; }
  .install-aside { padding: 22px; }
  .install-aside h1 { font-size: 27px; margin: 16px 0 8px; }
  .hero { padding: 48px 18px; }
  .hero h1 { font-size: 34px; }
  .account-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .email-code-row { grid-template-columns: 1fr; }
  .check-list > div { grid-template-columns: 42px 1fr; }
  .check-list small { grid-column: 1 / -1; }
}
