:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel2: #f3f4f6;
  --panel3: #eceef1;
  --line: #e4e6ea;
  --text: #15171c;
  --muted: #6a7080;
  --faint: #9aa0ad;
  --accent: #3b66f5;
  --accent-hover: #2d55df;
  --accent-soft: #eaf0ff;
  --on-accent: #ffffff;
  --wait: #b45309;
  --wait-bg: #fff4e0;
  --busy: #2f5fe8;
  --busy-bg: #e8efff;
  --idle: #15803d;
  --idle-bg: #e5f6ea;
  --err: #c62828;
  --err-bg: #fdeaea;
  --off: #737986;
  --off-bg: #eceef1;
  --shadow: 0 1px 2px rgba(15, 20, 35, .06), 0 12px 32px rgba(15, 20, 35, .10);
  --shadow-sm: 0 1px 3px rgba(15, 20, 35, .08);
  --mask: rgba(10, 12, 18, .48);
  --topbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f11;
    --panel: #16171a;
    --panel2: #1c1e22;
    --panel3: #24272c;
    --line: #292c32;
    --text: #ececf0;
    --muted: #9096a4;
    --faint: #646a78;
    --accent: #7191ff;
    --accent-hover: #8aa5ff;
    --accent-soft: #1c2540;
    --on-accent: #0b0d14;
    --wait: #f2b25c;
    --wait-bg: #33260f;
    --busy: #86a4ff;
    --busy-bg: #1b2544;
    --idle: #5fd08a;
    --idle-bg: #12301f;
    --err: #ff8a80;
    --err-bg: #3a1717;
    --off: #8c93a1;
    --off-bg: #24272c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px rgba(0, 0, 0, .55);
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, .35);
    --mask: rgba(0, 0, 0, .64);
  }
}

[data-theme="dark"] {
  --bg: #0e0f11;
  --panel: #16171a;
  --panel2: #1c1e22;
  --panel3: #24272c;
  --line: #292c32;
  --text: #ececf0;
  --muted: #9096a4;
  --faint: #646a78;
  --accent: #7191ff;
  --accent-hover: #8aa5ff;
  --accent-soft: #1c2540;
  --on-accent: #0b0d14;
  --wait: #f2b25c;
  --wait-bg: #33260f;
  --busy: #86a4ff;
  --busy-bg: #1b2544;
  --idle: #5fd08a;
  --idle-bg: #12301f;
  --err: #ff8a80;
  --err-bg: #3a1717;
  --off: #8c93a1;
  --off-bg: #24272c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px rgba(0, 0, 0, .55);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, .35);
  --mask: rgba(0, 0, 0, .64);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "PingFang SC", "Microsoft YaHei UI", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

button:disabled, select:disabled, input:disabled {
  opacity: .5;
  cursor: not-allowed;
}

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a {
  text-decoration: none;
}

svg {
  display: block;
  flex: none;
}

.sp {
  flex: 1;
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.app-root {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top Navigation Bar */
.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

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

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  flex: none;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--panel2);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--idle);
  flex: none;
}

.dot.offline {
  background: var(--off);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 5px;
  border-radius: 99px;
  background: var(--panel2);
  font-size: 13px;
  max-width: 170px;
}

.user-ava {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: none;
}

.user-ava img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  min-height: 36px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line);
  white-space: nowrap;
  transition: background .12s ease, opacity .12s ease;
}

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

.btn.pri {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: none;
}

.btn.pri:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.ghost {
  box-shadow: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 9px;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--panel2);
  color: var(--text);
}

.btn.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
}

.btn.danger {
  color: var(--err);
}

.btn.danger-solid {
  background: var(--err);
  color: #ffffff;
  box-shadow: none;
}

.btn.danger-solid:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

/* Workspace Two-Pane Layout */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.list-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 24px 32px;
}

/* Attention Banner */
.attn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--wait-bg);
  border-radius: 13px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.attn .ic {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--wait);
  color: #ffffff;
  display: grid;
  place-items: center;
  flex: none;
}

[data-theme="dark"] .attn .ic {
  color: #1b1204;
}

.attn .t {
  font-weight: 700;
  font-size: 14px;
}

