:root {
  color-scheme: light;
  --bg: #eef1f5;
  --panel: #ffffff;
  --line: #d7dde7;
  --text: #111827;
  --muted: #667085;
  --blue: #1167f2;
  --green: #0f9f6e;
  --red: #c43636;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, textarea {
  font: inherit;
}
button {
  border: 0;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}
button.secondary {
  background: #e7ecf4;
  color: var(--text);
}
.hidden { display: none !important; }
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-panel {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
}
.login h1 {
  margin: 0 0 18px;
  font-size: 26px;
}
.login form {
  display: grid;
  gap: 10px;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}
textarea {
  min-height: 86px;
  resize: vertical;
}
#loginError { color: var(--red); min-height: 20px; }
.shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.brand {
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand strong { font-size: 18px; }
.brand span {
  color: var(--green);
  font-weight: 700;
  font-size: 12px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.stat {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.stat strong { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12px; }
.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.tab {
  background: #e7ecf4;
  color: var(--text);
}
.tab.active {
  background: var(--blue);
  color: #fff;
}
.conversation-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}
.visitor-list {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}
.invite-panel {
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.invite-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}
.visitor-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  color: var(--text);
  text-align: left;
}
.visitor-row strong, .visitor-row span, .visitor-row a {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.visitor-row span {
  color: var(--muted);
  font-size: 12px;
}
.visitor-row a {
  max-width: min(760px, 55vw);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}
.visitor-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--green);
  font-weight: 800;
}
.visitor-status:before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}
.conversation {
  width: 100%;
  display: block;
  text-align: left;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 9px;
}
.conversation.active { border-color: var(--blue); }
.conversation b, .conversation span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}
.badge {
  float: right;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: var(--red);
  color: #fff;
  font-size: 12px;
}
.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}
#sitesTab {
  display: block;
  overflow: auto;
}
.chat-head {
  min-height: 76px;
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.chat-head > div:first-child {
  min-width: 0;
}
.chat-head h2 {
  margin: 0;
  font-size: 20px;
}
.chat-head span {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}
.chat-url {
  display: block;
  max-width: min(760px, 62vw);
  overflow: hidden;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
.typing-text {
  min-height: 18px;
  color: var(--green) !important;
  font-weight: 800;
}
.head-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}
#closeBtn { background: #5b6472; }
.messages {
  min-height: 0;
  padding: 18px 20px;
  overflow: auto;
}
.empty {
  color: var(--muted);
  margin: 24px 0;
}
.message {
  max-width: min(820px, 82%);
  margin: 0 0 12px;
}
.message.operator {
  margin-left: auto;
}
.bubble {
  display: inline-block;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  white-space: pre-wrap;
}
.operator .bubble {
  background: #eaf1ff;
  border-color: #c8d9ff;
}
.meta {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 4px;
}
.operator .meta { text-align: right; }
.reply {
  padding: 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.site-form {
  align-self: start;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.site-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}
.site-form label:nth-child(n + 5), .site-actions {
  grid-column: 1 / -1;
}
.check-row {
  align-content: center;
  grid-template-columns: auto 1fr !important;
  min-height: 42px;
}
.check-row input {
  width: 18px;
  height: 18px;
}
.site-actions {
  display: flex;
  gap: 10px;
}
.danger {
  background: var(--red);
}
.install-box {
  margin: 0 20px 18px;
  background: #101828;
  color: #fff;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
}
.install-box strong, .install-box code {
  display: block;
}
.install-box code {
  margin-top: 8px;
  color: #bfe1ff;
}
.sites-list {
  padding: 0 20px 20px;
  display: grid;
  gap: 10px;
}
.site-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.site-row {
  cursor: pointer;
  text-align: left;
}
.site-row.is-disabled {
  opacity: .62;
}
.site-row code {
  color: var(--blue);
}
.site-row strong, .site-row span {
  display: block;
}
.site-row span { color: var(--muted); }

@media (max-width: 840px) {
  body { overflow: auto; }
  .shell { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .sidebar { height: 44vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace { height: 56vh; }
  .site-form { grid-template-columns: 1fr; }
}
