:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --ink: #14201b;
  --muted: #5a6b64;
  --line: #e6ebe8;
  --accent: #0f5c45;
  --accent-dark: #0a3f30;
  --accent-soft: #e8f2ee;
  --accent-ink: #eef6f2;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #0f5c45;
  --ok-soft: #e8f2ee;
  --sidebar: #0c3d2e;
  --sidebar-2: #06251c;
  --sidebar-hover: rgba(255, 255, 255, 0.1);
  --blue-mid: #0f5c45;
  --shadow: 0 1px 2px rgba(12, 61, 46, 0.04), 0 8px 24px rgba(12, 61, 46, 0.05);
  --radius: 14px;
  --drawer-w: min(420px, 100vw);
  --drawer-w-wide: min(560px, 100vw);
  --font: "Outfit", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  word-break: break-all;
}

/* Layout */
.layout { display: flex; min-height: 100vh; position: relative; }
.content-shell {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sidebar {
  width: 252px;
  background: var(--sidebar);
  color: var(--accent-ink);
  padding: 1.15rem 0.85rem calc(1.1rem + var(--safe-bottom));
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  border-right: 0;
  transition: width 0.22s ease, padding 0.22s ease, opacity 0.18s ease, transform 0.22s ease;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.sidebar-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.35rem 0.55rem 1.05rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 0.65rem;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  color: #fff;
  flex-shrink: 0;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.35);
}
.sidebar-brand > picture {
  flex-shrink: 0;
  line-height: 0;
}
.brand-logo-full {
  display: block;
  width: min(220px, 72vw);
  height: auto;
  margin: 0 auto 0.85rem;
}
.sidebar-brand .brand-text { min-width: 0; }
.layout.sidebar-collapsed .sidebar-brand .brand-text { display: none; }
.layout.sidebar-collapsed .brand-logo { width: 36px; height: 36px; }
.brand-kicker {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.15rem;
}
.sidebar h1 {
  font-size: 0.98rem;
  margin: 0;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: #fff;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.12rem; flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: rgba(255, 255, 255, 0.88);
  padding: 0.72rem 0.85rem;
  border-radius: 10px;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
  font-size: 0.92rem;
  font-weight: 500;
}
.sidebar nav a .nav-ico {
  width: 1.35rem;
  height: 1.35rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  opacity: 0.88;
}
.sidebar nav a .nav-ico svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}
.sidebar nav a:hover {
  background: var(--sidebar-hover);
  text-decoration: none;
  color: #fff;
}
.sidebar nav a.active {
  background: rgba(255, 255, 255, 0.14);
  text-decoration: none;
  color: #fff;
  font-weight: 600;
}
body.sidebar-collapsed .sidebar {
  width: 76px !important;
  min-width: 76px;
  padding-left: 0.55rem;
  padding-right: 0.55rem;
  opacity: 1;
  pointer-events: auto;
  overflow: hidden;
}
body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}
body.sidebar-collapsed .sidebar-brand > div:not(.brand-mark) {
  display: none;
}
body.sidebar-collapsed .sidebar nav a {
  justify-content: center;
  padding-left: 0.7rem;
  padding-right: 0.7rem;
}
body.sidebar-collapsed .sidebar nav a .nav-text {
  display: none;
}
body.sidebar-collapsed .sidebar nav a .nav-ico {
  margin: 0;
}

.drawer-close-btn {
  font-size: 1.35rem !important;
  line-height: 1 !important;
  color: var(--ink) !important;
}
.drawer-close-btn span { display: none; }

.user-menu-item {
  width: 100%;
  text-align: left;
  cursor: pointer;
  border: 0;
  background: transparent;
  font: inherit;
}

