:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-subtle: #f8faf9;
  --text: #14201c;
  --text-muted: #5e6b66;
  --text-faint: #7b8883;
  --border: #d9e1de;
  --border-strong: #c5d0cc;
  --teal: #087d6c;
  --teal-dark: #066457;
  --teal-soft: #e2f3ee;
  --amber: #ad650f;
  --amber-soft: #fff1dc;
  --red: #b62f35;
  --red-dark: #94242a;
  --red-soft: #fde9ea;
  --blue-gray: #526979;
  --shadow-dialog: 0 24px 70px rgba(20, 32, 28, 0.2);
  --sidebar-width: 224px;
  --radius: 6px;
  font-family: "Noto Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: wait; opacity: .62; }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 50; left: 12px; top: 10px; transform: translateY(-160%); border-radius: 4px; background: var(--text); color: #fff; padding: 9px 12px; font-weight: 700; text-decoration: none; transition: transform 160ms ease; }
.skip-link:focus { transform: translateY(0); }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 3px solid rgba(8, 125, 108, .24); outline-offset: 2px; }

.eyebrow { margin: 0 0 3px; color: var(--text-muted); font-size: 12px; font-weight: 650; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 23px; line-height: 1.25; font-weight: 720; }
h2 { margin-bottom: 0; font-size: 17px; line-height: 1.35; font-weight: 700; }

