:root {
  --brand: #0b8f78;
  --brand-strong: #06715f;
  --brand-soft: #e4f7f1;
  --brand-message: #d9fdd3;
  --page: #eef2f4;
  --chat-bg: #efeae2;
  --panel: #ffffff;
  --surface: #f7f9fa;
  --surface-2: #eef2f4;
  --text: #172126;
  --muted: #667781;
  --line: #dfe5e8;
  --danger: #c83d4d;
  --danger-soft: #fdecee;
  --warning: #c3890d;
  --warning-soft: #fff4cf;
  --shadow-sm: 0 2px 10px rgba(20, 42, 52, .08);
  --shadow-lg: 0 20px 60px rgba(16, 35, 45, .24);
  --radius: 12px;
  --topbar-h: 64px;
}

[data-theme="dark"] {
  --brand: #20b99a;
  --brand-strong: #10a184;
  --brand-soft: #153a34;
  --brand-message: #075e54;
  --page: #0b141a;
  --chat-bg: #0b141a;
  --panel: #111b21;
  --surface: #182229;
  --surface-2: #202c33;
  --text: #e9edef;
  --muted: #9aa9b2;
  --line: #2d3b43;
  --danger-soft: #3b2228;
  --warning-soft: #3a321a;
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .22);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .52);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--page);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--panel);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
textarea { resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
label small, form small { color: var(--muted); font-size: 10px; font-weight: 400; }
h1, h2, h3, h4, p { margin-top: 0; }
.hidden { display: none !important; }
.grow { flex: 1; }
.span-2 { grid-column: 1 / -1; }
.full { width: 100%; }

.primary, .secondary, .ghost, .danger-soft, .note-button, .nav-action {
  border: 0;
  border-radius: 10px;
  padding: 9px 13px;
  font-weight: 700;
  transition: transform .1s, background .15s, border-color .15s, opacity .15s;
}
.primary:active, .secondary:active, .ghost:active, .danger-soft:active, .nav-action:active { transform: translateY(1px); }
.primary { background: var(--brand-strong); color: #fff; box-shadow: 0 5px 14px color-mix(in srgb, var(--brand) 20%, transparent); }
.primary:hover { background: var(--brand); }
.primary.large { min-height: 44px; }
.primary.compact, .ghost.compact { padding: 7px 10px; font-size: 11px; }
.secondary { color: var(--brand-strong); background: var(--brand-soft); }
.secondary:hover { filter: brightness(.97); }
.ghost { border: 1px solid var(--line); background: var(--panel); }
.ghost:hover { background: var(--surface); }
.danger-soft { color: var(--danger); background: var(--danger-soft); }
.note-button { color: #725b00; background: var(--warning-soft); }
.text-button { border: 0; padding: 4px; color: var(--brand); background: transparent; font-weight: 750; }
.icon-button, .composer-button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 17px;
}
.icon-button:hover, .composer-button:hover { color: var(--text); background: var(--surface-2); }

/* Login */
.login-view {
  min-height: 100%;
  overflow: auto;
  padding: 32px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 12% 15%, rgba(255, 255, 255, .18), transparent 26%),
    linear-gradient(135deg, #075e54 0%, #0d9b81 46%, var(--page) 46%);
}
.login-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 56px;
  align-items: center;
}
.login-brand { display: flex; align-items: flex-start; gap: 18px; color: #fff; }
.login-brand h1 { margin: 5px 0 8px; color: #fff; font-size: clamp(34px, 5vw, 58px); letter-spacing: -.04em; }
.login-brand p { max-width: 460px; color: rgba(255,255,255,.82); font-size: 17px; line-height: 1.6; }
.eyebrow { display: block; font-size: 12px; font-weight: 850; text-transform: uppercase; letter-spacing: .14em; opacity: .8; }
.brand-mark {
  width: 56px; height: 56px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(145deg, #1fcaa7, #05715f);
  box-shadow: 0 16px 34px rgba(0,0,0,.18);
  font-size: 24px; font-weight: 900;
}
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px; font-size: 15px; box-shadow: none; }
.login-card {
  padding: 30px;
  display: grid;
  gap: 16px;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
}
.login-card h2 { margin-bottom: 4px; font-size: 24px; }
.login-card p { margin-bottom: 0; color: var(--muted); }
.form-error { min-height: 17px; color: var(--danger); }

/* App shell */
.app { height: 100%; display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr); overflow: hidden; }
.topbar {
  position: relative;
  z-index: 30;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.brand { min-width: 160px; display: flex; align-items: center; gap: 10px; }
.brand strong { white-space: nowrap; }
.mobile-nav-button { display: none; }
.instance-status {
  flex: 0 0 auto;
  max-width: 190px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 7px 10px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
  white-space: nowrap;
}
.status-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #88959d; }
.status-dot.open { background: #25d366; box-shadow: 0 0 0 3px rgba(37,211,102,.15); }
.status-dot.connecting, .status-dot.reconnecting { background: #f5b942; animation: pulse 1.2s infinite; }
.status-dot.close, .status-dot.disconnected, .status-dot.disabled { background: #e45b68; }
.top-actions { margin-left: auto; min-width: 0; display: flex; align-items: center; gap: 3px; }
.nav-action { display: flex; align-items: center; gap: 5px; padding: 8px 9px; color: var(--muted); background: transparent; font-size: 11px; white-space: nowrap; }
.nav-action span { color: var(--brand); font-size: 14px; }
.nav-action b { font-weight: 650; }
.nav-action:hover { color: var(--text); background: var(--surface); }
.account-actions { display: flex; align-items: center; gap: 3px; }
.user-pill { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 7px 10px; border-radius: 16px; background: var(--surface); font-size: 11px; font-weight: 700; }
.mobile-nav-backdrop { position: fixed; inset: var(--topbar-h) 0 0; z-index: 26; background: rgba(5, 14, 18, .55); }

.workspace { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(290px, 340px) minmax(420px, 1fr) minmax(300px, 350px); background: var(--panel); }
.conversation-panel, .info-panel { min-height: 0; min-width: 0; background: var(--panel); }

/* Conversation list */
.conversation-panel { display: grid; grid-template-rows: auto auto auto auto minmax(0, 1fr); border-right: 1px solid var(--line); }
.panel-title { padding: 14px 14px 10px; display: flex; align-items: center; justify-content: space-between; }
.panel-title h2 { margin: 0 0 2px; font-size: 19px; letter-spacing: -.02em; }
.panel-title span { color: var(--muted); font-size: 10px; }
.conversation-state-tabs { padding: 0 12px 10px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.state-tab { min-width: 0; border: 0; border-radius: 9px; padding: 8px 6px; color: var(--muted); background: var(--surface); font-size: 11px; font-weight: 750; }
.state-tab.active { color: #fff; background: var(--brand-strong); }
.search-box { margin: 0 12px 9px; min-height: 40px; display: flex; align-items: center; gap: 7px; padding: 0 11px; border: 1px solid transparent; border-radius: 10px; color: var(--muted); background: var(--surface); }
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 12%, transparent); }
.search-box input { height: 38px; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.filters { padding: 0 12px 10px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.filters select { height: 34px; min-width: 0; padding: 6px 8px; font-size: 10px; text-overflow: ellipsis; }
.filter-chip { min-width: 0; border: 1px solid var(--line); border-radius: 16px; padding: 6px 8px; color: var(--muted); background: transparent; font-size: 10px; }
.filter-chip.active { border-color: var(--brand-strong); color: #fff; background: var(--brand-strong); }
.conversation-list { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.conversation-item { position: relative; min-width: 0; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conversation-item:hover, .conversation-item.active { background: var(--surface); }
.conversation-item.active { box-shadow: inset 3px 0 var(--brand); }
.avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: #49616c; background: #e4eaed; font-weight: 850; text-transform: uppercase; overflow: hidden; }
[data-theme="dark"] .avatar { color: #b8c8cf; background: #26343b; }
.avatar.large { width: 76px; height: 76px; font-size: 24px; }
.conversation-main { min-width: 0; }
.conversation-line { min-width: 0; display: flex; justify-content: space-between; gap: 8px; }
.conversation-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 750; }
.conversation-time { flex: 0 0 auto; color: var(--muted); font-size: 9px; }
.conversation-preview { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }
.conversation-meta { margin-top: 5px; display: flex; gap: 4px; flex-wrap: wrap; }
.mini-tag, .group-badge { padding: 3px 6px; border-radius: 10px; color: #fff; font-size: 8px; line-height: 1; font-weight: 850; }
.group-badge { background: #5865a6; }
.unread-badge { align-self: center; min-width: 20px; height: 20px; padding: 0 5px; display: grid; place-items: center; border-radius: 10px; color: #fff; background: var(--brand); font-size: 9px; font-weight: 800; }
.priority-mark { position: absolute; left: 4px; top: 8px; width: 4px; height: 30px; border-radius: 4px; background: var(--warning); }
.priority-mark.urgent { background: var(--danger); }

/* Chat */
.chat-panel { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--chat-bg); }
.empty-state { height: 100%; padding: 30px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 16px 0 5px; color: var(--text); font-size: 22px; }
.empty-state p { max-width: 420px; margin: 0; line-height: 1.5; }
.empty-illustration { width: 108px; height: 108px; display: grid; place-items: center; border-radius: 32px; background: color-mix(in srgb, var(--brand) 12%, var(--panel)); box-shadow: var(--shadow-sm); font-size: 46px; transform: rotate(-4deg); }
.active-chat { position: relative; height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto auto; }
.chat-header { min-height: 64px; min-width: 0; display: flex; align-items: center; gap: 9px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.chat-title { min-width: 0; display: grid; }
.chat-title strong, .chat-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title strong { font-size: 13px; }
.chat-title span { color: var(--muted); font-size: 9px; }
.chat-header-actions { margin-left: auto; min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 5px; }
.chat-header-actions select { width: auto; max-width: 145px; height: 34px; padding: 6px 8px; font-size: 10px; }
.chat-header-actions .danger-soft { height: 34px; padding: 6px 10px; font-size: 10px; }
.mobile-back { display: none; }
.message-list { min-height: 0; overflow: auto; padding: 22px clamp(16px, 4vw, 54px); background-color: var(--chat-bg); background-image: radial-gradient(rgba(120,110,90,.08) 1px, transparent 1px); background-size: 18px 18px; overscroll-behavior: contain; }
.message-row { display: flex; margin: 5px 0; }
.message-row.outgoing { justify-content: flex-end; }
.message-row.internal { justify-content: center; }
.message-bubble { position: relative; max-width: min(680px, 79%); padding: 8px 10px 6px; border-radius: 11px; background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.13); overflow-wrap: anywhere; }
.message-row.incoming .message-bubble { border-top-left-radius: 3px; }
.message-row.outgoing .message-bubble { border-top-right-radius: 3px; background: var(--brand-message); }
.message-row.internal .message-bubble { max-width: 86%; border: 1px dashed #d6b955; color: #4f4100; background: #fff3cd; }
[data-theme="dark"] .message-row.internal .message-bubble { color: #f4df87; background: #3c3317; }
.message-author { display: block; margin-bottom: 4px; color: var(--brand); font-size: 10px; font-weight: 850; }
.message-text { font-size: 13px; line-height: 1.42; white-space: pre-wrap; }
.message-meta { margin-top: 3px; display: flex; justify-content: flex-end; gap: 5px; color: var(--muted); font-size: 9px; }
.message-media { display: block; max-width: 100%; margin-bottom: 5px; border-radius: 8px; }
img.message-media { max-height: 440px; object-fit: contain; }
video.message-media { width: min(520px, 100%); }
.audio-wrap { min-width: min(310px, 72vw); }
.audio-wrap audio { width: 100%; height: 40px; }
.audio-download { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.document-media { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 8px; color: var(--text); background: rgba(255,255,255,.16); text-decoration: none; }
.reaction-button { position: absolute; top: 4px; right: -30px; width: 26px; height: 26px; border: 0; border-radius: 50%; opacity: 0; background: var(--panel); box-shadow: var(--shadow-sm); transition: opacity .15s; }
.message-row.outgoing .reaction-button { right: auto; left: -30px; }
.message-bubble:hover .reaction-button, .reaction-button:focus { opacity: 1; }
.message-reaction { position: absolute; bottom: -10px; left: 8px; padding: 1px 5px; border-radius: 10px; background: var(--panel); box-shadow: var(--shadow-sm); font-size: 13px; }
.reaction-menu { position: fixed; z-index: 100; display: flex; gap: 3px; padding: 6px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); box-shadow: var(--shadow-lg); }
.reaction-menu button { border: 0; padding: 4px; background: transparent; font-size: 19px; }
.scroll-bottom { position: absolute; right: 20px; bottom: 78px; z-index: 8; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); box-shadow: var(--shadow-sm); }
.composer-popovers { position: absolute; z-index: 15; left: 10px; bottom: 67px; max-width: calc(100% - 20px); }
.quick-reply-menu, .emoji-picker { max-height: min(330px, 48vh); overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow-lg); }
.emoji-picker { width: min(344px, calc(100vw - 24px)); padding: 8px; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
.emoji-picker button { min-height: 36px; border: 0; border-radius: 8px; background: transparent; font-size: 22px; }
.emoji-picker button:hover { background: var(--surface); }
.quick-reply-menu { width: min(430px, calc(100vw - 24px)); padding: 7px; }
.quick-reply-item { padding: 10px; border-radius: 9px; cursor: pointer; }
.quick-reply-item:hover, .quick-reply-item:focus { background: var(--surface); }
.quick-reply-item strong { display: block; font-size: 11px; }
.quick-reply-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.upload-preview { padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); background: var(--panel); font-size: 11px; }
.upload-preview span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recording-bar { min-height: 52px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); background: var(--panel); }
.recording-bar #recordingTime { margin-right: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.recording-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.composer { min-height: 62px; min-width: 0; display: flex; align-items: flex-end; gap: 5px; padding: 9px 10px calc(9px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface-2); }
.composer textarea { min-height: 42px; max-height: 136px; resize: none; border: 1px solid transparent; padding: 10px 12px; background: var(--panel); box-shadow: none; }
.composer textarea:focus { border-color: var(--brand); }
.composer-button { width: 38px; height: 42px; }
.record-button.recording { color: #fff; background: var(--danger); animation: pulse 1s infinite; }
.send-button { flex: 0 0 auto; width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 50%; color: #fff; background: var(--brand-strong); box-shadow: 0 5px 12px color-mix(in srgb, var(--brand) 23%, transparent); font-size: 18px; }

/* Information panel */
.info-panel { overflow: auto; border-left: 1px solid var(--line); }
.empty-info { min-height: 120px; height: 100%; padding: 28px; display: grid; place-items: center; text-align: center; color: var(--muted); }
.info-heading { position: sticky; top: 0; z-index: 4; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.info-heading h3 { margin: 0; }
.contact-summary { padding: 18px; display: grid; justify-items: center; gap: 5px; border-bottom: 1px solid var(--line); }
.contact-summary span { color: var(--muted); font-size: 11px; }
.contact-summary .group-badge { color: #fff; }
.info-section { padding: 14px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.info-section h4 { margin: 0; font-size: 13px; }
.two-columns { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.section-row { display: flex; align-items: center; justify-content: space-between; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-check { padding: 5px 8px; display: flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 14px; font-size: 10px; cursor: pointer; }
.tag-check input { width: auto; margin: 0; }
.tag-dot { width: 7px; height: 7px; border-radius: 50%; }
.history-list { display: grid; gap: 10px; }
.history-item { padding-left: 12px; border-left: 2px solid var(--line); font-size: 10px; }
.history-item strong { display: block; }
.history-item span { color: var(--muted); }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(3, 12, 17, .68); backdrop-filter: blur(2px); }
.modal { position: fixed; z-index: 51; top: 50%; left: 50%; width: min(720px, calc(100% - 28px)); max-height: calc(100% - 32px); overflow: auto; transform: translate(-50%, -50%); border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow-lg); }
.modal-sm { width: min(460px, calc(100% - 28px)); }
.modal-md { width: min(620px, calc(100% - 28px)); }
.modal-lg { width: min(900px, calc(100% - 28px)); }
.modal-xl { width: min(1440px, calc(100% - 28px)); }
.modal.fullscreen { inset: 10px; top: 0; left: 0; width: auto; max-height: none; transform: none; }
.modal > header { position: sticky; top: 0; z-index: 5; min-height: 68px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.modal h2 { margin: 0; font-size: 19px; }
.modal header p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.modal-header-actions { display: flex; gap: 7px; align-items: center; }
.modal-form { padding: 16px 18px; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; border-bottom: 1px solid var(--line); }
.modal-form.stacked { grid-template-columns: 1fr; }
.modal-toolbar { padding: 12px 18px; display: flex; align-items: end; gap: 10px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.instance-create-form label { min-width: 260px; }
.security-hint { margin: 12px 18px 0; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--warning) 28%, var(--line)); border-radius: 10px; color: var(--muted); background: var(--warning-soft); font-size: 10px; }
.saved-replies-list, .schedule-list { padding: 10px 18px 18px; }
.saved-reply-row, .schedule-row { min-width: 0; padding: 11px 0; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.saved-reply-row > div, .schedule-row > div { min-width: 0; }
.saved-reply-row small, .schedule-row small { display: block; margin-top: 3px; overflow-wrap: anywhere; color: var(--muted); font-size: 10px; }
.role-badge, .status-badge { padding: 4px 7px; border-radius: 10px; color: var(--brand); background: var(--brand-soft); font-size: 9px; font-weight: 850; }
.status-badge.failed, .status-badge.disconnected, .status-badge.close { color: var(--danger); background: var(--danger-soft); }
.status-badge.pending, .status-badge.processing, .status-badge.connecting, .status-badge.reconnecting { color: var(--warning); background: var(--warning-soft); }
.saved-form { grid-template-columns: 1fr 1fr; }
.campaign-form { padding: 18px; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; border-bottom: 1px solid var(--line); }
.section-heading { padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; }
.section-heading h3 { margin: 0; }
.instances-grid { padding: 15px 18px 22px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px; }
.instance-card { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.instance-card header { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.instance-card h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instance-card-grid { display: grid; gap: 10px; }
.switch-row { min-height: 34px; padding: 6px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; }
.switch-row input { width: 18px; height: 18px; margin: 0; }
.instance-actions { margin-top: 12px; display: flex; gap: 7px; flex-wrap: wrap; }
.kanban-board { min-height: 570px; padding: 16px; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(280px, 1fr); gap: 12px; overflow: auto; background: var(--surface); }
.kanban-column { min-height: 510px; border-radius: 12px; background: var(--surface-2); }
.kanban-column-header { padding: 12px; display: flex; align-items: center; justify-content: space-between; border-top: 4px solid var(--stage-color); border-radius: 12px 12px 0 0; font-size: 12px; font-weight: 850; }
.kanban-cards { min-height: 450px; padding: 8px; }
.kanban-card { padding: 11px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow-sm); cursor: grab; }
.kanban-card strong { display: block; font-size: 12px; }
.kanban-card p { margin: 5px 0; color: var(--muted); font-size: 10px; }
.kanban-card small { font-size: 9px; }
.kanban-column.dragover { outline: 2px dashed var(--brand); outline-offset: -4px; }
.qr-content { min-height: 300px; padding: 24px; display: grid; place-items: center; text-align: center; }
.qr-content img { width: min(300px, 100%); border-radius: 10px; }
.users-layout { min-height: 520px; display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); }
.user-editor { padding: 18px; display: grid; align-content: start; gap: 12px; border-right: 1px solid var(--line); background: var(--surface); }
.editor-heading { display: flex; align-items: center; justify-content: space-between; }
.editor-heading h3 { margin: 0; }
.instance-permissions { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 11px; }
.instance-permissions legend { padding: 0 5px; color: var(--text); font-size: 12px; font-weight: 800; }
.check-row { display: flex; grid-template-columns: none; flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.check-row input { width: 17px; height: 17px; margin: 0; }
.permission-grid { margin: 10px 0; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 7px; }
.permission-option { min-width: 0; padding: 8px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.permission-option input { width: 16px; height: 16px; margin: 0; }
.permission-option span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 10px; }
.users-list { min-width: 0; padding: 10px 18px 18px; overflow: auto; }
.user-row { min-width: 0; padding: 12px 0; display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.user-row > div { min-width: 0; }
.user-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row span.user-meta { display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }
.user-actions { display: flex; gap: 6px; }

/* Toasts */
.toast-container { position: fixed; z-index: 200; right: 18px; bottom: 18px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 270px; max-width: min(410px, calc(100vw - 36px)); padding: 12px 14px; border-radius: 10px; color: #fff; background: #34434b; box-shadow: var(--shadow-lg); font-size: 12px; animation: toastIn .18s ease; pointer-events: auto; }
.toast.error { background: #a43d3d; }
.toast.success { background: var(--brand-strong); }

@keyframes pulse { 50% { transform: scale(.92); opacity: .65; } }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

/* Large tablets / small laptops */
@media (max-width: 1420px) {
  .workspace { grid-template-columns: minmax(290px, 330px) minmax(420px, 1fr); }
  .info-panel {
    position: fixed;
    z-index: 24;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    width: min(370px, 94vw);
    transform: translateX(105%);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    transition: transform .2s ease;
  }
  .info-panel.open { transform: translateX(0); }
}

@media (max-width: 1180px) {
  .mobile-nav-button { display: grid; }
  .brand { min-width: auto; }
  .top-actions {
    position: fixed;
    z-index: 27;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(310px, 88vw);
    margin: 0;
    padding: 12px;
    display: grid;
    align-content: start;
    gap: 5px;
    overflow: auto;
    transform: translateX(-105%);
    border-right: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-lg);
    transition: transform .2s ease;
  }
  .top-actions.open { transform: translateX(0); }
  .nav-action { width: 100%; min-height: 44px; justify-content: flex-start; padding: 10px 12px; font-size: 12px; }
  .nav-action span { width: 26px; text-align: center; font-size: 18px; }
  .user-pill { display: none; }
}

@media (max-width: 820px) {
  :root { --topbar-h: 58px; }
  .topbar { gap: 5px; padding: 7px 8px; }
  .brand strong { display: none; }
  .brand-mark.small { width: 34px; height: 34px; }
  .instance-status { max-width: 148px; margin-right: auto; padding: 6px 8px; font-size: 10px; }
  .account-actions { gap: 0; }
  .account-actions .icon-button { width: 34px; height: 34px; }
  .workspace { position: relative; display: block; }
  .conversation-panel, .chat-panel { position: absolute; inset: 0; width: 100%; }
  .conversation-panel { z-index: 2; }
  .chat-panel { z-index: 4; transform: translateX(100%); transition: transform .2s ease; }
  .workspace.chat-open .chat-panel { transform: translateX(0); }
  .mobile-back { display: grid; }
  .chat-header { padding: 7px 8px; }
  .chat-header .avatar { width: 36px; height: 36px; }
  .chat-title { max-width: min(34vw, 210px); }
  .chat-header-actions { gap: 3px; }
  .chat-header-actions #chatStage, .chat-header-actions #chatAssignee { display: none; }
  .chat-header-actions select { max-width: 105px; height: 32px; padding: 5px; }
  .chat-header-actions .danger-soft { height: 32px; padding: 5px 7px; }
  .message-list { padding: 16px 12px; }
  .message-bubble { max-width: 88%; }
  .reaction-button { opacity: .7; }
  .composer { gap: 2px; padding-inline: 6px; }
  .composer-button { width: 34px; }
  .composer #attachBtn { display: none; }
  .composer textarea { padding-inline: 10px; }
  .info-panel { top: var(--topbar-h); width: min(390px, 100vw); }
  .modal { top: auto; bottom: 0; left: 0; width: 100%; max-height: calc(100% - 18px); transform: none; border-radius: 18px 18px 0 0; }
  .modal.fullscreen { inset: 0; border-radius: 0; }
  .modal > header { padding: 12px 14px; }
  .modal-header-actions .ghost { display: none; }
  .modal-form, .campaign-form, .saved-form { grid-template-columns: 1fr; padding: 14px; }
  .span-2 { grid-column: auto; }
  .modal-toolbar { align-items: stretch; flex-direction: column; padding: 14px; }
  .instance-create-form label { min-width: 0; }
  .security-hint { margin: 10px 14px 0; }
  .instances-grid { grid-template-columns: 1fr; padding: 12px 14px 18px; }
  .users-layout { display: block; }
  .user-editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .permission-grid { grid-template-columns: 1fr 1fr; }
  .saved-reply-row, .schedule-row { grid-template-columns: minmax(0,1fr) auto; }
  .saved-reply-row .danger-soft, .schedule-row .danger-soft { grid-column: 2; }
  .kanban-board { grid-auto-columns: minmax(82vw, 1fr); }
  .toast-container { right: 10px; bottom: 10px; left: 10px; }
  .toast { width: 100%; min-width: 0; max-width: none; }
}

@media (max-width: 520px) {
  .login-view { padding: 16px; background: linear-gradient(180deg, #075e54 0 34%, var(--page) 34%); }
  .login-shell { display: block; }
  .login-brand { margin-bottom: 24px; }
  .login-brand h1 { font-size: 32px; }
  .login-brand p { font-size: 14px; }
  .login-card { padding: 22px; }
  .instance-status span:last-child { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
  #soundBtn { display: none; }
  .conversation-item { padding-inline: 10px; }
  .chat-title { max-width: 31vw; }
  .chat-header-actions #automationMode { display: none; }
  .message-bubble { max-width: 92%; }
  .composer #emojiBtn { display: none; }
  .emoji-picker { grid-template-columns: repeat(7, minmax(0,1fr)); }
  .recording-bar { flex-wrap: wrap; }
  .recording-bar #recordingTime { margin-right: 0; }
  .permission-grid { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: minmax(0,1fr) auto; }
  .user-actions { grid-column: 1 / -1; }
}

/* v2.3 — omnichannel, assinatura e responsividade */
.active-chat {
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
}
.avatar { position: relative; flex: 0 0 auto; }
.avatar img {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  background: var(--surface-2);
}
.avatar > span { position: relative; z-index: 1; }
.chat-title { flex: 1 1 auto; }
.chat-title-line { min-width: 0; display: flex; align-items: center; gap: 7px; }
.chat-title-line strong { min-width: 0; }
.chat-primary-actions { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.compact-action { min-height: 34px; padding: 7px 10px; font-size: 10px; }
.instance-pill, .channel-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 180px;
  padding: 4px 7px;
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--line));
  border-radius: 999px;
  overflow: hidden;
  color: var(--brand-strong) !important;
  background: var(--brand-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 8px !important;
  font-weight: 850;
  letter-spacing: .02em;
}
.channel-pill { color: var(--muted) !important; background: var(--surface); }
.channel-mini { background: var(--brand-strong) !important; }
.contact-channel-line { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.chat-control-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(135px, 1fr));
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, var(--surface));
  scrollbar-width: thin;
}
.chat-control-bar label { min-width: 135px; gap: 3px; font-size: 9px; }
.chat-control-bar label > span { padding-left: 2px; }
.chat-control-bar select { height: 32px; padding: 5px 8px; border-radius: 8px; font-size: 10px; }
.message-bubble:has(.message-author):not(:has(.message-text)):not(:has(.message-media)):not(:has(.document-media))::after {
  content: "Conteúdo não informado pelo provedor";
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-style: italic;
}

.instance-create-tabs {
  padding: 12px 18px 0;
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.instance-create-tab {
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  padding: 10px 14px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 800;
}
.instance-create-tab.active { color: var(--brand-strong); background: var(--panel); border-color: var(--line); }
.external-instance-form {
  padding: 16px 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.external-credentials-notice {
  margin: 12px 18px 0;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line));
  border-radius: 12px;
  background: var(--brand-soft);
}
.external-credentials-notice strong { display: block; margin-bottom: 8px; }
.external-credentials-notice p { margin: 5px 0; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.external-credentials-notice code { color: var(--text); user-select: all; }
.external-credentials-notice > div { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 7px; }
.instance-title-wrap { min-width: 0; display: flex; align-items: center; gap: 9px; }
.instance-title-wrap > div { min-width: 0; }
.instance-title-wrap small { display: block; margin-top: 2px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
.channel-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(145deg, var(--brand), var(--brand-strong));
  font-size: 10px;
  font-weight: 900;
}
.external-card { border-color: color-mix(in srgb, var(--brand) 26%, var(--line)); }
.external-card .ext-inbound { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 9px; }

.campaign-recipient-panel {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.recipient-panel-heading { display: grid; grid-template-columns: auto minmax(180px, 1fr); gap: 12px; align-items: center; }
.recipient-panel-heading strong { font-size: 11px; }
.recipient-panel-heading input { height: 34px; }
.recipient-selection-toolbar { min-height: 32px; display: flex; align-items: center; gap: 10px; }
.recipient-selection-toolbar span { margin-right: auto; color: var(--muted); font-size: 10px; font-weight: 700; }
.recipient-multiselect {
  min-height: 210px;
  padding: 6px;
  border-radius: 10px;
  background: var(--panel);
}
.recipient-multiselect option { padding: 9px 10px; margin: 2px 0; border-radius: 7px; white-space: normal; }
.recipient-multiselect option:checked { color: #fff; background: var(--brand-strong) linear-gradient(0deg, var(--brand-strong), var(--brand-strong)); }

@media (max-width: 980px) {
  .chat-control-bar { grid-template-columns: repeat(4, minmax(125px, 150px)); }
  .chat-primary-actions .compact-action { padding-inline: 8px; }
}

@media (max-width: 820px) {
  .composer #attachBtn { display: grid; }
  .chat-header { min-height: 58px; }
  .chat-title { max-width: none; }
  .chat-title-line { gap: 5px; }
  .chat-title-line .instance-pill { max-width: 96px; }
  .chat-primary-actions { gap: 2px; }
  .chat-primary-actions #claimConversationBtn { display: none; }
  .chat-primary-actions .compact-action { min-height: 32px; padding: 5px 7px; font-size: 9px; }
  .chat-control-bar { padding: 7px 8px; grid-template-columns: repeat(4, minmax(120px, 145px)); }
  .external-instance-form { grid-template-columns: 1fr; padding: 14px; }
  .external-instance-form .span-2 { grid-column: auto; }
  .recipient-panel-heading { grid-template-columns: 1fr; gap: 6px; }
  .recipient-selection-toolbar { flex-wrap: wrap; gap: 5px; }
  .recipient-selection-toolbar span { width: 100%; }
  .recipient-multiselect { min-height: 240px; }
}

@media (max-width: 520px) {
  .conversation-panel { width: 100vw; }
  .composer #attachBtn { display: grid; }
  .conversation-state-tabs, .filters { gap: 7px; }
  .chat-header { gap: 6px; padding-inline: 6px; }
  .chat-header .avatar { width: 34px; height: 34px; }
  .chat-title strong { font-size: 12px; }
  .chat-title > span { max-width: 43vw; }
  .chat-title-line .instance-pill { max-width: 74px; padding-inline: 5px; }
  .chat-primary-actions #scheduleCurrentBtn { display: inline-flex; }
  .chat-primary-actions #closeConversationBtn { display: none; }
  .chat-control-bar { grid-template-columns: repeat(4, minmax(112px, 132px)); }
  .composer { gap: 1px; padding-inline: 4px; }
  .composer #emojiBtn { display: grid; }
  .composer-button { width: 31px; }
  .composer textarea { padding-inline: 8px; }
  .send-button { width: 39px; height: 39px; }
  .instance-create-tabs { padding-inline: 10px; }
  .instance-create-tab { flex: 1; padding: 9px 7px; font-size: 9px; }
  .external-credentials-notice { margin-inline: 12px; }
  .campaign-form { padding: 12px; }
  .recipient-multiselect { min-height: 260px; }
}
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