/* 桌面端表格横向滚动；手机也保留表格可见 */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.65rem + var(--safe-top)) 1.1rem 0.65rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 56px;
  box-shadow: 0 1px 0 rgba(12, 61, 46, 0.03);
}
.topbar .brand {
  font-weight: 650;
  font-size: 0.98rem;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
  margin-left: auto;
}
.topbar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sidebar);
  color: #fff;
  font-weight: 700;
  font-size: 0.86rem;
  flex-shrink: 0;
}
.topbar-role {
  font-size: 0.68rem;
  color: var(--muted);
}
.topbar-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 头像下拉 */
.user-menu {
  position: relative;
}
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  border: 0;
  background: transparent;
  padding: 0.2rem 0.25rem 0.2rem 0.2rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.user-menu-trigger:hover {
  background: #f3f6f4;
}
.user-menu.open .user-menu-trigger {
  background: #eef3f0;
}
.user-menu-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  max-width: 140px;
  line-height: 1.2;
  text-align: left;
}
.user-menu-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #8aa399;
  margin-right: 0.25rem;
  flex-shrink: 0;
}
.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 188px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(12, 61, 46, 0.14);
  padding: 0.4rem;
  z-index: 50;
}
.user-menu.open .user-menu-dropdown {
  display: block;
}
.user-menu-dropdown[hidden] { display: none !important; }
.user-menu-head {
  padding: 0.55rem 0.7rem 0.65rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.3rem;
}
.user-menu-head-role {
  font-size: 0.7rem;
  color: var(--muted);
}
.user-menu-head-name {
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--ink);
  word-break: break-all;
}
.user-menu-item {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.62rem 0.75rem;
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
.user-menu-item:hover {
  background: #f3f6f4;
  text-decoration: none;
  color: var(--ink);
}
.user-menu-item.danger {
  color: var(--danger);
}
.user-menu-item.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: #eef2f0;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  flex-shrink: 0;
}
.icon-btn:hover { background: #e4ebe7; }
.icon-btn span {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  position: relative;
}
.icon-btn span::before,
.icon-btn span::after {
  content: "";
  position: absolute;
  left: 0;
  width: 16px;
  height: 2px;
  background: currentColor;
}
.icon-btn span::before { top: -5px; }
.icon-btn span::after { top: 5px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 37, 28, 0.48);
  z-index: 35;
  backdrop-filter: blur(2px);
}
body.nav-open .sidebar-backdrop { display: block; }
body.nav-open { overflow: hidden; }

.main {
  flex: 1;
  min-width: 0;
  padding: 1.35rem 1.5rem 2rem;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-head h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}
.page-head .desc {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}

.search-bar {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-left: auto;
}
.search-bar input[type="search"] {
  min-width: 160px;
  width: 200px;
  max-width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 0.88rem;
}
.search-bar input[type="search"]:focus,
.search-bar select:focus {
  outline: 2px solid rgba(15, 92, 69, 0.18);
  border-color: var(--accent);
}
.search-bar select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 0.88rem;
}

