:root {
  --bg: #f4f5f6;
  --panel: #ffffff;
  --ink: #17181c;
  --muted: #7c828c;
  --line: #e8eaee;
  --accent: #6c5ce7;
  --accent-soft: #efedff;
  --green: #19a974;
  --orange: #e58b2b;
  --red: #d64545;
  --gray: #9aa0a8;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(23, 24, 28, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--red); }
.warn-text { color: var(--orange); font-weight: 600; }

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #17181c;
  color: #f5f6f8;
  padding: 26px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0 4px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: #2a2b31;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 24px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .02em;
}

.brand p {
  margin: 3px 0 0;
  color: #9096a1;
  font-size: 12px;
}

.switcher-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #7e8490;
  font-size: 11px;
  letter-spacing: .12em;
  padding: 0 4px;
}

.account-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-item {
  border: 1px solid #2c2d34;
  border-radius: 13px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  background: #1d1e23;
  color: #f5f6f8;
  text-align: left;
}

.account-item:hover { border-color: #434451; }
.account-item.active {
  border-color: #8b7cf7;
  box-shadow: 0 0 0 1px #8b7cf7 inset;
}

.account-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #2a2b31;
  display: grid;
  place-items: center;
  color: #b8bdc9;
  flex: 0 0 auto;
}

.account-main { min-width: 0; flex: 1; }
.account-phone { font-size: 14px; font-weight: 650; letter-spacing: .02em; }
.account-label { color: #8e94a0; font-size: 11px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
  flex: 0 0 auto;
}
.status-dot.online { background: var(--green); }
.status-dot.logging_in { background: var(--orange); }
.status-dot.needs_login { background: var(--orange); }
.status-dot.risk_blocked { background: var(--red); }
.status-dot.new { background: var(--gray); }
/* A background purchase keeps running after switching away, so the account's
   dot pulses rather than looking idle. */
.status-dot.running {
  background: var(--accent);
  animation: running-pulse 1.2s ease-in-out infinite;
}
@keyframes running-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}
@media (prefers-reduced-motion: reduce) {
  .status-dot.running { animation: none; }
}

.sidebar-footer { margin-top: auto; padding: 0 4px; }
.link-btn { background: none; border: 0; color: #8e94a0; padding: 0; }
.link-btn:hover { color: #fff; }

.main {
  padding: 28px 34px 60px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.account-header {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.account-head-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.account-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #f1f0ff;
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 22px;
}
.account-title { font-size: 22px; font-weight: 750; letter-spacing: .01em; }
.account-sub { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  background: #f1f2f4;
  color: #5b626d;
}
.badge.online { background: #e8f7f1; color: var(--green); }
.badge.needs_login, .badge.logging_in { background: #fff5e8; color: var(--orange); }
.badge.risk_blocked { background: #fdecec; color: var(--red); }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.product-grid.disabled { opacity: .58; }

@media (max-width: 1180px) { .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) { .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.product-card {
  border: 1.5px solid var(--line);
  border-radius: 13px;
  padding: 15px;
  background: #fffdf9;
  position: relative;
  transition: border-color .15s, transform .15s;
}
.product-card:hover { border-color: #c9c2ff; }
.product-card.selected { border-color: var(--accent); background: #fbfaff; box-shadow: 0 0 0 1px var(--accent) inset; }
.product-card input { position: absolute; right: 13px; top: 13px; accent-color: var(--accent); width: 17px; height: 17px; }
.product-name { color: #8a6a35; font-size: 13px; font-weight: 650; margin-bottom: 8px; }
.product-price { font-size: 27px; font-weight: 800; color: #e34c4c; letter-spacing: -.02em; }
.product-price small { font-size: 14px; font-weight: 700; margin-right: 2px; }
.product-origin { color: var(--muted); font-size: 12px; margin-top: 5px; }

.purchase-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.selected-summary { color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 15px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.2;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #5b4bd6; }
.btn-ghost { background: #22232a; color: #dfe1e7; border-color: #34353d; }
.btn-ghost:hover { border-color: #555766; }
.btn-block { width: 100%; }
.btn-danger { background: #fff0f0; color: var(--red); border-color: #f4c9c9; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}
.task-item .item-name { font-weight: 650; }
.task-item .item-meta { color: var(--muted); font-size: 12px; margin-top: 4px; word-break: break-all; }
.table .item-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.code-row { display: flex; gap: 8px; align-items: center; }
.code-row input {
  width: 130px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  letter-spacing: .18em;
  font-variant-numeric: tabular-nums;
}
.code-row input:focus { outline: 2px solid #d9d3ff; border-color: var(--accent); }

.status-pill {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1f2f4;
  color: #656b75;
  white-space: nowrap;
}
.status-pill.success { background: #e8f7f1; color: var(--green); }
.status-pill.code_sent, .status-pill.ordering { background: #f0edff; color: var(--accent); }
.status-pill.failed, .status-pill.code_failed, .status-pill.risk_blocked { background: #fdecec; color: var(--red); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tab {
  background: none;
  border: 0;
  padding: 9px 12px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 650; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table tr:last-child td { border-bottom: 0; }

.empty-state { color: var(--muted); padding: 18px 4px; text-align: center; }

.risk-banner {
  background: #fff4f4;
  border: 1px solid #f3cccc;
  color: #a53434;
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.risk-banner a { color: #a53434; font-weight: 650; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 20% 10%, #ede9ff, transparent 40%), var(--bg);
  padding: 20px;
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 80px rgba(40, 32, 100, .12);
  padding: 30px;
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 26px; }
.login-brand .brand-mark { background: var(--accent); }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 3px 0 0; color: var(--muted); }
.field-label { display: block; color: var(--muted); font-size: 12px; margin: 0 0 7px; }
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 13px;
  margin-bottom: 14px;
}
.login-card input:focus { outline: 2px solid #d9d3ff; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 14px 0 0; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 16, 20, .42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  width: min(460px, 100%);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .2);
  padding: 24px;
}
.modal h3 { margin: 0 0 6px; font-size: 19px; }
.modal p.modal-sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.modal input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 13px;
  margin-bottom: 12px;
}
.modal input:focus { outline: 2px solid #d9d3ff; border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #17181c;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  z-index: 80;
  max-width: min(640px, 92vw);
}
.toast.error { background: #b23b3b; }

.stats-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.stats-month {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.stats-month input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font: inherit;
  color: inherit;
  background: #fff;
}
.stats-summary { margin-bottom: 16px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.stat-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: #fff;
}
.stat-card.total { background: #f6f4ff; border-color: #ddd6ff; }
.stat-name { font-size: 13px; color: var(--muted); }
.stat-count { font-size: 26px; font-weight: 650; margin: 6px 0 2px; }
.stat-count small { font-size: 12px; font-weight: 500; color: var(--muted); }
.stat-amount { font-size: 13px; color: var(--muted); }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.pager-actions { display: flex; align-items: center; gap: 10px; }

.toast.long {
  border-radius: 14px;
  padding: 13px 18px;
  text-align: left;
  line-height: 1.5;
  max-width: min(720px, 94vw);
}