.attn .s {
  font-size: 12.5px;
  color: var(--muted);
}

/* Search & Filter Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  color: var(--faint);
  pointer-events: none;
}

.search-inp {
  width: 100%;
  min-height: 40px;
  padding: 8px 34px 8px 36px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  outline: none;
  font-size: 13.5px;
}

.search-inp:focus {
  border-color: var(--accent);
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.search-clear:hover {
  background: var(--panel2);
  color: var(--text);
}

.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line);
  white-space: nowrap;
  flex: none;
}

.chip b {
  font-weight: 650;
  color: var(--text);
}

.chip.on {
  background: var(--text);
  color: var(--bg);
  box-shadow: none;
}

.chip.on b {
  color: var(--bg);
}

/* Bot List */
.list {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 16px;
  min-height: 64px;
  width: 100%;
  text-align: left;
  border-top: 1px solid var(--line);
  position: relative;
  transition: background .1s ease;
}

.row:first-child {
  border-top: 0;
}

.row:hover {
  background: var(--panel2);
}

.row.sel {
  background: var(--accent-soft);
}

.row.sel::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.ava {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 700;
  font-size: 16px;
  flex: none;
}

.ava.lg {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  font-size: 21px;
}

.row.dim .ava, .row.dim .nm {
  opacity: .55;
}

.rb {
  flex: 1;
  min-width: 0;
}

.nm {
  font-weight: 650;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.nm-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 650;
  padding: 2px 9px;
  border-radius: 99px;
  white-space: nowrap;
  flex: none;
}

.pill i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.p-waiting { color: var(--wait); background: var(--wait-bg); }
.p-busy { color: var(--busy); background: var(--busy-bg); }
.p-busy i { animation: pulse 1.4s ease-in-out infinite; }
.p-idle { color: var(--idle); background: var(--idle-bg); }
.p-error, .p-session_closed { color: var(--err); background: var(--err-bg); }
.p-disabled, .p-unknown { color: var(--off); background: var(--off-bg); }

.mgr-badge {
  font-size: 11px;
  font-weight: 650;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

@keyframes pulse {
  50% { opacity: .25; }
}

.meta {
  display: flex;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
  align-items: center;
  white-space: nowrap;
  flex: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--panel2);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row.sel .tag {
  background: var(--panel);
}

.chev {
  color: var(--faint);
  flex: none;
}

/* Detail Inspector Panel */
.detail-pane {
  width: 404px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mobile-back {
  display: none;
}

.dh {
  padding: 20px 20px 14px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex: none;
}

.dh-info {
  min-width: 0;
  flex: 1;
}

.dh .n {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  word-break: break-word;
}

.dh-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 5px;
}

.dbody {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 20px 28px;
}

.quick {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.sec {
  padding-top: 18px;
}

.sec h3 {
  font-size: 12px;
  color: var(--faint);
  font-weight: 650;
  margin: 0 0 8px;
  letter-spacing: .04em;
}

.card {
  background: var(--panel2);
  border-radius: 12px;
  overflow: hidden;
}

.kv {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  min-height: 46px;
}

.kv:first-child {
  border-top: 0;
}

.kv .k {
  color: var(--muted);
  font-size: 13.5px;
  flex: none;
}

.kv .v {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-weight: 600;
  font-size: 13.5px;
  min-width: 0;
  max-width: 68%;
  text-align: right;
}

.kv-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.kv-stack:first-child {
  border-top: 0;
}

.select-ctrl {
  max-width: 100%;
  min-height: 36px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.select-ctrl.full {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  font-weight: 500;
}

.select-ctrl:focus {
  border-color: var(--accent);
}

.mini {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--panel);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  box-shadow: 0 0 0 1px var(--line);
  max-width: 100%;
}

.mini.full {
  display: flex;
  width: 100%;
}

.mini button {
  padding: 5px 10px;
  min-height: 32px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}

.mini.full button {
  flex: 1;
  text-align: center;
}

.mini button.on {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
}

.pend {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px;
}

.pend .pt {
  font-weight: 650;
  font-size: 13.5px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 7px;
  line-height: 1.55;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  padding: 48px 24px;
}

.empty-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--faint);
  padding: 36px;
  text-align: center;
}

