:root {
  --canvas: #F5F5F7;
  --base: #FFFFFF;
  --section: #FAFAFC;
  --inter: #F0F0F4;
  --hover: #E6E6EC;
  --line: #E4E4EB;
  --line-strong: #C8C8D4;
  --fg: #141418;
  --fg2: #4E4E5A;
  --mut: #737382;
  --pri-bg: #141418;
  --pri-fg: #FFFFFF;
  --ok: #137A4B;
  --ok-bg: rgba(19, 122, 75, .10);
  --warn: #9A6700;
  --warn-bg: rgba(154, 103, 0, .10);
  --bad: #C92A38;
  --bad-bg: rgba(201, 42, 56, .10);
  --live: #D93848;
  --scrim: rgba(10, 10, 16, .52);
  --shadow: 0 18px 42px rgba(0, 0, 0, .22);
  color-scheme: light;
}

html.dark {
  --canvas: #0B0B10;
  --base: #121218;
  --section: #15151C;
  --inter: #18181F;
  --hover: #1E1E27;
  --line: #292933;
  --line-strong: #3A3946;
  --fg: #F5F4F7;
  --fg2: #B8B6C2;
  --mut: #908E9E;
  --pri-bg: #F5F4F7;
  --pri-fg: #0B0B10;
  --ok: #62D6A4;
  --ok-bg: rgba(98, 214, 164, .12);
  --warn: #E4B64D;
  --warn-bg: rgba(228, 182, 77, .12);
  --bad: #FF8F95;
  --bad-bg: rgba(255, 143, 149, .13);
  --live: #FF5F57;
  --scrim: rgba(5, 5, 8, .72);
  --shadow: 0 18px 42px rgba(0, 0, 0, .48);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--canvas);
  color: var(--fg);
  font: 13px/1.6 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.num {
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* Layout shell: mobile-first (320/390) + desktop sidebar (>=960) */
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--pri-bg);
  color: var(--pri-fg);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  flex: 0 0 auto;
}

.brand-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 11px;
  color: var(--mut);
  display: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.body-wrap {
  flex: 1;
  display: flex;
  min-width: 0;
}

.sidebar {
  display: none;
  width: 184px;
  flex: 0 0 184px;
  background: var(--section);
  border-right: 1px solid var(--line);
  padding: 16px 8px;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--fg2);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  width: 100%;
  position: relative;
  transition: background .16s, color .16s;
}

.nav-item:hover {
  background: var(--hover);
  color: var(--fg);
}

.nav-item.active {
  background: var(--hover);
  color: var(--fg);
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--fg);
  border-radius: 2px;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 16px 12px calc(76px + env(safe-area-inset-bottom));
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  background: var(--base);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
  border: 0;
  background: transparent;
  color: var(--mut);
  height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 500;
  min-width: 0;
  padding: 0 2px;
}

.tab-btn svg {
  width: 18px;
  height: 18px;
}

.tab-btn.active {
  color: var(--fg);
  font-weight: 600;
}

@media (min-width: 960px) {
  .topbar {
    padding: 0 24px;
  }
  .brand-sub {
    display: inline;
  }
  .sidebar {
    display: flex;
  }
  .tabbar {
    display: none;
  }
  .main {
    padding: 24px 28px 40px;
  }
}

/* Typography roles */
.h-page {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -.015em;
}

.h-sec {
  font-size: 16px;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -.01em;
}

.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg2);
}

.meta {
  font-size: 11px;
  color: var(--mut);
  line-height: 1.5;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* Surfaces & dividers (flat-by-default, shared containers, 4/8/12 radius) */
.panel {
  background: var(--base);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-body {
  padding: 14px;
}

.list-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.list-row:last-child {
  border-bottom: 0;
}

.row-main {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.row-right {
  text-align: right;
  flex: 0 0 auto;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.kv {
  padding: 12px 10px;
  border-right: 1px solid var(--line);
  min-width: 0;
}

.kv:last-child {
  border-right: 0;
}

.kv-val {
  font-size: 18px;
  font-weight: 650;
  line-height: 1.3;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 360px) {
  .kv-val {
    font-size: 15px;
  }
  .kv {
    padding: 10px 8px;
  }
}

.kv2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kv2 .kv:nth-child(2n) {
  border-right: 0;
}

/* Notice banner (flat, semantic border) */
.notice {
  border: 1px solid var(--line);
  border-left: 3px solid var(--fg);
  background: var(--section);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--fg2);
  margin-bottom: 16px;
}

.notice.warn {
  border-left-color: var(--warn);
  background: var(--warn-bg);
  color: var(--fg);
}

.notice.ok {
  border-left-color: var(--ok);
  background: var(--ok-bg);
  color: var(--fg);
}

.notice.bad {
  border-left-color: var(--bad);
  background: var(--bad-bg);
  color: var(--fg);
}

/* Buttons (8px radius, 36px height) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--inter);
  color: var(--fg);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .16s, border-color .16s, transform .1s;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.btn:hover {
  background: var(--hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.nav-item:focus-visible,
.tab-btn:focus-visible,
.switch:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.btn-pri {
  background: var(--pri-bg);
  color: var(--pri-fg);
  border-color: var(--pri-bg);
}

.btn-pri:hover {
  opacity: .9;
  background: var(--pri-bg);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-xs {
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg2);
}

.btn-ghost:hover {
  background: var(--hover);
  color: var(--fg);
}

.btn-danger {
  color: var(--bad);
  border-color: var(--bad);
  background: transparent;
}

.btn-danger:hover {
  background: var(--bad-bg);
}

.btn-full {
  width: 100%;
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

/* Chips (4px radius, NOT pills) */
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chip {
  height: 28px;
  padding: 0 10px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--inter);
  color: var(--fg2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.chip.active {
  background: var(--pri-bg);
  color: var(--pri-fg);
  border-color: var(--pri-bg);
}

/* Tags (4px radius) */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--inter);
  color: var(--fg2);
}

.tag.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.tag.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.tag.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  display: inline-block;
}

/* Segmented bar */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--inter);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 14px;
}

