:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);

  --ink: #172033;
  --muted: #505d73;
  --surface: #fff;
  --canvas: #f4f6fa;
  --border: #dde3ed;
  --line: #eef1f6;
  --neutral-soft: #f0f3f8;
  --accent: #3452c5;
  --accent-hover: #2942a5;
  --accent-soft: #edf2ff;
  --accent-border: #cbd8fc;
  --focus: #4565d2;
  --success: #16634f;
  --success-soft: #eaf7f2;
  --danger: #a02b3a;
  --danger-soft: #fdf0f2;
  --warning: #755013;
  --warning-soft: #fff6e5;
  --radius: 13px;
  --section-pad: 21px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, h3, p { margin: 0; }
body { min-width: 0; }
button, input, textarea { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible,
summary:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
button svg, summary svg { flex-shrink: 0; }
svg { vertical-align: middle; }

/* Shared controls */
.button,
.icon-button,
.sidebar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
}
.button { padding: 8px 12px; }
.button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.sidebar-link:hover:not(:disabled) {
  background: var(--canvas);
  border-color: #c6d0e0;
}
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.button.small { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.button.link {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.button.link:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: transparent;
}
.button.danger {
  background: var(--surface);
  border-color: #ead4d5;
  color: var(--danger);
}
.button.danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: #dfb9bb;
}
.button.primary.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.button.primary.danger:hover:not(:disabled) {
  background: #89232b;
  border-color: #89232b;
}
.icon-button { width: 34px; min-height: 34px; padding: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--neutral-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.4;
}
.badge.muted { background: var(--neutral-soft); color: var(--muted); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* Account directory */
.shell {
  display: grid;
  grid-template-columns: 242px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 19px;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  padding: 22px 16px 18px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar-brand-row,
.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}
.sidebar-brand-row { justify-content: space-between; }
.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  background: var(--ink);
  color: white;
  border-radius: 9px;
}
.brand-mark svg { width: 23px; height: 23px; }
.brand-title { font-size: 15px; font-weight: 720; letter-spacing: -.025em; }
.sidebar-link { min-height: 32px; padding: 6px 8px; color: var(--muted); font-size: 12px; }
.sidebar-brand-row .sidebar-link { flex: 0 0 auto; }

.account-directory {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
  min-height: 0;
}
.directory-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.account-search {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
}
.account-search:focus-within { border-color: var(--focus); }
.account-search svg { flex-shrink: 0; }
.account-search input {
  width: 100%;
  min-width: 0;
  padding: 6px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}