/* 自定义弹窗 */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-root[hidden] { display: none !important; }
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: #fff;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(6, 37, 28, 0.22);
  padding: 1.15rem 1.25rem 1.1rem;
  animation: modal-in 0.18s ease;
}
.modal-panel.modal-wide { width: min(520px, 100%); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}
.modal-body {
  margin: 0.75rem 0 1rem;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.55;
  word-break: break-word;
}
.modal-body .muted { color: var(--muted); font-size: 0.84rem; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal-progress-track {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin: 0.85rem 0 0.45rem;
}
.modal-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s ease;
}
.modal-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.modal-progress-log {
  margin-top: 0.75rem;
  max-height: 160px;
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.45;
  background: #f5f8f6;
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}
.modal-progress-log .ok { color: #15803d; }
.modal-progress-log .err { color: #b91c1c; }
.modal-progress-log .skip { color: #64748b; }

.card {
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  box-shadow: var(--shadow);
}
.card-warn {
  border: 0;
  background: #fffbeb;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.card-head h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.card-head .muted { margin: 0.25rem 0 0; }

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.page-grid > .card { min-width: 0; }

.info-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  padding: 0.85rem 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  margin-bottom: 0.85rem;
}
.info-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.info-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
}
.result-list {
  margin: 0 0 0.5rem;
  padding-left: 1.1rem;
}
.hint-blocks { display: grid; gap: 0.7rem; }
.hint-block {
  padding: 0.85rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.hint-block:last-child { border-bottom: 0; }
.hint-title {
  font-size: 0.84rem;
  font-weight: 650;
  margin-bottom: 0.25rem;
  color: var(--ink);
}
.code-block {
  display: block;
  margin-top: 0.45rem;
  padding: 0.65rem 0.75rem;
  background: #f3f6f4;
  border: 0;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.45;
  word-break: break-all;
  white-space: pre-wrap;
}
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  align-items: end;
}
.check-pad { padding-bottom: 0.55rem; }
.form textarea.mono,
textarea.mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.drawer-meta {
  margin-top: 0.5rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}
.stat-card {
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  padding: 1.05rem 1.1rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  right: -24px;
  top: -24px;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: 0.55;
}
.stat-card.tone-sky::after { background: #e0f2fe; }
.stat-card.tone-amber::after { background: #ffedd5; }
.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  position: relative;
  z-index: 1;
  margin-bottom: 0.2rem;
}
.stat-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.stat-card.tone-sky .stat-ico { background: rgba(2, 132, 199, 0.12); color: #0369a1; }
.stat-card.tone-amber .stat-ico { background: rgba(217, 119, 6, 0.12); color: #b45309; }
.stat-ico svg { width: 18px; height: 18px; fill: currentColor; }
.stat-card .label { color: var(--muted); font-size: 0.82rem; margin-bottom: 0; }
.stat-card .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.03em; position: relative; z-index: 1; }
.stat-card .hint { margin-top: 0.35rem; color: var(--muted); font-size: 0.78rem; position: relative; z-index: 1; }

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 0.85rem;
  margin-top: 0.95rem;
}
.chart-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.chart-card.chart-wide {
  grid-column: 1 / -1;
}
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}
.chart-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.chart-head .muted { margin: 0.2rem 0 0; }
.chart-canvas-wrap {
  position: relative;
  height: 260px;
  width: 100%;
}
.chart-canvas-wrap.chart-pie {
  height: 240px;
  max-width: 280px;
  margin: 0 auto;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 640px;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.78rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
table.data tbody tr:hover { background: #f8fbfb; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 1px solid transparent;
  background: #eef2f0;
  color: var(--ink);
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 550;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:hover {
  text-decoration: none;
  background: #e4ebe7;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: none;
}
.btn.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}
.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.btn.ghost { background: transparent; }
.btn.small { padding: 0.32rem 0.6rem; font-size: 0.78rem; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.84rem;
  color: var(--muted);
}
.form label.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--ink);
  font-size: 0.88rem;
}
.form label.check input[type="checkbox"] {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 0;
}
.form input, .form select, .form textarea {
  display: block;
  width: 100%;
  margin-top: 0.38rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: 2px solid rgba(15, 92, 69, 0.2);
  border-color: var(--accent);
}
.form textarea {
  min-height: 180px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.84rem;
  resize: vertical;
}
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.form-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
  padding-top: 0;
  border-top: 0;
}

.login-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}
.login-tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft, #475569);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.login-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sku-builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sku-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}
.sku-row input {
  margin-top: 0;
}
@media (max-width: 640px) {
  .sku-row { grid-template-columns: 1fr; }
}

.flash {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--danger-soft); color: var(--danger); }