.seg button {
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--fg2);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.seg button.active {
  background: var(--base);
  color: var(--fg);
  border: 1px solid var(--line);
}

/* Inputs */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg2);
  margin-bottom: 5px;
}

.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--section);
  color: var(--fg);
  font-size: 13px;
}

.input.err {
  border-color: var(--bad);
}

.err-txt {
  font-size: 11px;
  color: var(--bad);
  margin-top: 4px;
  min-height: 16px;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-row .input {
  flex: 1;
  min-width: 0;
}

/* Promo code & QR block */
.code-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  background: var(--section);
  border-bottom: 1px solid var(--line);
}

.code-big {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: .12em;
  line-height: 1.1;
}

.link-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--section);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
}

.link-url {
  font-size: 12px;
  color: var(--fg2);
  word-break: break-all;
  min-width: 0;
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.qr-wrap {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.qr-box {
  width: 112px;
  height: 112px;
  background: #FFFFFF;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.qr-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-meta {
  flex: 1;
  min-width: 140px;
}

/* Switch */
.switch {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--inter);
  flex: 0 0 auto;
  transition: background .16s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--mut);
  transition: transform .16s, background .16s;
}

.switch.on {
  background: var(--pri-bg);
  border-color: var(--pri-bg);
}

.switch.on::after {
  transform: translateX(18px);
  background: var(--pri-fg);
}

.switch:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Modal / Dialog (12px radius, 20px padding, elevation shadow) */
.modal-bg {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--scrim);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-bg.open {
  display: flex;
}

.modal {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--base);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-ft {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.agree-box {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--section);
}

.agree-summary { margin: 8px 0 0; padding-inline-start: 20px; }
.agree-summary li + li { margin-top: 6px; }

/* Login screen */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.login-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--canvas);
}

.login-box {
  width: min(380px, 100%);
  background: var(--base);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--pri-bg);
  color: var(--pri-fg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  display: none;
  max-width: calc(100vw - 24px);
  text-align: center;
}

@media (min-width: 960px) {
  .toast {
    bottom: 24px;
  }
}

/* Semantic text & utility helpers */
.ok-txt { color: var(--ok); }
.bad-txt { color: var(--bad); }
.fg2-txt { color: var(--fg2); }
.mut-txt { color: var(--mut); }
.fg-txt { color: var(--fg); }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; flex-wrap: wrap; }
.nowrap { white-space: nowrap; }
.flex-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mb12 { margin-bottom: 12px; }
.mb0 { margin-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.break { word-break: break-all; }
.empty { padding: 32px 16px; text-align: center; color: var(--mut); font-size: 13px; }
.code-inline { font-size: 15px; color: var(--fg); font-weight: 650; letter-spacing: .08em; }
.amt-md { font-size: 15px; font-weight: 650; }
.amt-lg { font-size: 16px; font-weight: 650; }
.kv-grid-plain { border-bottom: 0; }
.setting-title { color: var(--fg); font-size: 14px; }
.agree-check { font-size: 12px; cursor: pointer; }

.legal-footer {
  text-align: center;
  padding: 16px 12px 88px;
}
.legal-footer a {
  color: inherit;
}


.theme-row .seg {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.theme-row .seg button {
  white-space: nowrap;
  padding-inline: 12px;
}

@media (max-width: 420px) {
  .theme-row {
    flex-direction: column;
    align-items: stretch;
  }

  .theme-row .seg {
    width: 100%;
  }
}

@media (min-width: 960px) {
  .app-embedded .main {
    max-width: none;
  }
}