.auth-shell { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-panel { width: min(100%, 390px); border: 1px solid var(--border); border-top: 3px solid var(--teal); border-radius: var(--radius); background: var(--surface); padding: 32px; box-shadow: 0 10px 36px rgba(20, 32, 28, .08); }
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--text); font-size: 17px; font-weight: 760; }
.brand-auth { margin-bottom: 44px; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 4px); align-items: end; gap: 3px; width: 18px; height: 18px; padding: 2px 1px; }
.brand-mark span { display: block; width: 4px; border-radius: 1px; background: var(--teal); }
.brand-mark span:nth-child(1) { height: 7px; }
.brand-mark span:nth-child(2) { height: 14px; }
.brand-mark span:nth-child(3) { height: 10px; background: var(--amber); }
.auth-heading { margin-bottom: 24px; }
.auth-heading h1 { font-size: 25px; }
.stack-form { display: grid; gap: 12px; }
.stack-form label, .form-field label, .dialog-body > label { color: var(--text-muted); font-size: 13px; font-weight: 650; }
.input-with-icon { position: relative; }
.input-with-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.input-with-icon input { padding-left: 42px; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); color: var(--text); padding: 9px 11px; transition: border-color 160ms ease, box-shadow 160ms ease; }
input:hover, select:hover, textarea:hover { border-color: #9eada7; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8, 125, 108, .12); outline: none; }
input[readonly] { background: var(--surface-subtle); color: #33423d; }
textarea { min-height: 112px; resize: vertical; }
.auth-status { display: flex; align-items: center; gap: 8px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; }

.button { min-height: 44px; border: 1px solid transparent; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 14px; font-weight: 680; transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { background: var(--teal); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--teal-dark); }
.button-secondary { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.button-secondary:hover:not(:disabled) { background: var(--surface-subtle); border-color: #aab7b2; }
.button-danger { background: var(--red); color: #fff; }
.button-danger:hover:not(:disabled) { background: var(--red-dark); }
.button-wide { width: 100%; }
.button-compact { min-height: 38px; padding: 7px 12px; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 5px; display: inline-grid; place-items: center; background: var(--surface); color: var(--text-muted); transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease; }
.icon-button:hover { border-color: var(--border-strong); background: var(--surface-subtle); color: var(--text); }
.text-button { min-height: 44px; border: 0; background: transparent; color: var(--teal); padding: 8px 0 8px 12px; font-weight: 680; }
.text-button:hover { color: var(--teal-dark); }

.app-shell { min-height: 100vh; min-height: 100dvh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: var(--sidebar-width); display: flex; flex-direction: column; border-right: 1px solid var(--border); background: #fbfcfc; padding: 18px 14px; }
.sidebar .brand { padding: 0 10px; margin-bottom: 30px; }
.nav-list { display: grid; gap: 4px; }
.nav-item { min-height: 44px; border: 1px solid transparent; border-radius: 5px; display: flex; align-items: center; gap: 11px; padding: 9px 11px; background: transparent; color: var(--text-muted); text-align: left; font-weight: 620; transition: background-color 160ms ease, color 160ms ease; }
.nav-item:hover { background: #edf2f0; color: var(--text); }
.nav-item.is-active { background: var(--teal-soft); color: var(--teal-dark); }
.nav-item.is-active .icon { stroke-width: 2.2; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding: 14px 4px 0 10px; border-top: 1px solid var(--border); }
.service-state { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; font-weight: 650; }
.sidebar-footer .icon-button { border-color: transparent; background: transparent; }
.status-dot { display: inline-block; width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--text-faint); box-shadow: 0 0 0 3px rgba(123, 136, 131, .12); }
.status-dot-live { background: var(--teal); box-shadow: 0 0 0 3px rgba(8, 125, 108, .13); }
.status-dot-wait { background: var(--amber); box-shadow: 0 0 0 3px rgba(173, 101, 15, .13); }
.status-dot-fail { background: var(--red); box-shadow: 0 0 0 3px rgba(182, 47, 53, .12); }

.main-area { min-height: 100vh; min-height: 100dvh; margin-left: var(--sidebar-width); padding: 26px clamp(22px, 3vw, 46px) 48px; }
.topbar { min-height: 58px; display: flex; align-items: center; justify-content: flex-start; gap: 12px; margin-bottom: 26px; }
.topbar > div:first-child { margin-right: auto; }
.page-loading { min-height: 160px; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--text-muted); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--teal); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.view { max-width: 1440px; margin: 0 auto; }
.signal-strip { min-height: 58px; display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); border-left: 3px solid var(--teal); border-radius: var(--radius); background: var(--surface); padding: 9px 16px; margin-bottom: 16px; }
.signal-label { display: flex; align-items: center; gap: 8px; padding-right: 16px; border-right: 1px solid var(--border); color: var(--text); font-weight: 700; }
.signal-step { display: flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.signal-line { height: 1px; min-width: 18px; flex: 1 1 42px; background: var(--border-strong); }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { position: relative; min-height: 124px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 16px 18px; display: grid; grid-template-rows: auto 1fr auto; }
.metric::before { content: ""; position: absolute; left: -1px; top: 17px; width: 3px; height: 30px; background: var(--blue-gray); border-radius: 0 2px 2px 0; }
.metric:nth-child(2)::before { background: var(--amber); }
.metric:nth-child(3)::before, .metric-accent::before { background: var(--teal); }
.metric > span { color: var(--text-muted); font-size: 12px; font-weight: 650; }
.metric strong { align-self: center; font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; font-size: 30px; line-height: 1; font-weight: 650; }
.metric small { color: var(--text-faint); font-size: 12px; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.panel, .table-frame, .plugin-list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.panel { min-width: 0; padding: 16px 18px 8px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading-tools { display: flex; align-items: center; gap: 12px; }
.section-heading-main { min-height: 48px; margin-bottom: 14px; }
.count-label { color: var(--text-muted); font-size: 12px; font-weight: 650; }
.failure-toolbar { min-height: 48px; display: flex; align-items: center; gap: 14px; margin-bottom: 10px; padding: 0 2px; }
.failure-toolbar .count-label { margin-right: auto; }
.select-toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; font-weight: 650; cursor: pointer; }
.select-toggle input, .failure-checkbox { width: 17px; height: 17px; margin: 0; accent-color: var(--teal); }
.failure-select-column, .failure-select-cell { width: 48px; }
.failure-message-cell { overflow: visible; white-space: normal; }
.failure-message { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.failure-message-details { min-width: 0; }
.failure-message-details summary { display: flex; align-items: center; gap: 5px; min-width: 0; cursor: pointer; list-style: none; }
.failure-message-details summary::-webkit-details-marker { display: none; }
.failure-message-details summary::before { content: ">"; flex: 0 0 auto; color: var(--text-faint); font-size: 13px; transition: transform 140ms ease; }
.failure-message-details[open] summary::before { transform: rotate(90deg); }
.failure-message-summary { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 680; }
.failure-message-full { max-height: 180px; overflow: auto; margin-top: 7px; padding: 8px 10px; border-left: 2px solid var(--border-strong); background: var(--surface-subtle); color: var(--text-muted); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.55; }
.failure-error { color: var(--red-dark); }
.compact-list { min-height: 244px; }
.compact-row { min-height: 57px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; border-top: 1px solid var(--border); }
.compact-row:first-child { border-top: 0; }
.compact-primary { min-width: 0; }
.compact-primary strong, .compact-primary span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-primary strong { font-size: 13px; font-weight: 680; }
.compact-primary span { margin-top: 2px; color: var(--text-muted); font-size: 12px; }
.compact-meta { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.empty-state { min-height: 180px; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--text-muted); text-align: center; }
.empty-state .icon { width: 24px; height: 24px; color: var(--text-faint); }
.empty-state strong { color: var(--text); font-size: 13px; }
.empty-state p { margin: 0; font-size: 12px; }

.table-frame { overflow: hidden; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { height: 52px; padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th { height: 42px; background: var(--surface-subtle); color: var(--text-muted); font-size: 11px; font-weight: 700; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }
td:last-child, th:last-child { text-align: right; }
.table-primary { display: block; overflow: hidden; text-overflow: ellipsis; font-weight: 680; }
.table-secondary { display: block; margin-top: 1px; color: var(--text-faint); font-size: 11px; }
.row-actions { display: inline-flex; align-items: center; gap: 6px; }
.row-action { width: 40px; height: 40px; }
.status-badge { min-height: 26px; display: inline-flex; align-items: center; gap: 7px; border-radius: 4px; padding: 3px 8px; color: var(--text-muted); background: #edf1ef; font-size: 11px; font-weight: 700; }
.status-badge.is-live { color: var(--teal-dark); background: var(--teal-soft); }
.status-badge.is-wait { color: #86500e; background: var(--amber-soft); }
.status-badge.is-fail { color: var(--red-dark); background: var(--red-soft); }
.status-badge .status-dot { width: 6px; height: 6px; box-shadow: none; }
.connection-label { margin-left: 6px; color: var(--text-muted); font-size: 11px; font-weight: 650; }
.connection-label.is-live { color: var(--teal-dark); }
.connection-label.is-wait { color: #86500e; }
.mono { font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.plugin-list { overflow: hidden; }
.plugin-row { min-height: 86px; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(240px, 2fr) auto auto; align-items: center; gap: 24px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.plugin-row:last-child { border-bottom: 0; }
.plugin-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.plugin-icon { width: 40px; height: 40px; border-radius: 5px; display: grid; place-items: center; color: var(--teal-dark); background: var(--teal-soft); }
.plugin-name strong, .plugin-name span { display: block; }
.plugin-name span, .plugin-description { color: var(--text-muted); font-size: 12px; }
.plugin-description { margin: 0; }
.permission-list { display: flex; flex-wrap: wrap; gap: 5px; }
.permission { border: 1px solid var(--border); border-radius: 4px; background: var(--surface-subtle); padding: 2px 6px; color: var(--text-muted); font-family: "Cascadia Mono", Consolas, monospace; font-size: 10px; }
.plugin-access { display: flex; align-items: center; gap: 18px; }
.plugin-access label { display: grid; gap: 4px; color: var(--text-faint); font-size: 10px; font-weight: 700; }
.plugin-access select { min-width: 84px; height: 34px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--text); padding: 0 26px 0 9px; font: inherit; font-size: 12px; font-weight: 750; }
.plan-badge { display: inline-flex; align-items: center; min-height: 23px; border: 1px solid var(--border-strong); border-radius: 4px; padding: 2px 7px; background: var(--surface-subtle); color: var(--text-muted); font-size: 10px; font-weight: 800; }
.plan-badge.is-mini { border-color: #6c9d8c; background: #edf7f2; color: #286956; }
.plan-badge.is-svip { border-color: #b18a36; background: #fff6dc; color: #755414; }
.install-count { min-width: 72px; text-align: right; }
.install-count strong, .install-count span { display: block; }
.install-count strong { font-family: "Cascadia Mono", Consolas, monospace; font-size: 18px; }
.install-count span { color: var(--text-faint); font-size: 10px; }

.dialog { width: min(calc(100% - 28px), 620px); max-height: calc(100vh - 28px); border: 0; border-radius: 7px; background: var(--surface); color: var(--text); padding: 0; box-shadow: var(--shadow-dialog); }
.dialog::backdrop { background: rgba(20, 32, 28, .46); }
.dialog-compact { width: min(calc(100% - 28px), 500px); }
.dialog-body { padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.dialog-heading .icon-button { margin: -6px -6px 0 0; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field { display: grid; gap: 6px; }
.form-field-wide { grid-column: 1 / -1; }
.control-row { display: flex; align-items: center; gap: 8px; }
.control-row select, .control-row input { min-width: 0; }
.control-row .icon-button { flex: 0 0 44px; }
.group-registration { display: grid; gap: 6px; margin-top: 16px; }
.group-registration > label { color: var(--text-muted); font-size: 12px; font-weight: 650; }
.check-field { min-height: 32px; display: inline-flex; align-items: center; gap: 9px; width: fit-content; color: var(--text-muted); font-size: 12px; cursor: pointer; }
.check-field input { width: 18px; min-height: 18px; height: 18px; accent-color: var(--teal); }
.field-error { margin: 2px 0 0; color: var(--red); font-size: 12px; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.dialog-copy { margin-bottom: 0; color: var(--text-muted); }
.success-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--teal-soft); color: var(--teal-dark); margin-bottom: 18px; }
.success-mark .icon { width: 22px; height: 22px; stroke-width: 2.4; }
.callback-heading { margin-bottom: 20px; }
.callback-heading p:last-child { margin: 8px 0 0; color: var(--text-muted); font-size: 13px; }
.copy-field { display: flex; gap: 8px; margin-top: 7px; }
.copy-field input { min-width: 0; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.generated-code-list { min-height: 210px; margin-top: 7px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; line-height: 1.65; white-space: pre; }

.toast-region { position: fixed; z-index: 50; right: 18px; bottom: 18px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: min(340px, calc(100vw - 36px)); max-width: 420px; border: 1px solid var(--border-strong); border-left: 3px solid var(--teal); border-radius: 5px; background: var(--surface); padding: 11px 14px; box-shadow: 0 8px 28px rgba(20, 32, 28, .14); color: var(--text); font-size: 13px; animation: toast-in 180ms ease-out; }
.toast.is-error { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 980px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .signal-strip { flex-wrap: wrap; }
  .signal-line { flex: 0 0 24px; }
  .plugin-row { grid-template-columns: minmax(180px, 1fr) minmax(220px, 2fr) auto; }
  .permission-list { grid-column: 2; }
}

@media (max-width: 720px) {
  body { padding-bottom: 72px; }
  input { font-size: 16px; }
  .sidebar { inset: auto 0 0 0; width: 100%; height: 68px; display: block; border-top: 1px solid var(--border); border-right: 0; padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .sidebar .brand, .sidebar-footer { display: none; }
  .nav-list { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
  .nav-item { min-height: 54px; justify-content: center; flex-direction: column; gap: 2px; padding: 4px 2px; font-size: 9px; white-space: nowrap; }
  .nav-item .icon { width: 19px; height: 19px; }
  .main-area { margin-left: 0; padding: 18px 14px 30px; }
  .topbar { margin-bottom: 20px; }
  .topbar .button span { display: none; }
  .topbar .button { width: 44px; padding: 0; }
  .signal-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 12px 14px; }
  .signal-label { grid-column: 1 / -1; border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 9px; }
  .signal-line { display: none; }
  .metrics-grid { gap: 8px; }
  .metric { min-height: 108px; padding: 13px 14px; }
  .metric strong { font-size: 25px; }
  .panel { padding: 14px 14px 6px; }
  .section-heading-main { margin-bottom: 10px; }
  .table-frame { border: 0; background: transparent; overflow: visible; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 8px; }
  tbody tr { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 6px 12px; }
  td, th { display: block; height: auto; min-height: 48px; padding: 8px 0; border-bottom: 1px solid var(--border); white-space: normal; overflow-wrap: anywhere; }
  td::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--text-faint); font-size: 10px; font-weight: 700; }
  td:nth-last-child(-n+2) { border-bottom: 0; }
  td:last-child:not([data-label]) { display: flex; align-items: end; justify-content: flex-end; text-align: right; }
  td:last-child:not([data-label])::before { display: none; }
  tbody tr:hover td { background: transparent; }
  .row-action { align-self: end; }
  .plugin-list { border: 0; background: transparent; display: grid; gap: 8px; }
  .plugin-row { grid-template-columns: 1fr auto; gap: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px; }
  .plugin-description { grid-column: 1 / -1; }
  .permission-list { grid-column: 1 / -1; }
  .plugin-access { grid-column: 1 / -1; justify-content: space-between; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field-wide { grid-column: auto; }
  .dialog-body { padding: 20px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .button { flex: 1 1 130px; }
}

@media (max-width: 420px) {
  .auth-shell { padding: 14px; }
  .auth-panel { padding: 26px 20px; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-width: 0; }
  .metric strong { font-size: 23px; }
  .compact-meta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