/* 页面常驻提示（非飘窗） */
.notice {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
  border: 1px solid transparent;
}
.notice.warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}
.notice.info {
  background: #f0f9ff;
  border-color: #bae6fd;
  color: #075985;
}
.notice.danger {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}
.notice a { font-weight: 600; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--muted);
}
.tag.on { background: var(--accent-soft); color: var(--accent-dark); }
.tag.off { background: var(--danger-soft); color: var(--danger); }
.tag.warn { background: #fff4e5; color: #9a5b00; }

.muted { color: var(--muted); font-size: 0.85rem; }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* Mobile cards for tables */
.mobile-list { display: none; gap: 0.7rem; }
.m-card {
  border: 0;
  border-radius: 12px;
  padding: 0.95rem 1rem;
  background: #fff;
  box-shadow: var(--shadow);
}
.m-card .title {
  font-weight: 650;
  margin-bottom: 0.45rem;
  word-break: break-all;
}
.m-card .meta {
  display: grid;
  gap: 0.28rem;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.7rem;
}
.m-card .meta strong { color: var(--ink); font-weight: 500; }

/* Drawer */
.drawer-root[hidden] { display: none !important; }
.drawer-root {
  position: fixed;
  inset: 0;
  z-index: 80;
}
.drawer-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 32, 43, 0.42);
  opacity: 0;
  transition: opacity .2s ease;
}
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--drawer-w);
  height: 100%;
  background: #fff;
  box-shadow: -8px 0 28px rgba(26, 35, 50, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s ease;
}
.drawer-root.drawer-wide .drawer-panel {
  width: var(--drawer-w-wide);
}
.drawer-root.open .drawer-mask { opacity: 1; }
.drawer-root.open .drawer-panel { transform: translateX(0); }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.drawer-header h3 { margin: 0; font-size: 1.05rem; }
.drawer-header .icon-btn {
  background: #eef2f0;
  color: var(--ink);
}
.drawer-header .icon-btn:hover { background: #e4ebe7; }
.drawer-body {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.1rem 1.4rem;
  -webkit-overflow-scrolling: touch;
}
body.drawer-open { overflow: hidden; }

/* Login / Install */
.login-body, .install-body {
  display: grid;
  place-items: center;
  padding: 1.25rem;
  min-height: 100vh;
  background: var(--sidebar);
}
.login-card, .install-card {
  width: min(440px, 100%);
  background: #fff;
  border: 0;
  border-radius: 18px;
  padding: 1.55rem 1.4rem;
  box-shadow: 0 18px 48px rgba(6, 37, 28, 0.28);
}
.install-card { width: min(560px, 100%); }
.login-card h1, .install-card h1 { margin-top: 0; font-size: 1.25rem; color: var(--ink); }
.install-card h2 { font-size: 0.98rem; margin: 1.2rem 0 0.7rem; }

.api-tip {
  margin-top: 1rem;
  padding: 0.85rem 0.95rem;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid #d5e8de;
  color: var(--muted);
  font-size: 0.84rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.pager-info { color: var(--muted); font-size: 0.82rem; }
.pager-links { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.pager-ellipsis { color: var(--muted); padding: 0 0.15rem; }
.pager-links .btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.filter-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}
.filter-select {
  min-width: 200px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbfa;
  color: var(--ink);
  font-size: 0.9rem;
}
.filter-select:focus {
  outline: 2px solid rgba(15, 92, 69, 0.18);
  border-color: var(--accent);
}

.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding: 0.35rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.page-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.page-tab:hover { color: var(--ink); background: #f3f7f5; }
.page-tab.active {
  background: var(--accent);
  color: #fff;
}
.page-pane[hidden] { display: none !important; }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.empty-state strong {
  display: block;
  color: var(--ink);
  margin-bottom: 0.35rem;
  font-size: 1rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 1rem;
  margin-top: 1.25rem;
}
.chart-card .card-head { margin-bottom: 0.35rem; }
.chart-wrap {
  position: relative;
  height: 240px;
  padding: 0.25rem 0.35rem 0.5rem;
}
.chart-wrap-pie { max-width: 280px; margin: 0 auto; }
@media (max-width: 1100px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-wrap-pie { max-width: 320px; }
}

.wallet-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1rem;
  border-radius: 16px;
  background: linear-gradient(135deg, #0f5c45 0%, #1a7a5c 55%, #2d9b73 100%);
  color: #fff;
}
.wallet-hero .muted { color: rgba(255,255,255,.75); margin: 0; }
.wallet-hero .bal {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0.2rem 0 0;
}
.wallet-hero .btn {
  background: #fff;
  color: var(--accent);
  border-color: transparent;
}
.wallet-hero .btn:hover { filter: brightness(0.97); }

.ai-item-pick {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1rem;
}
.ai-item-pick label { flex: 1; min-width: 180px; margin: 0; }

.toast-host {
  position: fixed;
  top: calc(0.85rem + var(--safe-top));
  right: 1rem;
  z-index: 4000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 1.5rem));
}
.toast {
  pointer-events: auto;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 32, 43, 0.16);
  border: 1px solid transparent;
  background: #fff;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  transform: translateX(120%);
  opacity: 0;
  transition: transform .28s ease, opacity .28s ease;
}
.toast.show {
  transform: translateX(0);
  opacity: 1;
}
.toast.hide {
  transform: translateX(110%);
  opacity: 0;
}
.toast.ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}
.toast.err {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}
.toast-icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(255,255,255,0.65);
}
.toast-body { flex: 1; word-break: break-word; }
.toast-close {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.55;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.toast-close:hover { opacity: 1; }

@media (max-width: 480px) {
  .toast-host {
    left: 0.75rem;
    right: 0.75rem;
    top: 0.75rem;
    max-width: none;
    align-items: stretch;
  }
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-card.chart-wide { grid-column: 1 / -1; }
  .page-grid { grid-template-columns: 1fr; }
  .form-row-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    width: min(300px, 88vw) !important;
    max-width: 320px;
    height: 100%;
    height: 100dvh;
    box-shadow: 12px 0 36px rgba(6, 37, 28, 0.28);
    padding: calc(1rem + var(--safe-top)) 0.85rem calc(1.1rem + var(--safe-bottom)) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    overflow: auto;
  }
  body.sidebar-collapsed .sidebar {
    width: min(300px, 88vw) !important;
    transform: translateX(-105%);
    padding: calc(1rem + var(--safe-top)) 0.85rem calc(1.1rem + var(--safe-bottom)) !important;
  }
  body.sidebar-collapsed .sidebar-brand > div:not(.brand-mark) {
    display: block;
  }
  body.sidebar-collapsed .sidebar nav a {
    justify-content: flex-start;
  }
  body.sidebar-collapsed .sidebar nav a .nav-text {
    display: inline;
  }
  body.nav-open .sidebar,
  body.nav-open.sidebar-collapsed .sidebar {
    transform: translateX(0);
  }
  .topbar-account-text { display: none; }
  .topbar-account { padding-right: 0; max-width: none; }
  .user-menu-meta { display: none; }
  .user-menu-caret { display: none; }
  .main {
    padding: 1rem 1rem calc(1.4rem + var(--safe-bottom));
  }
  .page-head {
    margin-bottom: 0.85rem;
    align-items: flex-start;
  }
  .page-head h2 { font-size: 1.22rem; }
  .page-head .desc { font-size: 0.84rem; }
  .page-head .btn { width: 100%; }
  .toolbar {
    gap: 0.5rem;
    margin-bottom: 0.85rem;
  }
  .search-bar {
    margin-left: 0;
    width: 100%;
  }
  .search-bar input[type="search"] {
    flex: 1 1 140px;
    width: auto;
    min-width: 0;
  }
  .form .row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
  .chart-grid { grid-template-columns: 1fr; }
  table.data { min-width: 560px; display: table; }
  .mobile-list { display: none; }
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
  }
  .desktop-only { display: none !important; }
  .actions { flex-wrap: wrap; }
  .actions .btn { margin-bottom: 0.2rem; }
  .pager {
    flex-wrap: wrap;
    gap: 0.45rem;
  }
}

