:root {
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  font-synthesis: none;
  --frame: #f4f6f9;
  --surface: #fff;
  --surface-soft: #f6f8fb;
  --ink: #14263b;
  --muted: #516278;
  --line: #dee5ed;
  --control-line: #a4b0bf;
  --accent: #174fce;
  --accent-hover: #1644ae;
  --accent-soft: #e7effe;
  --nav-ink: #1744a1;
  --sidebar-text: #14213d;
  --sidebar-active: #2459dc;
  --sidebar-active-fill: #edf4ff;
  --action: #174fce;
  --action-hover: #1644ae;
  --action-ink: #fff;
  --selection: #c8dcff;
  --tag-ink: #415368;
  --tag-fill: #ecf0f4;
  --trend-ink: #174d99;
  --trend-fill: #e1edff;
  --positive-ink: #176044;
  --positive-fill: #dcf5e8;
  --attention-ink: #75520b;
  --attention-fill: #fff2ca;
  --risk-ink: #9b303c;
  --risk-fill: #fce6e7;
  --focus: #245ddb;
  --danger: #9e2434;
  --gutter: clamp(22px, 2.5vw, 38px);
  --sidebar-width: 208px;
  background: var(--frame);
  color: var(--ink);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --frame: #162238;
  --surface: #111827;
  --surface-soft: #1b2130;
  --ink: #f0f3fa;
  --muted: #acbbd0;
  --line: #303746;
  --control-line: #677d9a;
  --accent: #aac6ff;
  --accent-soft: #213856;
  --nav-ink: #c4d8ff;
  --sidebar-text: #e4eaf4;
  --sidebar-active: #b1ceff;
  --sidebar-active-fill: #192855;
  --action: #2857b0;
  --action-hover: #315fc4;
  --selection: #365686;
  --focus: #a8c4ff;
  --danger: #ff858b;
  --tag-ink: #ccd7e9;
  --tag-fill: #2a384d;
  --trend-ink: #bdd5ff;
  --trend-fill: #253b5d;
  --positive-ink: #a8e6c7;
  --positive-fill: #1c4037;
  --attention-ink: #ffe19a;
  --attention-fill: #44351c;
  --risk-ink: #ffc3ca;
  --risk-fill: #4f2b35;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p { margin: 0; }
::selection { color: var(--ink); background: var(--selection); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
h1 { font-size: 24px; line-height: 1.25; letter-spacing: -.025em; }
h2 { font-size: 16px; line-height: 1.4; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand, .workspace-tools, .page-heading, .dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand { flex-shrink: 0; font-size: 17px; font-weight: 700; }
.brand img { display: block; }
.brand-title { display: grid; gap: 2px; line-height: 1.2; }
.brand-title small { color: var(--muted); font-size: 11px; font-weight: 400; }

.workspace-shortcuts {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
  gap: 6px;
  min-width: 0;
}
.workspace-shortcuts a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.workspace-shortcuts a:hover { background: var(--surface-soft); }
.workspace-shortcuts a[aria-current="page"] {
  color: var(--sidebar-active);
  background: var(--sidebar-active-fill);
}
.workspace-shortcuts .nav-icon { width: 14px; height: 14px; flex-basis: 14px; }
.workspace-tools { justify-content: flex-end; min-width: 0; }
.workspace-customer {
  color: var(--muted);
  max-inline-size: min(28ch, 15vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout { max-width: 1000px; margin: clamp(28px, 8vw, 100px) auto 48px; padding: 0 20px; }
.layout:has(#workspace:not([hidden])) { max-width: none; margin: 0; padding: 0; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}

.auth { max-width: 438px; margin-inline: auto; }
.muted { color: var(--muted); margin-top: 8px; }
.error { color: var(--danger); }
form { display: grid; gap: 16px; margin-top: 24px; }
label { display: grid; gap: 6px; font-weight: 600; }
input, button { font: inherit; }
input {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--control-line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  caret-color: var(--accent);
}

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.primary, #submit { background: var(--action); color: var(--action-ink); }
.primary:hover, #submit:hover { background: var(--action-hover); }
.quiet { background: transparent; color: var(--ink); border-color: var(--control-line); }
.quiet:hover { background: var(--surface); }
button:disabled { opacity: .65; cursor: wait; }
.switch { margin-top: 16px; }
.theme-toggle {
  display: grid;
  place-items: center;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
}
.theme-track {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 46px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--control-line);
  border-radius: 999px;
  background: var(--surface-soft);
}
.theme-track::after {
  position: absolute;
  inset: 2px auto 2px 2px;
  width: 16px;
  border: 1px solid var(--control-line);
  border-radius: 50%;
  background: #fff;
  content: "";
}
.theme-track svg { width: 12px; height: 12px; }
.theme-sun { color: #9a5500; }
.theme-moon { color: var(--accent); visibility: hidden; }
.theme-toggle[aria-checked="true"] .theme-track::after { inset-inline-start: 24px; }
.theme-toggle[aria-checked="true"] .theme-track { background: #245bf0; border-color: #245bf0; }
.theme-toggle[aria-checked="true"] .theme-sun { visibility: hidden; }
.theme-toggle[aria-checked="true"] .theme-moon { color: #fff; visibility: visible; }

@media (prefers-reduced-motion: no-preference) {
  .theme-track::after { transition: inset-inline-start 140ms ease-out; }
}

#workspace {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: calc(100dvh - 56px);
}

.workspace-sidebar {
  position: sticky;
  top: 56px;
  align-self: start;
  height: calc(100dvh - 56px);
  overflow-y: auto;
  padding: 14px 12px 20px;
  scrollbar-color: var(--control-line) transparent;
  scrollbar-width: thin;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.workspace-sidebar nav { display: grid; gap: 12px; }
.nav-group { display: grid; gap: 2px; }
.nav-group + .nav-group { border-top: 1px solid var(--line); padding-top: 10px; }
.nav-group p { margin: 0 10px 4px; color: var(--muted); font-size: 12px; }
.nav-group a, .nav-section summary {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 400;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
}
.nav-icon { display: block; width: 16px; height: 16px; flex: 0 0 16px; fill: currentColor; }

.nav-group a:hover { background: var(--surface-soft); }
.nav-group a[aria-current="page"] {
  color: var(--sidebar-active);
  background: var(--sidebar-active-fill);
  font-weight: 600;
}
.nav-section summary {
  cursor: pointer;
}
.nav-section summary::-webkit-details-marker { display: none; }
.nav-section summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-inline-start: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
}
.nav-section[open] > summary::after { transform: rotate(45deg) translateY(-2px); }
.nav-section summary:hover { background: var(--surface-soft); }
.nav-section:has(a[aria-current="page"]) > summary { color: var(--sidebar-active); }
.nav-children { display: grid; gap: 2px; margin-top: 2px; }
.nav-children a { min-height: 36px; padding-inline-start: 41px; }

.workspace-content {
  align-self: start;
  min-width: 0;
  padding: var(--gutter);
}

.page-heading { justify-content: space-between; min-height: 36px; }
.account { margin-top: 20px; padding: 20px; }
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 5px;
  color: var(--tag-ink);
  background: var(--tag-fill);
  font-size: 12px;
  font-weight: 600;
}
.tag[data-tone="trend"] { color: var(--trend-ink); background: var(--trend-fill); }
.tag[data-tone="positive"] { color: var(--positive-ink); background: var(--positive-fill); }
.tag[data-tone="attention"] { color: var(--attention-ink); background: var(--attention-fill); }
.tag[data-tone="risk"] { color: var(--risk-ink); background: var(--risk-fill); }
.tag--level { justify-content: center; min-width: 27px; border-radius: 999px; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
th:last-child, td:last-child { text-align: right; }
.directory { padding: 0; }
.directory-header { padding: 14px 24px; border-bottom: 1px solid var(--line); }
.directory-header h1 { font-size: 18px; letter-spacing: 0; }
.directory-content { padding: 18px 24px 24px; }
.directory-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.directory-count { color: var(--muted); font-size: 13px; }
.directory table { table-layout: fixed; }
.directory th, .directory td { padding: 16px 14px; text-align: left; overflow-wrap: anywhere; }
.directory th:first-child { width: clamp(160px, 33%, 300px); border-start-start-radius: 6px; }
.directory th.account-check { width: 44px; }
.directory th:nth-child(2) { width: 165px; }
.directory td.account-id { white-space: nowrap; font-size: 13px; }
.account-check input, .available-accounts input { width: auto; margin: 0; accent-color: var(--accent); }
#qc-remove:disabled { cursor: default; }
#qc-manage-form .dialog-actions { margin-top: 0; }
.directory th:last-child { border-start-end-radius: 6px; }
.directory thead, #qc-accounts tr:nth-child(even) { background: var(--surface-soft); }
.account-table-scroll { overflow-x: auto; }
.directory table { min-width: 980px; }
.directory .account-delete { color: var(--danger); border-color: var(--danger); min-height: 30px; padding: 3px 8px; }
.selection-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.inline-check input[type="checkbox"] { width: auto; }
.inline-check input[type="number"] { width: 62px; }
.selection-table-scroll { max-height: 400px; overflow: auto; }
.selection-table-scroll table { min-width: 400px; }
.selection-table-scroll th:first-child { width: 36px; }
.selection-table-scroll input { width: auto; }
select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--control-line); border-radius: 6px; padding: 5px; }
#qc-empty td { padding-block: 30px; text-align: center; color: var(--muted); }
.account-id { color: var(--muted); font-variant-numeric: tabular-nums; }
.module-action { display: inline-block; margin-top: 12px; color: var(--accent); text-underline-offset: 3px; }
.plan-layout {
  display: grid;
  grid-template-columns: clamp(192px, 19vw, 240px) minmax(0, 1fr);
  margin-top: 14px;
  padding: 0;
  overflow: clip;
}
.plan-list, .plan-detail { min-width: 0; min-height: 170px; padding: 16px 18px; }
.plan-list { background: var(--surface-soft); border-right: 1px solid var(--line); }
.plan-detail h2 { padding-bottom: 12px; border-bottom: 1px solid var(--line); }

#qc-dialog, #qc-manage-dialog {
  width: min(440px, calc(100% - 32px));
  padding: 24px;
  border: 0;
  border-radius: 12px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 12px 44px rgba(20, 38, 59, .2);
}
#qc-dialog::backdrop, #qc-manage-dialog::backdrop { background: rgba(20, 38, 59, .35); }
#qc-manage-dialog { width: min(800px, calc(100% - 32px)); }
#qc-dialog { width: min(800px, calc(100% - 32px)); }
.authorization-dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.authorization-dialog-heading form { margin: 0; }
.dialog-close { padding: 6px; border: 0; }
.dialog-close svg { display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.authorization-launch-actions { display: flex; flex-direction: column; align-items: center; gap: 16px; padding-block: 32px 28px; text-align: center; }
.authorization-launch-actions p { margin: 0; }
.authorization-result-page { min-height: 100dvh; display: grid; place-items: center; margin: 0; padding: 24px; }
.authorization-result-card { width: min(476px, 100%); padding: 28px 32px; text-align: center; background: var(--surface); border-radius: 12px; box-shadow: 0 12px 36px rgba(20, 38, 59, .1); }
.authorization-result-card h1 { font-size: 20px; margin: 16px 0 10px; }
.authorization-result-card p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.authorization-result-icon { width: 48px; height: 48px; }
.authorization-result-icon circle { fill: #e6f7ef; }
.authorization-result-icon path { fill: none; stroke: #00a873; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.dialog-actions { justify-content: flex-end; margin-top: 24px; }
.dialog-actions form { margin: 0; }

@media (min-width: 681px) {
  .nav-group a, .nav-section summary { min-height: 44px; padding-inline-start: 20px; }
  .nav-children a { min-height: 38px; padding-inline-start: 48px; }
}

@media (min-width: 681px) and (max-width: 840px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .workspace-shortcuts a { gap: 4px; padding-inline: 5px; }
  .workspace-tools { gap: 8px; }
  .workspace-tools:has(#logout:not([hidden])) .workspace-customer { display: none; }
}

@media (max-width: 680px) {
  .topbar { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; padding-inline: 12px; }
  .workspace-shortcuts { grid-column: 1 / -1; grid-row: 2; justify-content: stretch; }
  .workspace-shortcuts a { flex: 1; min-height: 38px; gap: 4px; padding-inline: 3px; }
  .brand, .workspace-tools { gap: 8px; }
  .brand-title small { display: none; }
  .workspace-customer { max-inline-size: 20vw; font-size: 12px; }
  .layout:has(#workspace:not([hidden])) { padding: 0; }
  #workspace { display: flex; flex-direction: column; min-height: calc(100dvh - 56px); }
  .workspace-sidebar { position: static; align-self: stretch; height: auto; max-height: 220px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace-sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .nav-group { align-content: start; }
  .nav-group + .nav-group { border: 0; padding: 0; }
  .nav-group a { min-height: 42px; }
  .nav-children a { padding-inline-start: 16px; }
  .workspace-content { align-self: stretch; padding: 20px 16px; }
  .workspace-content h1 { font-size: 22px; }
  .directory-header h1 { font-size: 16px; }
  .directory-header, .directory-content { padding-inline: 12px; }
  .directory th, .directory td { padding: 12px 8px; }
  .directory th:first-child { width: 30%; }
  .directory th.account-check { width: 34px; }
  .directory .account-id { font-size: 12px; }
  .account { margin-top: 16px; padding: 16px; }
  .plan-layout { grid-template-columns: minmax(0, 1fr); margin-top: 14px; }
  .plan-list, .plan-detail { min-height: 0; padding: 16px; }
  .plan-list { border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar button { min-height: 42px; }
}

@media (max-width: 380px) {
  .workspace-tools:has(#logout:not([hidden])) .workspace-customer { display: none; }
}