.account-search input:focus-visible { outline: none; }
.account-search input::placeholder,
.text-input::placeholder,
.form-textarea::placeholder { color: #626f84; }

.account-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  min-height: 0;
  padding: 2px 3px;
  overflow: auto;
  scrollbar-width: thin;
}
.account-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-width: 0;
  padding: 9px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--ink);
  text-align: left;
}
.account-item:hover { background: var(--neutral-soft); }
.account-item.selected { background: var(--accent-soft); border-color: var(--accent-border); }
.account-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--neutral-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.account-item.selected .account-avatar { background: #dce6ff; color: var(--accent); }
.account-item-details {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.account-item-title,
.account-item-subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-item-title { font-size: 13px; font-weight: 650; }
.account-item-subtitle { color: var(--muted); font-size: 11px; }
.account-status {
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8794a9;
}
.account-status.is-connected { background: var(--success); }
.account-status.has-error { background: #a16a22; }
.directory-empty { padding: 11px 4px; color: var(--muted); font-size: 13px; }
.sidebar > .button { width: 100%; }

/* Workspace and navigation */
.workspace { min-width: 0; }
.main { width: min(100%, 1200px); margin: 0 auto; padding: 32px clamp(20px, 3vw, 39px) 26px; }
.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 21px;
}
.page-heading-content { flex: 1 1 auto; min-width: 0; }
.page-heading h1 {
  color: var(--ink);
  font-size: clamp(23px, 2.8vw, 31px);
  font-weight: 740;
  line-height: 1.22;
  letter-spacing: -.04em;
}
.account-page-title {
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.account-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 9px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}
.account-meta > * { min-width: 0; overflow-wrap: anywhere; }
.account-meta .badge:not(.muted) { background: var(--success-soft); color: var(--success); }
.heading-actions,
.account-utilities {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.heading-actions { justify-content: flex-end; }
.eyebrow {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 680;
  letter-spacing: .06em;
}
.account-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 17px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--border);
}
.workspace-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 31px;
  padding: 5px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.tab-button:hover { background: var(--canvas); }
.tab-button.active, .tab-button[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.account-utilities { justify-content: flex-end; }
.account-utilities .button { min-height: 32px; padding: 5px 8px; font-size: 12px; }

.account-more { position: relative; max-width: 100%; }
.account-more > summary { display: inline-flex; list-style: none; cursor: pointer; }
.account-more > summary::-webkit-details-marker { display: none; }
.account-more[open] > summary { background: var(--accent-soft); }
.account-more:not([open]) .account-more-menu { display: none; }
.account-more-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  gap: 2px;
  width: max-content;
  min-width: 160px;
  max-width: calc(100vw - 32px);
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px #1720331a;
}
.account-more-menu > .button {
  justify-content: flex-start;
  width: 100%;
  border-color: transparent;
  text-align: left;
}

/* Cards and account data */
.overview-main { display: grid; min-width: 0; gap: 14px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px #17203306;
}
.full-card { margin-bottom: 14px; }
.stat-card { min-height: 111px; padding: 15px 17px; }
.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
}
.stat-top svg { flex-shrink: 0; color: var(--muted); }
.stat-main, .quota-value {
  color: var(--ink);
  font-size: 26px;
  font-weight: 720;
  line-height: 1.25;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
}
.stat-main { margin-top: 8px; }
.stat-main .unit { margin-left: 5px; color: var(--muted); font-size: 12px; font-weight: 500; letter-spacing: 0; }
.stat-label, .section-subtitle { margin-top: 4px; color: var(--muted); font-size: 12px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px 14px;
  padding: 16px var(--section-pad) 13px;
}
.section-header > div:first-child { min-width: 0; }
.section-header h2 { color: var(--ink); font-size: 16px; font-weight: 700; }
.section-header > .button { flex: 0 0 auto; }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 5px 12px;
  padding: 9px var(--section-pad);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.card-footer .button { min-height: 29px; padding: 4px 6px; font-size: 12px; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 13px;
  padding: 9px 11px;
  border: 1px solid #e9dbbb;
  border-radius: 8px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.notice svg { flex-shrink: 0; margin-top: 2px; }
.notice.info { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
.notice.danger { border-color: #eed7d9; background: var(--danger-soft); color: var(--danger); }
.form-body > .notice:last-child { margin-bottom: 0; }

.device-list, .key-list, .activity-list, .invoice-list, .account-details, .quota-body {
  padding-inline: var(--section-pad);
}
.device-row, .key-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.device-icon, .quota-unavailable-icon, .onboarding-icon, .confirm-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}
.device-icon { background: var(--neutral-soft); color: var(--muted); }
.device-details { min-width: 0; }
.device-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.device-meta, .key-code, .activity-time { margin-top: 3px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.device-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px 9px; min-width: 0; }
.trusted-toggle { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.trusted-toggle input, .mode-option input { accent-color: var(--accent); }
.trusted-toggle input { width: 15px; height: 15px; margin: 0; }
.key-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.activity-row, .invoice-row, .detail-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.activity-row { justify-content: flex-start; }
.activity-mark { width: 6px; height: 6px; flex: 0 0 6px; margin-top: 7px; border-radius: 50%; background: var(--focus); }
.activity-mark.danger { background: var(--danger); }
.invoice-row strong, .detail-label { flex-shrink: 0; }
.detail-label { color: var(--muted); }
.detail-value { min-width: 0; text-align: right; }
.account-details, .quota-body { padding-bottom: 13px; }
.quota-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding-bottom: 13px; }
.quota-stat { min-width: 0; }
.quota-label, .quota-unit { color: var(--muted); font-size: 12px; }
.quota-value { margin-top: 3px; }
.quota-unit { margin-top: 7px; }
.quota-progress { display: block; width: 100%; height: 7px; accent-color: var(--accent); }
.quota-demand { margin-top: 12px; }
.quota-unavailable { display: flex; align-items: center; gap: 10px; padding: 0 var(--section-pad) 15px; }
.quota-unavailable h3 { font-size: 13px; }
.quota-unavailable p { margin-top: 3px; color: var(--muted); font-size: 12px; }

.empty, .onboarding { color: var(--muted); text-align: center; }
.empty { padding: 19px var(--section-pad); font-size: 13px; }
.empty > svg { color: var(--accent); }
.empty h3 { margin: 4px 0 2px; color: var(--ink); font-size: 14px; }
.onboarding { padding: 29px var(--section-pad); }
.onboarding-icon { width: 49px; height: 49px; margin: 0 auto 12px; }
.onboarding-icon svg { width: 28px; height: 28px; }
.onboarding h2 { color: var(--ink); font-size: 19px; }
.onboarding p { margin: 5px 0 12px; }

/* Forms, login, and native dialogs */
.form-body { padding: 0 var(--section-pad) 15px; }
.form-label { display: block; margin-bottom: 5px; color: var(--ink); font-size: 13px; font-weight: 650; }
.form-help, .login-description { margin-top: 5px; color: var(--muted); font-size: 12px; }
.text-input, .form-textarea {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #c6d0e0;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.text-input { min-height: 40px; }
.form-textarea { min-height: 96px; resize: vertical; }
.import-textarea { min-height: 116px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.form-actions, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 13px;
}
.official-login { display: flex; align-items: center; justify-content: space-between; gap: 9px 14px; }
.official-login > div { min-width: 0; }
.official-login > .button { flex: 0 0 auto; }
.official-login p { font-size: 13px; }

.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mode-option {
  display: block;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}
.mode-option:has(input:checked) { border-color: var(--focus); background: var(--accent-soft); }
.mode-icon { display: block; margin-bottom: 5px; color: var(--accent); }
.mode-title { font-size: 13px; font-weight: 650; }
.mode-description { margin-top: 4px; color: var(--muted); font-size: 12px; }
.settings-summary { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--canvas); color: var(--muted); font-size: 12px; }

.login-page, .boot-screen {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 24px 16px;
}
.login-workspace { width: min(100%, 408px); }
.login-page { background: radial-gradient(ellipse at 50% 20%, #e7eeff 0, var(--canvas) 64%); }
.login-card {
  padding: clamp(22px, 5vw, 30px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 45px #17203312;
}
.login-card .brand { margin-bottom: 19px; }
.login-card h1 { color: var(--ink); font-size: 22px; font-weight: 730; letter-spacing: -.025em; }
.login-description { margin-bottom: 14px; }
.login-submit { width: 100%; margin-top: 13px; }
.login-card .field-group { margin-top: 10px; }
.boot-screen { align-content: center; gap: 9px; color: var(--muted); }
.busy-dot {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.import-dialog, .confirm-dialog {
  width: min(calc(100% - 28px), 540px);
  max-height: calc(100dvh - 28px);
  padding: clamp(15px, 3vw, 22px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 56px #17203330;
}
.confirm-dialog { width: min(calc(100% - 28px), 430px); }
.import-dialog::backdrop, .confirm-dialog::backdrop { background: #111b3266; }
.dialog-heading, .confirm-heading { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.dialog-heading { justify-content: space-between; }
.confirm-heading { align-items: center; }
.dialog-heading h2, .confirm-heading h2 { color: var(--ink); font-size: 17px; font-weight: 720; line-height: 1.35; }
.confirm-dialog.is-danger .confirm-icon { background: var(--danger-soft); color: var(--danger); }
.dialog-description, .confirm-message { margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.confirm-message { white-space: pre-line; }
.confirm-message p + p { margin-top: 7px; }
.import-help { margin-top: 9px; padding: 8px 10px; border-radius: 8px; background: var(--canvas); color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.import-help strong { color: var(--ink); }
.dialog-error { margin-top: 8px; }
.clipboard-helper { position: fixed; left: -10000px; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toast {
  position: fixed;
  z-index: 10;
  right: 16px;
  bottom: 16px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--ink);
  color: white;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.toast.error { background: var(--danger); }

/* Narrow windows and phones */
@media (max-width: 940px) {
  .shell { grid-template-columns: 208px minmax(0, 1fr); }
  .sidebar { padding-inline: 13px; }
  .sidebar .brand-title { font-size: 14px; }
}

@media (max-width: 720px) {
  :root { --section-pad: 15px; }
  .shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
    gap: 10px;
    padding: 13px 15px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar .brand-title { font-size: 15px; }
  .account-directory { gap: 6px; }
  .account-list { flex-direction: row; }
  .account-item { flex: 0 0 min(185px, 75vw); }
  .sidebar > .button { width: auto; align-self: flex-start; }
  .main { padding: 19px 15px 20px; }
  .page-heading { gap: 10px; margin-bottom: 14px; }
  .account-toolbar { gap: 7px; }
  .stat-card { min-height: 91px; padding: 11px; }
  .stat-main, .quota-value { font-size: 23px; }
}

@media (max-width: 490px) {
  .page-heading { flex-direction: column; }
  .page-heading-content { width: 100%; }
  .heading-actions, .account-utilities { justify-content: flex-start; width: 100%; }
  .account-more-menu { left: 0; right: auto; }
  .account-toolbar { flex-direction: column; align-items: stretch; }
  .workspace-tabs { width: 100%; }
  .tab-button { flex: 1 1 auto; padding-inline: 5px; }
  .summary-grid, .quota-grid { gap: 6px; }
  .stat-card { padding: 8px 7px; }
  .stat-top, .stat-label, .quota-label { font-size: 11px; }
  .stat-top svg { display: none; }
  .stat-main, .quota-value { font-size: 20px; }
  .stat-main .unit { margin-left: 3px; font-size: 10px; }
  .section-header { flex-wrap: wrap; }
  .device-row { grid-template-columns: 34px minmax(0, 1fr); }
  .device-actions { grid-column: 2; justify-content: flex-start; }
  .device-icon { width: 34px; height: 34px; }
  .official-login { flex-wrap: wrap; }
  .mode-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .busy-dot { animation: none; }
}