.qr-stage {
  position: relative;
  width: 200px;
  min-height: 200px;
  margin-top: 0.35rem;
}
.qr-stage.is-empty {
  display: none;
}
.qr-stage.is-ready,
.qr-stage.is-loading {
  display: block;
}
.qr-stage #qr-canvas,
.qr-stage #qr-img,
.qr-stage .qr-box {
  width: 200px;
  height: 200px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  display: block;
  box-sizing: border-box;
  object-fit: contain;
}
.qr-stage .qr-box {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.qr-stage .qr-box img,
.qr-stage .qr-box canvas {
  display: block;
  width: 184px !important;
  height: 184px !important;
}
.qr-stage #qr-canvas[hidden],
.qr-stage #qr-img[hidden],
.qr-stage .qr-box[hidden] {
  display: none !important;
}
.qr-loading {
  width: 200px;
  height: 200px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fafaf8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  text-align: center;
  box-sizing: border-box;
}
.qr-loading[hidden] { display: none !important; }
.qr-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #ebe6d8;
  border-top-color: #e6b800;
  border-radius: 50%;
  animation: qr-spin 0.75s linear infinite;
}
@keyframes qr-spin {
  to { transform: rotate(360deg); }
}
.qr-loading-text {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.site-logo-edit {
  margin: 0.35rem 0 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafaf8;
}
.site-logo-preview {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}
.site-logo-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .toolbar .btn { flex: 1 1 calc(50% - 0.35rem); }
  .toolbar .btn.primary,
  .toolbar .btn.danger { flex: 1 1 100%; }
  .search-bar { flex: 1 1 100%; }
  .search-bar select { flex: 1 1 auto; min-width: 0; }
  .drawer-panel,
  .drawer-root.drawer-wide .drawer-panel { width: 100vw; }
  .chart-canvas-wrap { height: 220px; }
  .m-card .actions .btn { flex: 1 1 auto; }
  .stat-card .value { font-size: 1.45rem; }
}
