[hidden] { display: none !important; }
:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #15803d;
  --soft: #f8fafc;
  --text: #0f172a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: #f1f5f9; color: var(--text); }
button, input, textarea, select { font: inherit; }
button { border: 0; border-radius: 12px; background: var(--accent); color: white; padding: 10px 14px; font-weight: 700; cursor: pointer; }
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: #e2e8f0; color: #0f172a; }
.login-shell { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at top left, #164e63, #0f172a 45%, #020617); padding: 24px; }
.login-card { width: min(420px, 100%); background: rgba(255,255,255,.96); border: 1px solid rgba(255,255,255,.4); border-radius: 28px; box-shadow: 0 25px 70px rgba(0,0,0,.32); padding: 30px; display: grid; gap: 14px; }
.brand-mark { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: linear-gradient(135deg, #0f766e, #0891b2); color: white; font-weight: 900; letter-spacing: .08em; }
.login-card h1 { margin: 0; font-size: 28px; }
.login-card p { margin: 0 0 6px; color: var(--muted); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: #334155; }
input, textarea, select { border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: white; color: var(--text); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.error-message { background: #fee2e2; color: #991b1b; padding: 10px 12px; border-radius: 12px; font-size: 14px; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: #0f172a; color: white; }
.topbar strong { display: block; font-size: 17px; }
.topbar span { color: #cbd5e1; font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.layout { height: calc(100vh - 64px); display: grid; grid-template-columns: 340px minmax(360px, 1fr) 320px; gap: 1px; background: var(--line); }
.sidebar, .chat-panel, .details-panel { background: var(--panel); min-height: 0; }
.sidebar { display: flex; flex-direction: column; }
.filter-box { padding: 12px; display: grid; grid-template-columns: 1fr; gap: 8px; border-bottom: 1px solid var(--line); }
.conversation-list { overflow: auto; }
.conversation-item { display: grid; gap: 5px; padding: 13px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conversation-item:hover, .conversation-item.active { background: #ecfeff; }
.conversation-line { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conversation-name { font-weight: 800; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conversation-phone, .conversation-preview, .conversation-meta { color: var(--muted); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.unread { min-width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--accent); color: white; font-size: 12px; font-weight: 800; }
.status-chip { display: inline-block; border-radius: 999px; padding: 3px 8px; background: #e2e8f0; color: #334155; font-size: 11px; font-weight: 800; }
.chat-panel { min-width: 0; }
.empty-state { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.chat-view { height: 100%; display: grid; grid-template-rows: auto 1fr auto auto; min-height: 0; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.chat-header h2 { margin: 0; font-size: 18px; }
.chat-header span { color: var(--muted); font-size: 13px; }
.window-badge { border-radius: 999px; padding: 6px 10px; background: #dcfce7; color: #166534; font-size: 12px; font-weight: 900; }
.window-badge.closed { background: #fee2e2; color: #991b1b; }
.messages { overflow: auto; padding: 18px; background: #f8fafc; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: min(640px, 88%); padding: 10px 12px; border-radius: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.08); white-space: pre-wrap; word-break: break-word; }
.message.inbound { align-self: flex-start; background: white; border-bottom-left-radius: 4px; }
.message.outbound { align-self: flex-end; background: #ccfbf1; border-bottom-right-radius: 4px; }
.message-meta { display: flex; gap: 8px; margin-top: 5px; color: #64748b; font-size: 11px; }
.quick-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); background: white; align-items: end; }
.composer textarea { resize: vertical; min-height: 54px; max-height: 160px; }
.send-hint { min-height: 26px; color: var(--muted); font-size: 12px; padding: 0 14px 10px; }
.details-panel { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.details-panel h3 { margin: 0 0 4px; }
.info-card { background: var(--soft); border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.info-card p { margin: 8px 0; color: #334155; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; color: #334155; font-size: 12px; }

.chat-title-area { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mobile-back { display: none; padding: 8px 10px; border-radius: 10px; background: #e2e8f0; color: #0f172a; white-space: nowrap; }

@media (max-width: 1100px) { .layout { grid-template-columns: 300px 1fr; } .details-panel { display: none; } }
@media (max-width: 760px) {
  html, body { width: 100%; min-height: 100%; overflow: hidden; }
  body { background: #fff; }

  .login-shell { min-height: 100dvh; padding: 14px; }
  .login-card { border-radius: 22px; padding: 22px; }
  .login-card h1 { font-size: 24px; }

  .topbar {
    min-height: 74px;
    height: auto;
    gap: 10px;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
  }
  .topbar > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
  .top-actions { width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
  .top-actions button { padding: 9px 10px; border-radius: 10px; }
  #agentName { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; align-self: center; }

  .layout {
    height: calc(100dvh - 92px);
    display: block;
    overflow: hidden;
    background: #fff;
  }
  .sidebar { display: flex; height: 100%; min-height: 0; }
  .filter-box { position: sticky; top: 0; z-index: 2; background: #fff; padding: 10px; }
  .conversation-list { flex: 1; min-height: 0; }
  .conversation-item { padding: 14px 12px; }

  .chat-panel { display: none; height: 100%; min-height: 0; }
  .details-panel { display: none; }

  .app-shell.chat-open .sidebar { display: none; }
  .app-shell.chat-open .chat-panel { display: block; height: 100%; }
  .app-shell.chat-open .details-panel {
    display: flex;
    height: auto;
    max-height: 42dvh;
    overflow: auto;
    border-top: 1px solid var(--line);
    padding: 12px;
  }
  .app-shell.chat-open .layout { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  .mobile-back { display: inline-flex; align-items: center; justify-content: center; }
  .chat-title-area { flex: 1; min-width: 0; }
  .chat-title-area > div { min-width: 0; }
  .chat-header { padding: 10px 12px; gap: 8px; }
  .chat-header h2 { font-size: 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 46vw; }
  .chat-header span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 46vw; }
  .window-badge { padding: 5px 8px; font-size: 11px; max-width: 38vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

  .chat-view { height: 100%; min-height: 0; grid-template-rows: auto 1fr auto auto auto; }
  .messages { padding: 12px; gap: 8px; }
  .message { max-width: 92%; font-size: 14px; }
  .quick-row { padding: 8px 10px; grid-template-columns: 1fr auto; }
  .quick-row button { padding: 9px 10px; }
  .composer { padding: 9px 10px; gap: 8px; grid-template-columns: 1fr auto; }
  .composer textarea { min-height: 46px; max-height: 110px; padding: 10px; }
  .composer button { padding: 10px 12px; }
  .send-hint { padding: 0 10px 8px; font-size: 11px; }
  .info-card { border-radius: 14px; padding: 12px; }
  .toast { right: 10px; bottom: 10px; max-width: calc(100vw - 20px); }
}

@media (max-width: 420px) {
  .top-actions { grid-template-columns: 1fr auto auto; }
  .top-actions button { font-size: 13px; padding: 8px; }
  .brand-mark { width: 50px; height: 50px; }
  .window-badge { max-width: 34vw; }
  .chat-header h2, .chat-header span { max-width: 42vw; }
  .quick-row { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr; }
  .composer button { width: 100%; }
}

/* Ajustes de performance/UX da versão otimizada */
.conversation-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--text);
  font-weight: 400;
  box-shadow: none;
}
.conversation-item:hover,
.conversation-item.active {
  background: #ecfeff;
  color: var(--text);
}
.conversation-item:focus-visible {
  outline: 2px solid rgba(15,118,110,.35);
  outline-offset: -2px;
}
.empty-state small {
  display: block;
  margin-top: 8px;
  color: #94a3b8;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9999;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 14px;
  background: #0f172a;
  color: white;
  box-shadow: 0 18px 50px rgba(15,23,42,.28);
  font-size: 14px;
  font-weight: 700;
}
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }
.toast.info { background: #0f172a; }

/* Roteamento de atendimento */
.conversation-assigned {
  color: #64748b;
  font-size: 11px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.assignment-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}
.assignment-card small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.assignment-card strong {
  display: block;
  margin-top: 3px;
  color: #0f172a;
}
.assignment-card strong.mine {
  color: #0f766e;
}
#claimBtn, #transferBtn {
  color: #0f172a;
}
