:root {
  --ink: #173e38;
  --ink-soft: #54716b;
  --paper: #f4f8f4;
  --surface: #ffffff;
  --line: #dbe8e1;
  --primary: #176f67;
  --primary-dark: #115a54;
  --primary-soft: #e4f1ed;
  --danger: #a6473c;
  --danger-soft: #f8ebe8;
  --warning: #8a631d;
  --sidebar: #153e38;
  --sidebar-ink: #eff8f4;
  --sidebar-muted: #a8c3bc;
  --radius: 14px;
  --shadow: 0 12px 32px rgb(18 24 22 / 8%);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
* { scrollbar-color: #aec9bf transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 999px; background: #aec9bf; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgb(23 111 103 / 28%); outline-offset: 2px; }
::selection { background: #bde5da; color: var(--ink); }

.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;
}

.login-shell {
  width: min(440px, calc(100% - 32px));
  margin: clamp(56px, 12vh, 130px) auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 36px;
  box-shadow: var(--shadow);
}
.login-brand, .brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  font-size: 23px;
  font-weight: 700;
}
.login-shell h1 { margin: 24px 0 0; font-size: 28px; letter-spacing: -.025em; }
.login-lead { margin: 8px 0 24px; color: var(--ink-soft); }
.login-form { display: grid; gap: 16px; }
.login-form label, .field { display: grid; gap: 7px; }
.login-form label > span, .field > span {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbdcd5;
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
textarea { resize: vertical; line-height: 1.65; }
input:hover, select:hover, textarea:hover { border-color: #a9c9be; }
input[readonly] { background: #f3f7f5; color: #667b76; cursor: default; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(23 111 103 / 10%);
  outline: none;
}
.login-submit { width: 100%; margin-top: 4px; }
.login-help { display: block; margin: 12px auto 0; }
.login-note { margin: 20px 0 0; color: #5b6f69; font-size: 12px; }
.form-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 12px; }
.form-error.is-success { color: var(--primary); }
.form-hint { margin: 14px 0 0; color: var(--ink-soft); font-size: 12px; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
}
.brand-block { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; }
.brand-block .brand-mark { background: #eff8f4; color: var(--sidebar); }
.brand-block strong { display: block; font-size: 18px; }
.brand-block small { display: block; color: var(--sidebar-muted); font-size: 11px; }
.side-nav { flex: 1; overflow-y: auto; }
.nav-label {
  margin: 18px 10px 7px;
  color: #789a92;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
}
.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--sidebar-muted);
  padding: 9px 12px;
  text-align: left;
  transition: background-color .16s ease, color .16s ease;
}
.nav-item:hover { background: rgb(255 255 255 / 7%); color: white; }
.nav-item.is-active { background: #f0f8f4; color: var(--sidebar); font-weight: 700; }
.sidebar-footer { border-top: 1px solid rgb(255 255 255 / 11%); padding: 16px 9px 0; }
.connection-line { display: flex; align-items: center; gap: 8px; color: var(--sidebar-muted); font-size: 12px; }
#connectionDot { width: 8px; height: 8px; border-radius: 50%; background: #e3ae58; }
#connectionDot.is-online { background: #59d0a8; }
#connectionDot.is-degraded { background: #d97706; box-shadow: 0 0 0 4px rgb(217 119 6 / 12%); }
.text-button { border: 0; background: transparent; color: #c8ded8; padding: 10px 0 0; }
.text-button:hover { color: white; }

.workspace { min-width: 0; padding: 26px clamp(20px, 3.5vw, 52px) 60px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin: -8px 0 24px;
  padding: 8px 0 14px;
  background: var(--paper);
}
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.topbar p { margin: 5px 0 0; color: var(--ink-soft); }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.save-state { color: var(--ink-soft); font-size: 12px; }
.save-state.is-dirty { color: var(--warning); font-weight: 600; }
.primary-button, .secondary-button, .small-button, .danger-button {
  min-height: 40px;
  border-radius: 10px;
  padding: 8px 14px;
  border: 1px solid transparent;
  font-weight: 600;
  transition: background-color .16s ease, border-color .16s ease, transform .16s ease;
}
.primary-button { background: var(--primary); color: white; }
.primary-button:hover { background: var(--primary-dark); }
.secondary-button { background: white; border-color: #c9dbd3; color: var(--ink); }
.secondary-button:hover { border-color: #8db9aa; background: #f8fbf9; }
.small-button { min-height: 32px; padding: 5px 10px; background: var(--primary-soft); color: var(--primary); }
.small-button:hover { background: #d5ebe4; }
.danger-button { background: var(--danger-soft); color: var(--danger); border-color: #eccac4; }
.text-link { border: 0; background: transparent; color: var(--primary); padding: 6px 0; font-weight: 600; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}
.metric { min-height: 92px; background: var(--surface); padding: 16px; }
.metric span { display: block; color: var(--ink-soft); font-size: 12px; }
.metric strong { display: block; margin-top: 8px; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.surface {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.surface + .surface { margin-top: 16px; }
.surface-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.surface-heading h2 { margin: 0; font-size: 17px; }
.surface-heading p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }
.release-summary { display: grid; gap: 12px; }
.release-row { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid #edf3ef; padding-bottom: 10px; }
.release-row:last-child { border-bottom: 0; padding-bottom: 0; }
.release-row span { color: var(--ink-soft); }
.quick-links { display: grid; gap: 8px; }
.quick-links button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f9fcfa;
  padding: 10px 12px;
  text-align: left;
}
.quick-links button:hover { border-color: #a7c9bd; }
.quick-links span { color: var(--ink-soft); font-size: 12px; }
.activity-list { display: grid; gap: 10px; }
.activity-row { display: flex; justify-content: space-between; gap: 18px; padding: 10px 0; border-bottom: 1px solid #edf3ef; }
.activity-row:last-child { border: 0; }
.activity-row p { margin: 0; }
.activity-row small { color: var(--ink-soft); }

.editor-layout { min-width: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.item-rail {
  min-width: 0;
  position: sticky;
  top: 20px;
  min-height: 360px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.rail-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.rail-heading h2 { margin: 0; font-size: 15px; }
.search-field input { min-height: 38px; }
.rail-list { min-height: 0; overflow: auto; margin-top: 10px; }
.rail-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  padding: 10px;
  text-align: left;
}
.rail-item:hover { background: #f5faf7; }
.rail-item.is-active { background: var(--primary-soft); border-color: #b8d9cd; }
.rail-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item small { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 11px; }
.editor-main { min-width: 0; display: grid; gap: 16px; }
.editor-titlebar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.editor-titlebar h2 { margin: 0; font-size: 20px; }
.editor-titlebar p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field-wide { grid-column: 1 / -1; }
.form-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 12px;
}
.form-section-title h3 { margin: 0; font-size: 15px; }
.form-section-title p { margin: 3px 0 0; color: var(--ink-soft); font-size: 12px; }
.button-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
#recoveryCode { flex: 1; min-width: 160px; }
.button-stack { display: grid; gap: 9px; }
.inline-note { color: var(--ink-soft); font-size: 12px; }

.table-wrap { width: 100%; overflow: auto; border: 1px solid #e2ece7; border-radius: 10px; background: #fff; padding: 8px; }
table { width: 100%; min-width: 720px; border-collapse: collapse; }
th, td { padding: 11px 12px; border-bottom: 1px solid #e9f0ec; text-align: left; vertical-align: top; }
th { background: #f5f9f6; color: var(--ink-soft); font-size: 11px; font-weight: 700; letter-spacing: .02em; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
.cell-actions { display: flex; gap: 6px; white-space: nowrap; }
.table-button { min-height: 30px; border: 1px solid #d3e2dc; border-radius: 8px; background: white; padding: 4px 9px; font-size: 12px; }
.table-button:hover { border-color: #9fc3b7; }
.table-button.is-danger { color: var(--danger); border-color: #e9cbc6; background: #fffafa; }
.empty-state { padding: 28px 16px; color: var(--ink-soft); text-align: center; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; background: #eef3f0; padding: 2px 8px; color: #5f746f; font-size: 11px; font-weight: 600; }
.status-pill.is-good { background: #e2f3eb; color: #17694f; }
.status-pill.is-warn { background: #fbf0d9; color: #80591a; }
.status-pill.is-blue { background: #e8eefb; color: #365b9e; }
.status-pill.is-danger { background: var(--danger-soft); color: var(--danger); }
.test-badge { display: inline-flex; align-items: center; border-radius: 999px; background: #fdf1d6; padding: 1px 7px; color: #8a5b00; font-size: 10px; font-weight: 700; line-height: 18px; vertical-align: middle; }

.filter-row { display: flex; gap: 9px; align-items: center; margin-bottom: 12px; }
.filter-row .search-field { flex: 1; }
.filter-row select { width: 150px; min-height: 38px; }
.publish-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(240px, .65fr); gap: 16px; margin-bottom: 16px; }
.publish-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: var(--line); margin-bottom: 16px; }
.publish-summary div { background: #fbfdfc; padding: 12px; }
.publish-summary span { display: block; color: var(--ink-soft); font-size: 11px; }
.publish-summary strong { display: block; margin-top: 4px; font-size: 18px; }
.inline-form { display: flex; align-items: end; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 200px; }

dialog {
  width: min(820px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgb(15 23 21 / 20%);
  padding: 8px;
}
dialog::backdrop { background: rgb(15 40 36 / 38%); }
.dialog-heading { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 20px; padding: 20px 22px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; font-size: 19px; }
.dialog-heading p { margin: 3px 0 0; color: var(--ink-soft); font-size: 12px; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: white; font-size: 21px; line-height: 1; }
#wordForm, #questionForm { display: grid; }
.editor-dialog .form-grid { padding: 20px 22px; }
.editor-dialog .form-error { padding: 0 22px; }
.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(380px, calc(100vw - 44px));
  transform: translateY(20px);
  opacity: 0;
  border-radius: 11px;
  background: #173e38;
  color: white;
  padding: 12px 16px;
  box-shadow: 0 12px 32px rgb(15 23 21 / 20%);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #8e4036; }

@media (max-width: 1180px) {
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px 18px; }
  .brand-block { padding-bottom: 12px; }
  .side-nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
  .nav-label { display: none; }
  .nav-item { width: auto; min-width: max-content; min-height: 38px; padding: 7px 12px; }
  .sidebar-footer { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; }
  .text-button { padding: 0; }
  .workspace { padding: 22px 18px 60px; }
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .item-rail { position: static; width: 100%; max-height: none; min-height: 0; }
  .rail-list { display: flex; gap: 7px; overflow-x: auto; }
  .rail-item { min-width: 190px; }
  .publish-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .publish-summary { grid-template-columns: repeat(2, 1fr); }
  .filter-row { flex-wrap: wrap; }
  .filter-row .search-field { flex-basis: 100%; }
  .quick-links button { align-items: flex-start; flex-direction: column; gap: 3px; }
  .login-shell { padding: 26px; }
}

/* Commerce, realtime, and user detail additions */
.metric-strip { grid-template-columns: repeat(5, minmax(0, 1fr)); }
#section-orders .table-wrap table { min-width: 980px; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.plan-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdfc;
  padding: 16px;
}
.plan-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.plan-card h3 { margin: 0; font-size: 16px; }
.plan-price { color: var(--primary); font-size: 26px; font-weight: 750; letter-spacing: -.03em; }
.plan-price small { color: var(--ink-soft); font-size: 11px; font-weight: 500; letter-spacing: 0; }
.plan-meta { color: var(--ink-soft); font-size: 12px; line-height: 1.65; }
.plan-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.feed-row { display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-bottom: 1px solid #edf3ef; }
.feed-row:last-child { border-bottom: 0; }
.feed-dot { width: 7px; height: 7px; margin-top: 7px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgb(23 111 103 / 10%); }
.feed-dot.is-blue { background: #4e78c9; box-shadow: 0 0 0 4px rgb(78 120 201 / 10%); }
.feed-dot.is-warn { background: #b48223; box-shadow: 0 0 0 4px rgb(180 130 35 / 11%); }
.feed-dot.is-danger { background: var(--danger); box-shadow: 0 0 0 4px rgb(166 71 60 / 10%); }
.feed-row p { margin: 0; font-size: 13px; }
.feed-row small { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 11px; }
.online-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf3ef; }
.online-row:last-child { border-bottom: 0; }
.online-row strong { display: block; font-size: 13px; }
.online-row small { color: var(--ink-soft); font-size: 11px; }
.order-actions { display: flex; gap: 6px; white-space: nowrap; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.user-detail-body { padding: 20px 22px 24px; display: grid; gap: 18px; }
.detail-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.detail-kpi { border: 1px solid var(--line); border-radius: 11px; background: #fbfdfc; padding: 12px; }
.detail-kpi span { display: block; color: var(--ink-soft); font-size: 11px; }
.detail-kpi strong { display: block; margin-top: 5px; font-size: 20px; font-variant-numeric: tabular-nums; }
.detail-section h3 { margin: 0 0 9px; font-size: 14px; }
.detail-section .table-wrap table { min-width: 620px; }
.raw-json { max-height: 260px; overflow: auto; border-radius: 10px; background: #102d28; color: #d4eee7; padding: 14px; font-size: 11px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
@media (max-width: 680px) {
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .detail-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