/* Modals & Bottom Sheets */
.mask {
  position: fixed;
  inset: 0;
  background: var(--mask);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.sheet {
  width: 460px;
  max-width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px;
  border: 1px solid var(--line);
}

.sheet h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.steps {
  display: flex;
  gap: 6px;
  margin: 12px 0 18px;
}

.steps span {
  flex: 1;
  height: 3.5px;
  border-radius: 2px;
  background: var(--panel3);
}

.steps span.on {
  background: var(--accent);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.inp {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  outline: none;
  font-size: 14px;
}

.inp:focus {
  border-color: var(--accent);
}

.static-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel2);
  font-size: 13.5px;
  color: var(--muted);
}

.qr-box {
  width: 188px;
  height: 188px;
  margin: 8px auto 14px;
  padding: 10px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

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

.center {
  text-align: center;
}

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

.ok-circle {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--idle-bg);
  color: var(--idle);
  display: grid;
  place-items: center;
  margin: 6px auto 12px;
}

.warn-box {
  background: var(--wait-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 13.5px;
  line-height: 1.6;
}

.err-box {
  background: var(--err-bg);
  color: var(--err);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 10px 0;
}

.summary-kv {
  background: var(--panel2);
  border-radius: 12px;
  padding: 4px 12px;
  margin: 12px 0;
}

.summary-kv .kv {
  padding: 8px 0;
  min-height: 36px;
}

/* Auth & Offline Full-Page States */
.center-screen {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.status-card {
  width: 400px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.status-card h2 {
  margin: 4px 0 0;
  font-size: 19px;
}

.status-card p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
}

.hero-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}

.hero-icon.offline {
  background: var(--panel2);
  color: var(--muted);
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  display: inline-block;
  flex: none;
}

.spinner.lg {
  width: 30px;
  height: 30px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toasts */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
  max-width: calc(100vw - 24px);
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  text-align: center;
}

.toast.err {
  background: var(--err);
  color: #ffffff;
}

/* Mobile Responsive (< 768px, verified at 390px) */
@media (max-width: 767px) {
  .topbar {
    padding: 0 10px;
    gap: 5px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .topbar .btn.pri {
    padding: 7px 11px;
  }

  .brand-title {
    font-size: 14.5px;
  }

  .conn-text {
    display: none;
  }

  .conn {
    padding: 6px;
  }

  .user-pill {
    display: none;
  }

  .btn {
    min-height: 40px;
  }

  .btn.sm {
    min-height: 36px;
  }

  .btn.icon-btn {
    width: 40px;
    height: 40px;
  }

  .create-label-full {
    display: none;
  }

  .list-scroll {
    padding: 12px 14px 28px;
  }

  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 2px 14px 4px;
    scrollbar-width: none;
  }

  .filters::-webkit-scrollbar {
    display: none;
  }

  .chip {
    min-height: 38px;
    padding: 6px 12px;
  }

  .row {
    padding: 12px 13px;
    gap: 11px;
  }

  .meta {
    display: none;
  }

  .workspace {
    position: relative;
  }

  .detail-pane {
    display: none;
    width: 100%;
    border-left: 0;
  }

  .workspace.mobile-detail .list-pane {
    display: none;
  }

  .workspace.mobile-detail .detail-pane {
    display: flex;
  }

  .mobile-back {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    min-height: 44px;
    border-bottom: 1px solid var(--line);
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    flex: none;
  }

  .desktop-close {
    display: none;
  }

  .dh {
    padding: 14px 16px 10px;
  }

  .dbody {
    padding: 0 14px 28px;
  }

  .kv {
    min-height: 48px;
  }

  .mini button {
    min-height: 38px;
    font-size: 12px;
    padding: 5px 7px;
  }

  .mask {
    align-items: end;
    padding: 0;
  }

  .sheet {
    width: 100%;
    border-radius: 22px 22px 0 0;
    padding: 20px 18px calc(22px + env(safe-area-inset-bottom, 0px));
    max-height: 90vh;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .qr-desktop-only {
    display: none;
  }
}

@media (min-width: 768px) {
  .create-label-short {
    display: none;
  }
}
