:root {
  --bg: #0f1419;
  --panel: #171e27;
  --card: #1d2630;
  --line: #2b3642;
  --text: #e8eef4;
  --muted: #93a4b5;
  --accent: #3d9cf0;
  --ok: #3ecf8e;
  --warn: #e7b549;
  --bad: #ef6b6b;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; }

aside {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.brand { margin: 0; font-weight: 700; letter-spacing: .02em; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
nav { display: flex; flex-direction: column; gap: 4px; }
nav button, .ghost, button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
}
nav button.active, button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #041018; font-weight: 600; }
.aside-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
select, input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

main { flex: 1; overflow: auto; padding: 20px 24px 40px; }
header h1 { margin: 0 0 4px; font-size: 22px; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.bot-pick {
  min-width: 220px;
  margin: 0;
}
.section-title { margin: 8px 0 12px; font-size: 16px; }
.session-list { display: flex; flex-direction: column; gap: 10px; }
.session-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.session-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.session-card-head strong { display: block; font-size: 15px; }
.session-card .row-actions { margin-top: 10px; }
.qr-inline { text-align: center; margin: 10px 0; }
.qr-inline img { width: 220px; height: 220px; background: #fff; border-radius: 8px; padding: 8px; }
.status-pill.ok { color: var(--ok); }
.status-pill.warn { color: var(--warn); }
.status-pill.bad { color: var(--bad); }
.wa-phone, .wa-time { color: var(--muted); font-size: 12px; }
.mode-box { display: flex; align-items: center; gap: 8px; }
button.danger { border-color: #6b3030; color: var(--bad); }
.env { color: var(--muted); margin: 0 0 16px; font-size: 13px; }
.tab { display: none; }
.tab.active { display: block; }

.card, table, .placeholder, .chat-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.form-grid h2 { grid-column: 1 / -1; margin: 0 0 4px; font-size: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions button { text-align: center; }
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  resize: vertical;
}
.workspace-dev h2 { margin: 0 0 8px; font-size: 16px; }
.workspace-dev { margin-top: 16px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; padding: 0; overflow: hidden; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.bubble { max-width: 720px; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; line-height: 1.4; }
.bubble.user { align-self: flex-end; background: #2a4158; }
.bubble.assistant { align-self: flex-start; background: #22302c; }
.bubble .meta { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; }

.note, .placeholder { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
a { color: var(--accent); }

.pay-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.pay-card { width: min(440px, 92vw); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.pay-card h1 { margin: 8px 0; }
.amount { font-size: 28px; font-weight: 700; }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; }
button.dev { width: 100%; background: var(--warn); border-color: var(--warn); color: #1a1404; font-weight: 700; padding: 12px; }
.hint { color: var(--muted); font-size: 12px; }
.token { font-size: 12px; color: var(--muted); word-break: break-all; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.ia-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.ia-status.ok { color: var(--ok); border-color: #2a6b4e; }
.ia-status.warn { color: var(--warn); border-color: #6b5a24; }
.ia-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.ia-section h2 { margin: 0 0 12px; font-size: 18px; }
.ia-section h3 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.ia-hidden { display: none !important; }
.bot-pick { display: none !important; }
.cfg-section h2 { margin: 0 0 12px; font-size: 18px; }
.cfg-section h3 { margin: 0 0 8px; font-size: 14px; }
.cfg-block { margin: 16px 0; padding-top: 8px; border-top: 1px solid var(--line); }
.cfg-toggle {
  min-width: 140px;
  text-align: center;
  font-weight: 700;
}
.cfg-toggle.on { background: #1f6b4a; border-color: #2f9d6a; color: #e8eef4; }
.cfg-toggle.off { background: transparent; color: var(--muted); }
.chats-session {
  min-width: min(420px, 46vw);
  margin-left: auto;
}
.chats-session label { margin: 0; color: #8696a0; }
.chats-session select {
  background: #202c33;
  border-color: #2a3942;
  color: #e9edef;
}
main.tab-chats-active {
  padding: 10px 16px 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  flex: 1;
}
main.tab-chats-active .page-head { margin-bottom: 10px; align-items: center; }
main.tab-chats-active #pageTitle { margin: 0; font-size: 20px; }
#tab-chats.tab.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}
.wa-layout {
  display: grid;
  grid-template-columns: minmax(320px, 32fr) minmax(0, 68fr);
  gap: 0;
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: calc(100vh - 88px);
  border: 1px solid #2a3942;
  border-radius: 4px;
  overflow: hidden;
}
.wa-list, .wa-thread {
  background: #111b21;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}
.wa-thread { background: #0b141a; border-left: 1px solid #2a3942; }
.wa-list { padding: 0; }
.wa-list-head {
  padding: 8px 10px;
  border-bottom: 1px solid #222d34;
  background: #111b21;
}
.wa-list-head input {
  background: #202c33;
  border: 0;
  border-radius: 8px;
  color: #e9edef;
  padding: 9px 12px;
}
.wa-items {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  margin: 0;
}
#tab-chats .wa-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid #222d34;
  border-radius: 0;
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  min-height: 64px;
  max-height: 64px;
  background: transparent;
  color: #e9edef;
  font-weight: 400;
}
#tab-chats .wa-item:hover { background: #202c33; }
#tab-chats .wa-item.active { background: #2a3942; }
.wa-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #6a7175;
  color: #e9edef;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: .02em;
}
.wa-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.wa-item-top, .wa-item-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
#tab-chats .wa-item strong {
  min-width: 0;
  flex: 1;
  font-size: 16px;
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}
.wa-preview {
  color: #8696a0;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.wa-time { color: #8696a0; font-size: 12px; flex-shrink: 0; }
#tab-chats .wa-item.active .wa-time { color: #8696a0; }
.unread {
  background: #00a884;
  color: #111b21;
  border-radius: 999px;
  font-size: 11px;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  padding: 0 6px;
  font-weight: 700;
  flex-shrink: 0;
}
.wa-empty { padding: 16px 14px; }
.wa-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid #2a3942;
  background: #202c33;
  align-items: center;
  min-height: 60px;
}
.wa-head-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.wa-head-text { min-width: 0; }
.wa-head-identity strong {
  display: block;
  font-size: 16px;
  color: #e9edef;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-head-identity .note { margin: 1px 0 0; color: #8696a0; font-size: 13px; }
.wa-head-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
#tab-chats .wa-head-btn {
  background: transparent;
  border: 1px solid #3b4a54;
  color: #e9edef;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
}
#tab-chats .wa-head-btn:hover { background: #2a3942; }
.wa-thread .chat-log {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 14px 10px;
  gap: 3px;
  background: #0b141a;
}
#tab-chats .bubble {
  display: flex;
  flex-direction: column;
  width: fit-content;
  max-width: 65%;
  min-width: 0;
  padding: 6px 11px 5px;
  border-radius: 7.5px;
  box-sizing: border-box;
  box-shadow: 0 1px 0.5px rgba(0,0,0,.13);
}
#tab-chats .bubble.in {
  align-self: flex-start;
  background: #202c33;
  color: #e9edef;
}
#tab-chats .bubble.out {
  align-self: flex-end;
  background: #005c4b;
  color: #e9edef;
}
#tab-chats .bubble-text {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
  font-size: 14.2px;
  min-width: 0;
}
#tab-chats .bubble-text a {
  overflow-wrap: anywhere;
  word-break: break-word;
}
#tab-chats .bubble-meta {
  display: flex;
  justify-content: flex-end;
  align-self: flex-end;
  margin-top: 2px;
  flex-shrink: 0;
}
#tab-chats .bubble-time {
  display: block;
  font-size: 11px;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}
#tab-chats .wa-items,
#tab-chats .wa-thread .chat-log {
  scrollbar-width: thin;
  scrollbar-color: #54656f transparent;
}
#tab-chats .wa-items::-webkit-scrollbar,
#tab-chats .wa-thread .chat-log::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
#tab-chats .wa-items::-webkit-scrollbar-track,
#tab-chats .wa-thread .chat-log::-webkit-scrollbar-track {
  background: transparent;
}
#tab-chats .wa-items::-webkit-scrollbar-thumb,
#tab-chats .wa-thread .chat-log::-webkit-scrollbar-thumb {
  background: #3b4a54;
  border-radius: 8px;
}
#tab-chats .wa-items::-webkit-scrollbar-thumb:hover,
#tab-chats .wa-thread .chat-log::-webkit-scrollbar-thumb:hover {
  background: #627884;
}
.wa-thread .chat-form {
  padding: 8px 12px 10px;
  background: #202c33;
  margin: 0;
  align-items: flex-end;
  gap: 8px;
}
#tab-chats .chat-form textarea {
  flex: 1;
  width: auto;
  min-height: 42px;
  max-height: 96px;
  resize: none;
  background: #2a3942;
  border: 0;
  border-radius: 8px;
  color: #e9edef;
  padding: 11px 14px;
  font: inherit;
  line-height: 1.35;
}
#tab-chats #waSend {
  background: #00a884;
  border-color: #00a884;
  color: #111b21;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
}
@media (max-width: 980px) {
  .wa-layout { grid-template-columns: minmax(0, 32fr) minmax(0, 68fr); }
  .chats-session { min-width: 220px; }
}
.qr-box { text-align: center; }
.qr-box img { width: 260px; height: 260px; background: #fff; border-radius: 8px; padding: 8px; }
.status-pill { font-size: 12px; }

.gateway-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.gateway-card h3 { margin: 0 0 8px; }
.gateway-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.payments-heading {
  margin: 8px 0 12px;
  font-size: 16px;
}
.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-card h2 { margin: 0; }
