:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #142033;
  --muted: #64748b;
  --line: #dbe4ef;
  --primary: #1d4ed8;
  --primary-weak: #dbeafe;
  --success: #0f8a5f;
  --warn: #b7791f;
  --danger: #c2410c;
  --shadow: 0 14px 36px rgba(15, 23, 42, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.shell { width: min(1440px, 100%); margin: 0 auto; padding: 20px; }
.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 10px;
  z-index: 10;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 250px; }
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; color: var(--muted); margin-top: 2px; font-size: 12px; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #172554;
  color: white;
  font-weight: 800;
}
.brand-mark.large { width: 54px; height: 54px; font-size: 24px; }
.top-nav { display: flex; align-items: center; gap: 6px; flex: 1; overflow-x: auto; }
.top-nav a {
  padding: 8px 10px;
  color: var(--muted);
  border-radius: 6px;
  white-space: nowrap;
}
.top-nav a.active, .top-nav a:hover { color: var(--primary); background: var(--primary-weak); }
.session-tools { display: flex; align-items: center; gap: 10px; color: var(--muted); white-space: nowrap; }

main { padding: 22px 0 60px; }
.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.hero h1, .detail-head h1 { margin: 6px 0; font-size: 34px; line-height: 1.1; }
.hero p, .detail-head p { margin: 0; color: var(--muted); max-width: 780px; line-height: 1.7; }
.eyebrow { margin: 0; color: var(--primary); font-weight: 700; text-transform: uppercase; font-size: 12px; }
.hero-actions, .detail-actions, .actions, .split-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 13px;
  background: white;
  color: var(--text);
  font-weight: 700;
}
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.ghost { border-color: var(--line); color: #1e293b; }
.btn.danger { background: #fff7ed; color: var(--danger); border-color: #fed7aa; }
.btn.small { min-height: 30px; padding: 5px 9px; font-size: 13px; }
.btn.full { width: 100%; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card, .panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.stat-card { padding: 16px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; font-size: 32px; margin: 8px 0 4px; }
.stat-card small { color: var(--muted); }

.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.panel { padding: 16px; min-width: 0; }
.panel.wide { min-width: 0; }
.panel h2 { margin: 0; font-size: 18px; }
.panel p { color: var(--muted); line-height: 1.6; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head p { margin: 4px 0 0; font-size: 13px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; background: #f8fafc; }
td { line-height: 1.45; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); font-size: 12px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
code, .code-block {
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 5px;
  color: #0f172a;
  overflow-wrap: anywhere;
}
.code-block { display: block; padding: 12px; line-height: 1.6; overflow-x: auto; }

.chip, .tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}
.chip.online, .chip.running { background: #dcfce7; color: #166534; }
.chip.offline, .chip.stopped { background: #e2e8f0; color: #475569; }
.chip.pending, .chip.paused { background: #fef3c7; color: #92400e; }
.chip.login_failed, .chip.proxy_error, .chip.error { background: #fee2e2; color: #991b1b; }
.tag { background: #eef2ff; color: #3730a3; margin: 2px; }

.form-stack { display: grid; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-hint { margin: -2px 0 0; font-size: 13px; }
label { display: grid; gap: 6px; color: #334155; font-weight: 700; font-size: 13px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 10px 11px;
  min-height: 38px;
}
textarea { resize: vertical; line-height: 1.5; }
.filter-input { max-width: 260px; }

.conversation-list { display: grid; gap: 8px; }
.conv-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.conv-item.active, .conv-item:hover { border-color: #93c5fd; background: #eff6ff; }
.conv-item strong, .conv-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item small { color: var(--muted); margin-top: 2px; }
.conv-item em {
  font-style: normal;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
  padding: 2px 6px;
  font-size: 12px;
}
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fee2e2;
  color: #991b1b;
  font-weight: 800;
}
.message-shell { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 14px; }
.conversation-panel, .chat-panel { min-height: 640px; }
.message-list { display: grid; gap: 12px; max-height: 480px; overflow: auto; padding-right: 4px; }
.message {
  max-width: 72%;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f1f5f9;
}
.message.outbound { margin-left: auto; background: #dbeafe; }
.message small { color: var(--muted); }
.message p { margin: 5px 0 0; color: var(--text); }
.send-box { display: grid; grid-template-columns: 180px minmax(0, 1fr) auto; gap: 8px; margin-top: 14px; }

.timeline { display: grid; gap: 10px; }
.log-item {
  border-left: 3px solid var(--line);
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 6px;
}
.log-item.warning { border-color: var(--warn); }
.log-item.error { border-color: var(--danger); }
.log-item.info { border-color: var(--primary); }
.log-item span { color: var(--muted); float: right; }
.log-item p { margin: 6px 0 0; color: #334155; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 14px; color: var(--muted); }

.diagram, .arch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.diagram span, .arch div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  font-weight: 800;
}
.diagram i, .arch i {
  width: 26px;
  height: 1px;
  background: var(--line);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 800; }

.login-wrap {
  min-height: calc(100vh - 110px);
  display: grid;
  place-items: center;
}
.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .brand-mark { margin: 0 auto 14px; }
.login-brand h1 { margin: 0; font-size: 26px; }
.login-brand p { margin: 8px 0 0; color: var(--muted); }

.detail-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.back-link { color: var(--primary); font-weight: 800; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.detail-grid div, .mini-block, .cookie-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}
.detail-grid span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.detail-grid strong { font-size: 16px; }
.qr-card img {
  display: block;
  width: 190px;
  height: 190px;
  margin: 0 auto 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: white;
}
.qr-actions { display: grid; gap: 8px; }
.detail-messages { max-height: 360px; }
.split-actions { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; }
.toast {
  margin: 14px 0 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}
.toast.success { background: #ecfdf5; color: #047857; border-color: #bbf7d0; }
.toast.error, .toast.danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.toast.warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .message-shell { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .app-header { align-items: flex-start; flex-wrap: wrap; }
  .top-nav { order: 3; width: 100%; }
}

@media (max-width: 640px) {
  .shell { padding: 12px; }
  .hero, .detail-head { display: block; }
  .hero-actions, .detail-actions { margin-top: 12px; }
  .hero h1, .detail-head h1 { font-size: 28px; }
  .stat-grid, .detail-grid, .form-grid, .send-box { grid-template-columns: 1fr; }
  .message { max-width: 100%; }
  table { min-width: 640px; }
}
