:root {
  --brand: #0a7cff;
  --brand-strong: #0867d8;
  --brand-soft: #eaf3ff;
  --brand-message: #d9fdd3;
  --page: #edf2f7;
  --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: #53b0ff;
  --brand-strong: #2f9bff;
  --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 {
  position: relative;
  isolation: isolate;
  min-height: 100%;
  overflow: auto;
  padding: clamp(24px, 5vw, 64px);
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 10% 18%, rgba(45, 212, 191, .24), transparent 30%),
    radial-gradient(circle at 88% 82%, rgba(34, 197, 94, .18), transparent 28%),
    linear-gradient(145deg, #071c21 0%, #0a3030 48%, #0d3f36 100%);
}
.login-view::before,
.login-view::after {
  content: '';
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(4px);
  pointer-events: none;
}
.login-view::before { width: 360px; height: 360px; top: -150px; right: -90px; border: 1px solid rgba(255,255,255,.12); box-shadow: 0 0 0 55px rgba(255,255,255,.025), 0 0 0 110px rgba(255,255,255,.018); }
.login-view::after { width: 240px; height: 240px; bottom: -110px; left: -70px; background: rgba(32, 201, 151, .08); box-shadow: 0 0 0 45px rgba(32,201,151,.035); }
.login-shell {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 430px);
  gap: clamp(36px, 7vw, 88px);
  align-items: center;
}
.login-brand {
  min-width: 0;
  display: grid;
  gap: 30px;
  color: #fff;
}
.login-brand-top { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.login-online {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  color: rgba(255,255,255,.88);
  background: rgba(255,255,255,.07);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 750;
}
.login-online i { width: 8px; height: 8px; border-radius: 50%; background: #42e695; box-shadow: 0 0 0 5px rgba(66,230,149,.12); }
.login-copy { max-width: 620px; }
.login-brand h1 {
  margin: 8px 0 14px;
  color: #fff;
  font-size: clamp(48px, 7vw, 78px);
  line-height: .95;
  letter-spacing: -.055em;
}
.login-brand p { max-width: 580px; margin: 0; color: rgba(237,255,250,.76); font-size: clamp(16px, 2vw, 19px); line-height: 1.65; }
.eyebrow { display: block; color: #59e3b2; font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .18em; }
.login-features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.login-features > div {
  min-width: 0;
  padding: 16px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 3px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 18px;
  background: rgba(255,255,255,.055);
  backdrop-filter: blur(12px);
}
.login-features > div > span { grid-row: 1 / 3; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; color: #04271f; background: #6ee7b7; font-size: 17px; font-weight: 900; }
.login-features strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.login-features small { color: rgba(237,255,250,.62); font-size: 10px; line-height: 1.35; }
.brand-mark {
  width: 56px; height: 56px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(145deg, #20c997, #087f5b);
  box-shadow: 0 16px 34px rgba(0,0,0,.18);
  font-size: 24px; font-weight: 900;
}
.login-brand .brand-mark { width: 72px; height: 72px; border-radius: 23px; background: linear-gradient(145deg, #5ee7b1, #18a678); color: #05382d; box-shadow: 0 20px 50px rgba(4, 15, 18, .35); font-size: 31px; }
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px; font-size: 15px; box-shadow: none; }
.brand-visual { display: grid; place-items: center; }
.brand-logo { width: 82px; height: 82px; display: block; object-fit: contain; border-radius: 18px; background: rgba(255,255,255,.92); box-shadow: var(--shadow-sm); }
.brand-logo.small { width: 36px; height: 36px; border-radius: 11px; box-shadow: none; }
.login-brand .brand-logo { width: 72px; height: 72px; border-radius: 22px; }
.login-card {
  position: relative;
  padding: clamp(26px, 4vw, 38px);
  display: grid;
  gap: 18px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 28px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 35px 90px rgba(0, 12, 15, .34);
  backdrop-filter: blur(18px);
}
.login-card::before { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; background: linear-gradient(145deg, rgba(255,255,255,.52), transparent 38%); }
.login-card > * { position: relative; }
.login-card-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 4px; }
.login-card-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: #fff; background: linear-gradient(145deg, #18a678, #087f5b); box-shadow: 0 10px 24px rgba(8,127,91,.24); font-size: 20px; font-weight: 900; }
.login-card h2 { margin: 0 0 3px; color: #102a2e; font-size: 27px; letter-spacing: -.025em; }
.login-card p { margin: 0; color: #718087; font-size: 13px; }
.login-card label { gap: 8px; color: #33484d; font-size: 12px; }
.login-card input { min-height: 50px; padding-inline: 15px; border-color: #dce7e8; border-radius: 14px; color: #142a2f; background: #f7fafb; }
.login-card input::placeholder { color: #98a6ab; }
.login-card input:focus { border-color: #18a678; background: #fff; box-shadow: 0 0 0 4px rgba(24,166,120,.11); }
.login-submit { min-height: 52px; margin-top: 3px; display: flex; align-items: center; justify-content: space-between; padding-inline: 18px; border-radius: 15px; background: linear-gradient(135deg, #18a678, #087f5b); box-shadow: 0 14px 30px rgba(8,127,91,.24); }
.login-submit:hover { background: linear-gradient(135deg, #20b985, #087f5b); }
.login-submit b { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 9px; background: rgba(255,255,255,.16); }
.login-security { display: flex; align-items: center; justify-content: center; gap: 7px; color: #8a999e; font-size: 10px; }
.login-security span { color: #22b573; font-size: 9px; }
.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 {
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .07);
  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: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'%3E%3Cg fill='none' stroke='%23c8c1b7' stroke-width='1.25' opacity='.34'%3E%3Cpath d='M28 40c8-10 24-8 28 3 4 12-9 22-20 18l-9 6 2-11c-8-4-8-11-1-16z'/%3E%3Cpath d='M116 34l8 8 11-3-5 10 7 9-12-1-6 10-3-12-12-3 10-6z'/%3E%3Cpath d='M222 32c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zm-7 17h14m-14 10h9'/%3E%3Cpath d='M342 28l18 8-9 8 7 16-17-8-9 8-5-17z'/%3E%3Cpath d='M63 135c0-12 10-22 22-22h12l9-9 9 9h12c12 0 22 10 22 22v18c0 12-10 22-22 22H85c-12 0-22-10-22-22z'/%3E%3Cpath d='M199 121c14 0 25 11 25 25s-11 25-25 25-25-11-25-25 11-25 25-25zm-8 25h16m-8-8v16'/%3E%3Cpath d='M302 116l13 13 18-5-6 18 12 14-19-1-10 16-5-18-18-5 15-10z'/%3E%3Cpath d='M29 239c12-8 29-2 32 12 3 13-8 25-21 24l-11 9 2-15c-9-8-10-22-2-30z'/%3E%3Cpath d='M128 229h42v34h-42z m8 8h26m-26 9h18'/%3E%3Cpath d='M239 226c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zm-8 17c5-5 11-5 16 0m-17 10c6 6 12 6 18 0'/%3E%3Cpath d='M337 231l18 19-11 11-19-18z m-13 10l-9 19 19-8'/%3E%3Cpath d='M56 335l17-9 16 9-3 19-13 10-15-10z'/%3E%3Cpath d='M158 326c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zm-6 14h12v16h-12z'/%3E%3Cpath d='M247 332h45v29h-45z m8 7h29m-29 8h18'/%3E%3Cpath d='M349 326c8 0 15 7 15 15 0 12-15 24-15 24s-15-12-15-24c0-8 7-15 15-15z'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 420px 420px;
  background-attachment: local;
  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: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 92%, var(--surface-2)); box-shadow: 0 -8px 20px rgba(15, 23, 42, .04); }
.composer textarea { min-height: 44px; max-height: 136px; resize: none; border: 1px solid transparent; padding: 11px 14px; background: var(--panel); box-shadow: 0 1px 2px rgba(15, 23, 42, .03); border-radius: 16px; }
.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: 16px; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, white), var(--surface)); box-shadow: 0 8px 26px rgba(15, 23, 42, .05); }
.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; gap: 8px; border-top: 4px solid var(--stage-color); border-radius: 12px 12px 0 0; font-size: 12px; font-weight: 850; }
.stage-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-header-right { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; }
.stage-edit, .stage-delete { width: 25px; height: 25px; display: grid; place-items: center; border: 0; border-radius: 7px; background: var(--panel); color: var(--muted); font-weight: 900; }
.stage-edit:hover { color: var(--brand); background: var(--brand-soft); }
.stage-delete:hover { color: var(--danger); background: var(--danger-soft); }
.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 {
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .07); 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: 900px) and (min-width: 521px) {
  .login-shell { grid-template-columns: 1fr minmax(340px, 390px); gap: 32px; }
  .login-features { grid-template-columns: 1fr; }
  .login-brand h1 { font-size: 54px; }
}

@media (max-width: 520px) {
  .login-view { padding: 18px; place-items: start center; }
  .login-shell { display: grid; grid-template-columns: 1fr; gap: 22px; }
  .login-brand { gap: 16px; }
  .login-brand-top { justify-content: flex-start; }
  .login-online { margin-left: auto; }
  .login-brand .brand-mark, .login-brand .brand-logo { width: 54px; height: 54px; border-radius: 17px; font-size: 23px; }
  .login-brand h1 { margin-block: 5px 8px; font-size: 40px; }
  .login-brand p { font-size: 14px; line-height: 1.5; }
  .login-features { grid-template-columns: 1fr; gap: 8px; }
  .login-features > div { padding: 11px 13px; }
  .login-features > div > span { width: 30px; height: 30px; }
  .login-card { padding: 24px 20px; border-radius: 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)):not(:has(.inline-media-shell))::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;
}

/* v2.4 - mídia interna e automações visuais */
.inline-media-button { display: block; max-width: 100%; margin: 0 0 5px; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: transparent; cursor: zoom-in; }
.inline-media-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
.audio-label { margin-bottom: 4px; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.audio-label strong { color: var(--text); }
.audio-review { min-width: min(520px, 100%); display: grid; grid-template-columns: minmax(120px, .65fr) minmax(220px, 1fr); gap: 12px; align-items: center; }
.audio-review div { display: grid; gap: 2px; }
.audio-review small { color: var(--muted); }
.audio-review audio { width: 100%; }
.upload-preview-actions { display: flex; flex: 0 0 auto; gap: 6px; align-items: center; }
.media-viewer-modal { width: min(1120px, calc(100% - 24px)); background: rgba(9, 16, 20, .98); }
.media-viewer-content { min-height: min(72vh, 760px); padding: 18px; display: grid; place-items: center; }
.media-viewer-content img, .media-viewer-content video { max-width: 100%; max-height: 76vh; object-fit: contain; border-radius: 10px; }

.automation-settings { border-bottom: 1px solid var(--line); background: var(--surface); }
.compact-heading { padding-bottom: 4px; }
.compact-heading p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.automation-settings-form { padding: 8px 18px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; align-items: end; }
.check-card { min-height: 60px; padding: 10px; display: flex; grid-template-columns: none; flex-direction: row; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.check-card input { width: 18px; height: 18px; margin: 0; }
.check-card span { display: grid; gap: 2px; }
.check-card strong { color: var(--text); }
.check-card small { color: var(--muted); }
.workflow-layout { min-height: 620px; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.workflow-sidebar { min-width: 0; padding: 14px; border-right: 1px solid var(--line); background: var(--surface); }
.workflow-sidebar-heading { margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.workflow-sidebar-heading h3 { margin: 0; }
.workflow-list { display: grid; gap: 6px; }
.workflow-list-item { width: 100%; min-width: 0; padding: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 10px; text-align: left; background: var(--panel); }
.workflow-list-item.active { border-color: var(--brand); box-shadow: inset 3px 0 var(--brand); }
.workflow-list-item span:first-child { min-width: 0; display: grid; gap: 3px; }
.workflow-list-item strong, .workflow-list-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workflow-list-item small { color: var(--muted); font-size: 9px; }
.compact-empty { min-height: 100px; padding: 14px; }
.workflow-editor { min-width: 0; background: var(--chat-bg); }
.empty-workflow { min-height: 620px; padding: 30px; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--muted); text-align: center; }
.empty-workflow strong { color: var(--text); font-size: 18px; }
.workflow-editor-header { position: sticky; top: 68px; z-index: 4; padding: 12px 14px; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, .8fr) auto auto; gap: 10px; align-items: end; border-bottom: 1px solid var(--line); background: var(--panel); }
.workflow-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.node-toolbar { position: sticky; top: 147px; z-index: 3; padding: 8px 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.node-toolbar span { margin-right: 4px; color: var(--muted); font-size: 10px; font-weight: 800; }
.node-toolbar button { min-height: 30px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel); font-size: 10px; }
.workflow-canvas { min-height: 500px; padding: 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 34px 28px; align-items: start; background-image: radial-gradient(color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px); background-size: 18px 18px; }
.workflow-node { position: relative; min-width: 0; border: 1px solid var(--line); border-top: 4px solid var(--node-color, var(--brand)); border-radius: 13px; background: var(--panel); box-shadow: var(--shadow-sm); }
.workflow-node.node-trigger { --node-color: #627d98; }
.workflow-node.node-message { --node-color: #2f80ed; }
.workflow-node.node-menu { --node-color: #9b51e0; }
.workflow-node.node-condition { --node-color: #f2994a; }
.workflow-node.node-handoff { --node-color: #00a884; }
.workflow-node.node-close { --node-color: #eb5757; }
.workflow-node.node-stage { --node-color: #219653; }
.workflow-node > header { padding: 10px 11px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; border-bottom: 1px solid var(--line); }
.workflow-node > header > div { min-width: 0; display: grid; gap: 2px; }
.workflow-node > header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workflow-node > header small { color: var(--muted); font-size: 8px; }
.node-type { width: fit-content; padding: 2px 6px; border-radius: 8px; color: #fff; background: var(--node-color, var(--brand)); font-size: 8px; font-weight: 900; text-transform: uppercase; }
.workflow-node-body { padding: 11px; display: grid; gap: 9px; }
.workflow-node-body textarea { resize: vertical; }
.node-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.workflow-node-port { position: absolute; left: 50%; width: 13px; height: 13px; border: 3px solid var(--panel); border-radius: 50%; background: var(--node-color, var(--brand)); transform: translateX(-50%); }
.input-port { top: -10px; }
.output-port { bottom: -10px; }

@media (max-width: 900px) {
  .audio-review { grid-template-columns: 1fr; }
  .upload-preview { align-items: stretch; flex-direction: column; }
  .upload-preview-actions { justify-content: flex-end; }
  .automation-settings-form { grid-template-columns: 1fr; }
  .automation-settings-form .span-2 { grid-column: auto; }
  .workflow-layout { grid-template-columns: 1fr; }
  .workflow-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .workflow-list { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .workflow-editor-header { top: 68px; grid-template-columns: 1fr 1fr; }
  .workflow-actions { grid-column: 1 / -1; justify-content: stretch; }
  .workflow-actions button { flex: 1; }
  .node-toolbar { top: 205px; }
}

@media (max-width: 560px) {
  .workflow-editor-header { position: static; grid-template-columns: 1fr; }
  .node-toolbar { position: static; }
  .workflow-canvas { padding: 18px 12px; grid-template-columns: 1fr; }
  .node-grid { grid-template-columns: 1fr; }
  .audio-wrap { min-width: min(250px, 68vw); }
}
.menu-options-editor { display: grid; gap: 8px; padding: 9px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface); }
.menu-options-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-option-list { display: grid; gap: 7px; }
.menu-option-row { display: grid; grid-template-columns: minmax(70px, .45fr) minmax(120px, 1fr) minmax(130px, 1fr) 32px; gap: 6px; align-items: end; padding: 7px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.menu-option-row label { min-width: 0; }
.menu-option-row .icon-button { margin-bottom: 2px; }
@media (max-width: 650px) {
  .menu-option-row { grid-template-columns: 74px minmax(0, 1fr) 32px; }
  .menu-option-row label:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  .menu-option-row .icon-button { grid-column: 3; grid-row: 1; }
}

/* v2.5 - setores, limpeza e estabilidade de modais */
.chat-control-bar { grid-template-columns: repeat(5, minmax(132px, 1fr)); }
.danger { min-height: 40px; border: 0; border-radius: 9px; padding: 9px 13px; color: #fff; background: var(--danger); font-weight: 850; }
.danger:hover { filter: brightness(.94); }

.users-content { min-width: 0; max-height: 72vh; overflow: auto; display: grid; align-content: start; }
.department-manager { border-bottom: 1px solid var(--line); background: var(--surface); }
.department-form { padding: 10px 18px 16px; display: grid; grid-template-columns: minmax(180px, 1fr) 90px auto; gap: 10px; align-items: end; }
.department-form input[type="color"] { height: 38px; padding: 3px; }
.department-form-actions { display: flex; gap: 6px; }
.departments-list { padding: 0 18px 16px; display: grid; gap: 7px; }
.department-row { min-width: 0; padding: 10px; display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.department-dot { width: 10px; height: 10px; border-radius: 50%; }
.department-row strong, .department-row small { display: block; }
.department-row small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.department-actions { display: flex; gap: 6px; }

.system-summary { padding: 18px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; border-bottom: 1px solid var(--line); }
.branding-settings { margin: 18px; padding: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.branding-settings > div:first-child { grid-column: 1 / -1; }
.branding-settings h3 { margin: 0; }
.branding-settings p { margin: 4px 0 0; color: var(--muted); }
.branding-preview { grid-column: 1 / -1; display: grid; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.branding-preview > div { min-height: 62px; padding: 12px; display: flex; align-items: center; gap: 12px; border: 1px dashed var(--line); border-radius: 12px; background: var(--panel); color: var(--text); }
.branding-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.summary-card { min-height: 86px; padding: 14px; display: grid; place-content: center; gap: 3px; border: 1px solid var(--line); border-radius: 12px; text-align: center; background: var(--surface); }
.summary-card strong { color: var(--brand-strong); font-size: 24px; }
.summary-card span { color: var(--muted); font-size: 10px; }
.danger-zone { margin: 18px; padding: 18px; display: grid; gap: 14px; border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line)); border-radius: 14px; background: color-mix(in srgb, var(--danger-soft) 72%, var(--panel)); }
.danger-zone h3 { margin: 0; color: var(--danger); }
.danger-zone p { margin: 4px 0 0; color: var(--muted); line-height: 1.5; }

.modal.hidden, .modal-backdrop.hidden { display: none !important; }
body:has(.modal:not(.hidden)) { overflow: hidden; }

@media (max-width: 980px) {
  .chat-control-bar { grid-template-columns: repeat(5, minmax(122px, 150px)); }
  .users-layout { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .department-form { grid-template-columns: 1fr 82px; }
  .department-form-actions { grid-column: 1 / -1; }
  .system-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .users-layout { grid-template-columns: 1fr; }
  .user-editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .users-content { max-height: none; }
  .department-form { grid-template-columns: minmax(0, 1fr) 72px; padding-inline: 12px; }
  .departments-list { padding-inline: 12px; }
  .department-row { grid-template-columns: 12px minmax(0, 1fr); }
  .department-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

@media (max-width: 520px) {
  .chat-control-bar { grid-template-columns: repeat(5, minmax(112px, 132px)); }
  .system-summary { grid-template-columns: 1fr 1fr; padding: 12px; }
  .danger-zone { margin: 12px; padding: 14px; }
  .branding-settings { margin: 12px; padding: 14px; grid-template-columns: 1fr; }
  .branding-settings > div, .branding-preview, .branding-actions { grid-column: 1; }
}

/* v2.6 - mídia inline e permissões de setores */
.inline-document-button { width: 100%; text-align: left; cursor: pointer; }
.media-document-frame { width: min(980px, 94vw); height: min(76vh, 820px); border: 0; border-radius: 10px; background: #fff; }
.audio-wrap { display: grid; gap: 6px; }
.audio-label { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.audio-wrap audio { display: block; max-width: 100%; }
.department-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.user-editor .instance-permissions { min-width: 0; }
@media (max-width: 760px) {
  .media-document-frame { width: 100%; height: 70vh; }
  .audio-wrap { min-width: min(240px, 72vw); }
}

/* v2.8 — mídia interna confiável e controle de requisições */
.inline-media-shell { display: grid; gap: 6px; max-width: min(540px, 100%); }
.media-load-error {
  display: none;
  max-width: 360px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--danger) 36%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 10%, var(--panel));
  color: var(--text);
  font-size: 11px;
  line-height: 1.35;
}
.media-load-error.visible { display: block; }
.media-load-warning { color: var(--muted); font-size: 10px; }
.audio-wrap audio { min-width: min(320px, 68vw); }
@media (max-width: 520px) {
  .audio-wrap audio { min-width: min(250px, 76vw); }
}

/* v2.8 — mantém no máximo três avisos e evita pilhas de erros repetidos */
.toast[data-repeated]:not([data-repeated="1"])::after {
  content: " ×" attr(data-repeated);
  font-weight: 800;
  opacity: .82;
}

/* v3.0 — mídia recebida sempre permanece dentro do chat */
.inline-document-button { width: 100%; text-align: left; cursor: pointer; }
.media-load-error.visible { margin-top: 8px; }


/* v3.2.4: transferência e integração NotificaMe */
.transfer-control {
  min-height: 48px;
  align-self: end;
  white-space: nowrap;
}
.instance-provider-status {
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--soft);
  font-size: 11px;
  color: var(--muted);
}
.instance-provider-status strong { color: var(--text); }
@media (min-width: 1180px) {
  .chat-control-bar { grid-template-columns: repeat(5, minmax(118px, 1fr)) auto; }
}

.ext-embed{font-family: ui-monospace,SFMono-Regular,Menlo,monospace; font-size:12px; min-height:92px;}

/* v3.2.26 — eventos de transferência e chat do site */
.transfer-event-row {
  justify-content: center;
  margin: 13px 0;
}
.transfer-event {
  max-width: min(900px, 94%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid #f1cfaa;
  border-radius: 999px;
  color: #a75b20;
  background: #fff8ef;
  box-shadow: 0 1px 3px rgba(116, 67, 25, .08);
  font-size: 12px;
  text-align: center;
}
.transfer-event-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #efbd8d;
  border-radius: 50%;
  font-weight: 900;
}
.transfer-event small {
  color: #b77a48;
  white-space: nowrap;
}
[data-theme="dark"] .transfer-event {
  color: #ffd2a7;
  border-color: #714b2b;
  background: #322319;
}
[data-theme="dark"] .transfer-event small { color: #dba77a; }

#webchatInstanceForm {
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--line));
  border-radius: 16px;
  background: color-mix(in srgb, var(--brand-soft) 38%, var(--panel));
}
.instance-card[data-channel="webchat"] .channel-icon {
  color: #fff;
  background: linear-gradient(135deg, #0a7cff, #20b99a);
}
.instance-card[data-channel="webchat"] .ext-embed {
  min-height: 112px;
  resize: vertical;
}


[data-theme="dark"] .message-list {
  background-color: #0b141a;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'%3E%3Cg fill='none' stroke='%236a747a' stroke-width='1.25' opacity='.18'%3E%3Cpath d='M28 40c8-10 24-8 28 3 4 12-9 22-20 18l-9 6 2-11c-8-4-8-11-1-16z'/%3E%3Cpath d='M116 34l8 8 11-3-5 10 7 9-12-1-6 10-3-12-12-3 10-6z'/%3E%3Cpath d='M222 32c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zm-7 17h14m-14 10h9'/%3E%3Cpath d='M342 28l18 8-9 8 7 16-17-8-9 8-5-17z'/%3E%3Cpath d='M63 135c0-12 10-22 22-22h12l9-9 9 9h12c12 0 22 10 22 22v18c0 12-10 22-22 22H85c-12 0-22-10-22-22z'/%3E%3Cpath d='M199 121c14 0 25 11 25 25s-11 25-25 25-25-11-25-25 11-25 25-25zm-8 25h16m-8-8v16'/%3E%3Cpath d='M302 116l13 13 18-5-6 18 12 14-19-1-10 16-5-18-18-5 15-10z'/%3E%3Cpath d='M29 239c12-8 29-2 32 12 3 13-8 25-21 24l-11 9 2-15c-9-8-10-22-2-30z'/%3E%3Cpath d='M128 229h42v34h-42z m8 8h26m-26 9h18'/%3E%3Cpath d='M239 226c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zm-8 17c5-5 11-5 16 0m-17 10c6 6 12 6 18 0'/%3E%3Cpath d='M337 231l18 19-11 11-19-18z m-13 10l-9 19 19-8'/%3E%3Cpath d='M56 335l17-9 16 9-3 19-13 10-15-10z'/%3E%3Cpath d='M158 326c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zm-6 14h12v16h-12z'/%3E%3Cpath d='M247 332h45v29h-45z m8 7h29m-29 8h18'/%3E%3Cpath d='M349 326c8 0 15 7 15 15 0 12-15 24-15 24s-15-12-15-24c0-8 7-15 15-15z'/%3E%3C/g%3E%3C/svg%3E");
}

.chat-presence {
  flex: 0 1 auto;
  max-width: 260px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid color-mix(in srgb, #22c55e 32%, var(--line));
  border-radius: 999px;
  color: color-mix(in srgb, #16a34a 78%, var(--text));
  background: color-mix(in srgb, #22c55e 12%, var(--panel));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 800;
}
.chat-presence::before {
  content: '';
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px color-mix(in srgb, #22c55e 18%, transparent);
  animation: active-user-pulse 1.8s ease-in-out infinite;
}
.viewing-mini { background: #16803f !important; color: #fff !important; }
@keyframes active-user-pulse { 50% { opacity: .45; transform: scale(.82); } }

@media (max-width: 980px) {
  .chat-presence { max-width: 180px; padding-inline: 8px; }
}
@media (max-width: 700px) {
  .chat-presence { position: absolute; top: 58px; left: 50px; right: 8px; max-width: none; z-index: 5; justify-content: center; border-radius: 10px; }
}


/* Linha do tempo interna: atribuições e transferências */
.message-row.system-event {
  width: 100%;
  justify-content: center;
  margin: 12px 0;
  padding: 0 12px;
}
.system-event-card {
  width: min(760px, 94%);
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 28%, var(--line));
  border-radius: 999px;
  color: color-mix(in srgb, var(--text) 86%, var(--brand));
  background: color-mix(in srgb, var(--panel) 88%, var(--brand-soft));
  box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
}
.system-event-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--brand-strong);
  font-size: 14px;
  font-weight: 900;
}
.system-event.claimed .system-event-card {
  border-color: color-mix(in srgb, #20a464 35%, var(--line));
  background: color-mix(in srgb, var(--panel) 88%, #dff7e9);
}
.system-event.claimed .system-event-icon { background: #168a53; }
.system-event.closed .system-event-card {
  border-color: color-mix(in srgb, #d24b59 38%, var(--line));
  background: color-mix(in srgb, var(--panel) 88%, #fde9ec);
}
.system-event.closed .system-event-icon { background: #c83d4d; }
.system-event.reopened .system-event-card {
  border-color: color-mix(in srgb, #2f80ed 36%, var(--line));
  background: color-mix(in srgb, var(--panel) 88%, #e7f1ff);
}
.system-event.reopened .system-event-icon { background: #2f80ed; }
.system-event-content {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.system-event-content strong {
  color: inherit;
  font-size: 12px;
}
.system-event-content span {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}
.system-event-card time {
  white-space: nowrap;
  color: var(--muted);
  font-size: 10px;
}
[data-theme="dark"] .system-event-card {
  background: color-mix(in srgb, var(--surface) 90%, var(--brand-soft));
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
[data-theme="dark"] .system-event.claimed .system-event-card {
  background: color-mix(in srgb, var(--surface) 88%, #153d2a);
}
[data-theme="dark"] .system-event.closed .system-event-card {
  background: color-mix(in srgb, var(--surface) 88%, #461f28);
}
[data-theme="dark"] .system-event.reopened .system-event-card {
  background: color-mix(in srgb, var(--surface) 88%, #173553);
}
@media (max-width: 720px) {
  .system-event-card {
    width: 100%;
    grid-template-columns: 26px minmax(0, 1fr);
    border-radius: 16px;
  }
  .system-event-card time {
    grid-column: 2;
  }
}

/* Tickets v3.2.34 */
.ticket-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, .85fr) minmax(420px, 1.15fr);
  gap: 16px;
  padding: 0 18px 18px;
}
.ticket-list-panel,
.ticket-editor {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow: hidden;
}
.ticket-list-panel { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.ticket-filters {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(130px, .8fr);
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.ticket-filters .compact-check { align-self: center; min-height: 38px; }
.ticket-list {
  min-height: 260px;
  max-height: calc(100vh - 245px);
  overflow: auto;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 8px;
}
.ticket-card {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
  text-align: left;
}
.ticket-card:hover { background: var(--brand-soft); }
.ticket-card.low { border-left-color: #78909c; }
.ticket-card.normal { border-left-color: #2f80ed; }
.ticket-card.high { border-left-color: #ef9b23; }
.ticket-card.urgent,
.ticket-card.overdue { border-left-color: #d64550; }
.ticket-card.done { border-left-color: #38a169; opacity: .8; }
.ticket-card.compact { padding: 9px; gap: 5px; }
.ticket-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ticket-card-top strong { min-width: 0; overflow-wrap: anywhere; font-size: 12px; }
.ticket-status {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--brand-strong);
  background: var(--brand-soft);
  font-size: 9px;
  font-weight: 800;
}
.ticket-card-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; color: var(--muted); font-size: 10px; }
.ticket-card-meta b { color: var(--text); }
.ticket-card-meta time { margin-left: auto; }
.contact-ticket-list { display: grid; gap: 7px; }
.ticket-editor {
  max-height: calc(100vh - 175px);
  overflow: auto;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 12px;
}
.ticket-editor .editor-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.ticket-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.ticket-comments-wrap { padding-top: 14px; border-top: 1px solid var(--line); }
.ticket-comments { max-height: 230px; overflow: auto; display: grid; gap: 8px; margin-bottom: 10px; }
.ticket-comments > .ticket-comment { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ticket-comments > .ticket-comment strong { font-size: 11px; }
.ticket-comments > .ticket-comment p { margin: 5px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ticket-comments > .ticket-comment time { color: var(--muted); font-size: 9px; }
.ticket-comment-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.ticket-comment-form textarea { resize: vertical; }
.system-event.ticket .system-event-card,
.system-event.ticket-comment .system-event-card,
.system-event.ticket-reminder .system-event-card {
  border-color: color-mix(in srgb, #7b61d1 35%, var(--line));
  background: color-mix(in srgb, var(--panel) 90%, #eee9ff);
}
.system-event.ticket .system-event-icon,
.system-event.ticket-comment .system-event-icon,
.system-event.ticket-reminder .system-event-icon { background: #7357c8; }
.system-event.ticket-overdue .system-event-card {
  border-color: color-mix(in srgb, #d64550 42%, var(--line));
  background: color-mix(in srgb, var(--panel) 88%, #ffe8eb);
}
.system-event.ticket-overdue .system-event-icon { background: #d64550; }
[data-theme="dark"] .system-event.ticket .system-event-card,
[data-theme="dark"] .system-event.ticket-comment .system-event-card,
[data-theme="dark"] .system-event.ticket-reminder .system-event-card {
  background: color-mix(in srgb, var(--surface) 88%, #302753);
}
[data-theme="dark"] .system-event.ticket-overdue .system-event-card {
  background: color-mix(in srgb, var(--surface) 88%, #4b2027);
}
@media (max-width: 900px) {
  .ticket-layout { grid-template-columns: 1fr; overflow: auto; }
  .ticket-list { max-height: 310px; }
  .ticket-editor { max-height: none; }
}
@media (max-width: 560px) {
  .ticket-layout { padding: 0 8px 10px; gap: 10px; }
  .ticket-filters,
  .ticket-form-grid { grid-template-columns: 1fr; }
  .ticket-comment-form { grid-template-columns: 1fr; }
  .ticket-card-meta time { margin-left: 0; }
}
