:root {
  --primary: #159b8c;
  --primary-dark: #087f73;
  --primary-soft: #e8f7f5;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --border: #e3e7eb;
  --text: #17212b;
  --muted: #74808c;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8f2;
  --shadow: 0 1px 3px rgba(20, 35, 45, .08);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 250px 310px minmax(420px, 1fr) 310px;
  overflow: hidden;
  background: var(--panel);
}

/* Sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: #fff;
  overflow: hidden;
}

.brand {
  height: 72px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--primary);
  font-size: 21px;
  font-weight: 700;
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-tabs {
  padding: 12px 10px;
  display: grid;
  gap: 4px;
}

.tab {
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #53606c;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
}

.tab:hover { background: #f4f7f8; }

.tab.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.tab b {
  margin-left: auto;
  font-size: 11px;
  background: #eef1f3;
  color: #65717c;
  border-radius: 10px;
  padding: 2px 7px;
}

.tab.active b {
  background: #d1eee9;
  color: var(--primary-dark);
}

.sidebar-footer {
  margin-top: auto;
  padding: 15px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  width: 100%;
}

.status-dot, .online i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #20c66b;
}

/* Headers */
.panel-header {
  height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Conversation list */
.conversation-list {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
}

.search-box {
  margin: 12px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 9px;
  background: #f1f4f6;
  color: #8a96a1;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.conversation-items {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.conversation-item {
  padding: 13px 14px;
  display: flex;
  gap: 11px;
  border-bottom: 1px solid #edf0f2;
  cursor: pointer;
}

.conversation-item:hover { background: #f8fafb; }

.conversation-item.selected {
  background: var(--primary-soft);
  border-left: 3px solid var(--primary);
  padding-left: 11px;
}

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e2f1ef;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}

.conversation-main { min-width: 0; flex: 1; }

.conversation-top {
  display: flex;
  align-items: center;
  gap: 7px;
}

.conversation-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 650;
}

.conversation-time {
  margin-left: auto;
  color: #98a2ab;
  font-size: 10px;
}

.conversation-preview {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: #71808b;
  font-size: 11px;
}

.conversation-preview .online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #20c66b;
}

/* Chat */
.chat-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #f7f9fa;
}

.chat-header {
  height: 72px;
  flex: 0 0 72px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.avatar.large {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
}

.chat-title {
  min-width: 0;
  flex: 1;
}

.chat-title strong {
  display: block;
  font-size: 14px;
}

.chat-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-actions button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #596671;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  margin-top: 10px;
  color: var(--text);
  font-size: 14px;
}

.empty-state span {
  max-width: 270px;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
}

.empty-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e4f5f2;
  font-size: 24px;
}

.message-row {
  display: flex;
  width: 100%;
  margin: 5px 0;
  padding: 0 2px;
}

.message-row.in {
  justify-content: flex-start;
}

.message-row.out {
  justify-content: flex-end;
}

.message-bubble {
  position: relative;
  max-width: min(74%, 680px);
  min-width: 72px;
  padding: 8px 12px 6px;
  border: 1px solid transparent;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(20, 35, 45, .07);
  background: var(--bubble-in);
  color: var(--text);
  font-size: 13px;
  line-height: 1.48;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: box-shadow .15s ease, transform .15s ease;
}

.message-row.in .message-bubble {
  border-color: #e4e8eb;
  border-top-left-radius: 5px;
}

.message-row.out .message-bubble {
  background: var(--bubble-out);
  border-color: #c9ebe3;
  border-top-right-radius: 5px;
}

.message-bubble:hover {
  box-shadow: 0 2px 5px rgba(20, 35, 45, .10);
}

.message-sender {
  margin-bottom: 3px;
  color: #71808a;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.message-row.out .message-sender {
  color: #3e8177;
}

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 5px;
  min-height: 12px;
  color: #8a959b;
  font-size: 9px;
  line-height: 1;
}

.message-status {
  font-weight: 700;
  letter-spacing: -1px;
}

.message-row.out .message-status {
  color: #438f84;
}

.composer {
  position: relative;
  min-height: 82px;
  padding: 10px 70px 27px 14px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 130px;
  resize: none;
  padding: 11px 13px;
  border: 1px solid #dce2e6;
  border-radius: 9px;
  outline: 0;
  color: var(--text);
  background: #f7f9fa;
  font-size: 13px;
}

.composer textarea:focus {
  border-color: #a8dcd5;
  background: #fff;
}

.composer button {
  position: absolute;
  right: 16px;
  top: 10px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
}

.composer button:disabled {
  background: #cbd4d8;
  cursor: not-allowed;
}

.composer-help {
  position: absolute;
  left: 16px;
  bottom: 6px;
  color: #98a1a8;
  font-size: 10px;
}

/* Client */
.client-panel {
  min-width: 0;
  border-left: 1px solid var(--border);
  background: #fff;
}

.client-header {
  min-height: 150px;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.client-avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e4f2f0;
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: 700;
}

.client-header h2 {
  margin: 9px 0 5px;
  font-size: 15px;
}

.badge {
  padding: 3px 9px;
  border-radius: 12px;
  background: #e8f7ee;
  color: #18824a;
  font-size: 10px;
  font-weight: 600;
}

.client-content { padding: 16px; }

.info-card {
  padding: 11px 12px;
  margin-bottom: 8px;
  border: 1px solid #edf0f2;
  border-radius: 9px;
  background: #fafbfc;
}

.info-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.info-card strong {
  font-size: 12px;
  word-break: break-word;
}

.section-title {
  margin: 21px 0 9px;
  color: #89949d;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.info-row {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f0f2f3;
  color: #69757e;
  font-size: 11px;
}

.info-row strong {
  color: var(--text);
  font-size: 11px;
}

.online { color: #18824a !important; }

/* Utility */
.loading, .no-results {
  padding: 30px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.error {
  padding: 18px;
  color: #b42318;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 1200px) {
  .app-shell { grid-template-columns: 220px 280px minmax(380px, 1fr) 260px; }
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 210px 280px minmax(360px, 1fr); }
  .client-panel { display: none; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar, .conversation-list { display: none; }
  .chat-panel { display: flex; }
}
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.logged-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-info strong {
  font-size: 13px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info span {
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
  transition: .2s;
}

.logout-button:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
/* ========================================
   PAINEL DE USUÁRIOS
======================================== */

.users-panel {
  grid-column: 2 / -1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #f8fafb;
  overflow: hidden;
  z-index: 10;
}

.users-header {
  min-height: 72px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.users-header h1 {
  margin: 0;
  font-size: 20px;
  color: #1f2933;
}

.users-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#btn-novo-usuario {
  border: 0;
  border-radius: 8px;
  padding: 10px 15px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#btn-novo-usuario:hover {
  opacity: .9;
}

.users-content {
  flex: 1;
  padding: 22px;
  overflow: auto;
}

.users-table {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.users-table-header {
  display: grid;
  grid-template-columns: 1.2fr 1.5fr .8fr .8fr .8fr;
  gap: 12px;
  padding: 13px 16px;
  background: #f5f7f8;
  border-bottom: 1px solid var(--border);
  color: #65717c;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.users-empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.users-row {
  display: grid;
  grid-template-columns: 1.2fr 1.5fr .8fr .8fr .8fr;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.users-row:last-child {
  border-bottom: 0;
}

.user-role,
.user-status {
  display: inline-flex;
  width: fit-content;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.user-role {
  background: #eef2ff;
  color: #4338ca;
}

.user-status {
  background: #dcfce7;
  color: #166534;
}

.user-status.inactive {
  background: #fee2e2;
  color: #991b1b;
}
/* ========================================
   FORMULÁRIO DE USUÁRIO
======================================== */

.user-form-panel {
  background: #fff;
  margin: 20px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.user-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 25px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.user-form-header h2 {
  margin: 0;
  font-size: 20px;
  color: #1f2937;
}

.user-form-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .08);
}

.checkbox-group {
  margin-top: 20px;
}

.checkbox-group label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-group input {
  width: auto;
}

.user-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 25px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.btn-primary,
.btn-secondary {
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  opacity: .9;
}

.btn-secondary {
  background: #eef1f3;
  color: #53606c;
}

.btn-secondary:hover {
  background: #e2e6e9;
}

.user-form-error {
  margin-top: 18px;
  padding: 11px 13px;
  border-radius: 8px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 13px;
}
/* ========================================
   ATENDIMENTO - FILA AGUARDANDO
   ======================================== */

.conversation-waiting {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conversation-waiting span {
  font-size: 11px;
  color: #a06b00;
}

.btn-assumir {
  border: 0;
  border-radius: 6px;
  padding: 5px 9px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-assumir:hover {
  opacity: 0.9;
}

.btn-assumir:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ========================================
   PAINEL DE CATEGORIAS
======================================== */

.categorias-panel {
  grid-column: 2 / -1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #f8fafb;
  overflow: hidden;
  z-index: 10;
}

.categorias-header {
  min-height: 72px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.categorias-header h1 {
  margin: 0;
  font-size: 20px;
  color: #1f2933;
}

.categorias-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#btn-nova-categoria {
  border: 0;
  border-radius: 8px;
  padding: 10px 15px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#btn-nova-categoria:hover {
  opacity: .9;
}

.categorias-content {
  flex: 1;
  padding: 22px;
  overflow: auto;
}

.categorias-lista {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.categoria-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

.categoria-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 15px;
}

.categoria-info {
  min-width: 0;
}

.categoria-info h3 {
  margin: 0;
  font-size: 16px;
  color: #1f2933;
}

.categoria-descricao {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.categoria-status {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 6px;
  background: #dcfce7;
  color: #166534;
  font-size: 11px;
  font-weight: 600;
}

.categoria-status.inativa {
  background: #fee2e2;
  color: #991b1b;
}

.categoria-acoes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.categoria-acoes button,
.subcategoria-acoes button {
  border: 0;
  border-radius: 7px;
  padding: 8px 11px;
  background: #eef2f5;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.categoria-acoes button:hover,
.subcategoria-acoes button:hover {
  background: #e2e8f0;
}

.categoria-acoes .btn-subcategoria {
  background: #e0f2fe;
  color: #0369a1;
}

.categoria-acoes .btn-desativar {
  background: #fee2e2;
  color: #991b1b;
}

.subcategorias {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.subcategorias-title {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
}

.subcategoria-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 12px;
  margin-bottom: 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.subcategoria-info {
  min-width: 0;
}

.subcategoria-info strong {
  display: block;
  font-size: 13px;
  color: #1f2937;
}

.subcategoria-info span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: #64748b;
}

.subcategoria-acoes {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.subcategoria-acoes .btn-desativar {
  background: #fee2e2;
  color: #991b1b;
}

.categorias-empty {
  padding: 50px;
  text-align: center;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* FORMULÁRIO DE CATEGORIA */

.categoria-form-panel {
  background: #fff;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.categoria-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.categoria-form-header h2 {
  margin: 0;
  font-size: 18px;
  color: #1f2933;
}

.categoria-form-header p {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.categoria-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.categoria-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.categoria-form input,
.categoria-form textarea,
.categoria-form select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid #d7dee5;
  border-radius: 7px;
  font-size: 13px;
  outline: none;
}

.categoria-form input:focus,
.categoria-form textarea:focus,
.categoria-form select:focus {
  border-color: var(--primary);
}

.categoria-form textarea {
  min-height: 90px;
  resize: vertical;
}

.categoria-form-acoes {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 5px;
}


/* Controle de visibilidade dos recursos administrativos */
.admin-only {
  display: none;
}



/* ========================================
   FRONTEND V3 — VIEWPORT / CHAT
   ======================================== */

html {
  min-height: 100%;
  overflow: hidden;
}

body {
  min-height: 100%;
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
}

.chat-panel {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.messages {
  min-height: 0;
  flex: 1 1 auto;
  overscroll-behavior: contain;
}

.composer {
  flex: 0 0 auto;
  min-height: 78px;
  max-height: 180px;
  overflow: hidden;
}

.composer textarea {
  display: block;
}

.client-panel {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
}

.sidebar,
.conversation-list {
  min-height: 0;
}

.conversation-items {
  scrollbar-gutter: stable;
}

/* ========================================
   RELATÓRIOS
   ======================================== */

.relatorios-panel {
  grid-column: 2 / -1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #f7f9fa;
  overflow: hidden;
  z-index: 10;
}

.relatorios-header {
  min-height: 72px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.relatorios-header h1 {
  margin: 0;
  font-size: 20px;
}

.relatorios-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.relatorios-filtros {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.relatorio-periodo {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  background: #fff;
  color: #5b6670;
  font-size: 12px;
  font-weight: 600;
}

.relatorio-periodo:hover {
  background: #f4f7f8;
}

.relatorio-periodo.active {
  background: var(--primary-soft);
  border-color: #b9e3dd;
  color: var(--primary-dark);
}

.relatorios-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 22px 28px;
}

.relatorio-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.relatorio-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.relatorio-card span,
.relatorio-card small {
  display: block;
  color: var(--muted);
}

.relatorio-card span {
  font-size: 12px;
  font-weight: 600;
}

.relatorio-card strong {
  display: block;
  margin: 7px 0 3px;
  font-size: 27px;
  line-height: 1;
}

.relatorio-card small {
  font-size: 10px;
}

.relatorios-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.relatorio-box {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.relatorio-box-header {
  margin-bottom: 14px;
}

.relatorio-box-header h2 {
  margin: 0;
  font-size: 14px;
}

.relatorio-box-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.relatorio-volume {
  min-height: 190px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-top: 10px;
}

.relatorio-volume-item {
  min-width: 0;
  flex: 1;
  height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.relatorio-volume-bar-wrap {
  width: 100%;
  height: 145px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.relatorio-volume-bar {
  width: min(32px, 70%);
  min-height: 3px;
  border-radius: 6px 6px 2px 2px;
  background: var(--primary);
}

.relatorio-volume-value {
  font-size: 10px;
  font-weight: 700;
}

.relatorio-volume-label {
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}

.relatorio-status {
  display: grid;
  gap: 13px;
}

.relatorio-status-row {
  display: grid;
  grid-template-columns: 82px 1fr 32px;
  align-items: center;
  gap: 9px;
  font-size: 11px;
}

.relatorio-status-label {
  color: #5d6972;
}

.relatorio-status-track {
  height: 9px;
  overflow: hidden;
  border-radius: 8px;
  background: #edf1f3;
}

.relatorio-status-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.relatorio-status-value {
  text-align: right;
  font-weight: 700;
}

.relatorio-table-wrap {
  overflow-x: auto;
}

.relatorio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.relatorio-table th,
.relatorio-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #edf0f2;
  text-align: left;
  white-space: nowrap;
}

.relatorio-table th {
  color: #7a858e;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.relatorio-table td {
  color: #33404a;
}

.relatorio-status-badge {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 8px;
  background: #e8f7ee;
  color: #18824a;
  font-size: 9px;
  font-weight: 700;
}

.relatorio-status-badge.aguardando {
  background: #fff4d6;
  color: #9a6700;
}

.relatorio-status-badge.encerrada {
  background: #eef1f3;
  color: #68747d;
}

.relatorio-empty {
  padding: 25px !important;
  color: var(--muted) !important;
  text-align: center !important;
}

@media (max-width: 1200px) {
  .app-shell { grid-template-columns: 220px 280px minmax(360px, 1fr) 260px; }
  .relatorio-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 210px 280px minmax(360px, 1fr); }
  .client-panel { display: none; }
  .relatorios-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  html, body { overflow: auto; }
  .app-shell { min-height: 100dvh; height: auto; grid-template-columns: 1fr; }
  .sidebar, .conversation-list { display: none; }
  .chat-panel { min-height: 100dvh; height: 100dvh; }
  .relatorios-panel { min-height: 100dvh; }
  .relatorio-cards { grid-template-columns: 1fr 1fr; }
  .relatorios-header { align-items: flex-start; flex-direction: column; }
}

/* Conversas: refinamento visual dos balões */
@media (max-width: 900px) {
  .message-bubble {
    max-width: 82%;
  }
}

@media (max-width: 640px) {
  .messages {
    padding: 14px 10px;
  }

  .message-row {
    margin: 4px 0;
  }

  .message-bubble {
    max-width: 88%;
    font-size: 13px;
    border-radius: 13px;
  }
}


/* ================================================================
   START ATENDIMENTO — TEMA DARK MODERNO V7
   Somente apresentação. Não altera lógica, API, tenant ou banco.
   ================================================================ */

:root {
  --primary: #12b8a6;
  --primary-dark: #0aa28f;
  --primary-soft: rgba(18, 184, 166, .13);
  --bg: #070b12;
  --panel: #0f1622;
  --border: #253244;
  --text: #edf4f7;
  --muted: #8b9aab;
  --bubble-in: #151f2d;
  --bubble-out: #0b8f84;
  --shadow: 0 10px 30px rgba(0, 0, 0, .24);
}

html, body {
  background: var(--bg);
  color: var(--text);
}

body {
  color-scheme: dark;
}

/* Estrutura principal */
.app-shell {
  background: #0a1019;
}

/* Barra lateral */
.sidebar {
  background: #0b111b;
  border-right-color: #202c3c;
}

.brand {
  border-bottom-color: #202c3c;
}

.brand-mark {
  background: linear-gradient(135deg, #15c9b5, #0a8f82);
  box-shadow: 0 8px 20px rgba(18, 184, 166, .24);
}

.brand strong {
  color: #f4f8fa;
}

.brand span {
  color: #7f8fa1;
}

.sidebar-tabs {
  padding-top: 16px;
}

.tab {
  color: #97a6b6;
}

.tab:hover {
  background: #121b29;
  color: #dce6eb;
}

.tab.active {
  background: linear-gradient(90deg, rgba(18,184,166,.20), rgba(18,184,166,.08));
  color: #63e5d7;
  box-shadow: inset 3px 0 0 #12b8a6;
}

.tab b {
  background: #192536;
  color: #91a1b1;
}

.tab.active b {
  background: rgba(18,184,166,.22);
  color: #78efe1;
}

.sidebar-footer {
  border-top-color: #202c3c;
  background: #0a1019;
  color: #8292a4;
}

.connection-status {
  color: #96a5b4;
}

.logged-user {
  border-top-color: #202c3c;
}

.user-avatar {
  background: linear-gradient(135deg, #19bcb0, #1768d6);
}

.user-info strong {
  color: #eaf1f5;
}

.user-info span {
  color: #8191a2;
}

.logout-button {
  color: #8090a0;
}

.logout-button:hover {
  background: #142030;
  color: #fff;
}

/* Coluna de conversas */
.conversation-list {
  background: #0e1622;
  border-right-color: #253244;
}

.panel-header {
  background: #0e1622;
  border-bottom-color: #253244;
}

.panel-header h1,
.conversation-name {
  color: #ecf3f6;
}

.panel-header p,
.conversation-preview {
  color: #8494a5;
}

.search-box {
  background: #141e2b;
  border: 1px solid #233043;
  color: #75879a;
}

.search-box:focus-within {
  border-color: rgba(18,184,166,.55);
  box-shadow: 0 0 0 3px rgba(18,184,166,.10);
}

.search-box input {
  color: #e6eef2;
}

.search-box input::placeholder {
  color: #687a8e;
}

.conversation-item {
  border-bottom-color: #202b3a;
}

.conversation-item:hover {
  background: #121c29;
}

.conversation-item.selected {
  background: linear-gradient(90deg, rgba(18,184,166,.16), rgba(18,184,166,.05));
  border-left-color: #12b8a6;
}

.avatar {
  background: linear-gradient(135deg, #183b43, #17303c);
  color: #59ddcf;
}

.conversation-time {
  color: #6f8193;
}

.conversation-preview .online-dot {
  background: #1bd6a5;
  box-shadow: 0 0 0 3px rgba(27,214,165,.10);
}

/* Chat */
.chat-panel {
  background: radial-gradient(circle at 50% 15%, #101b29 0%, #0a111a 55%, #070c13 100%);
}

.chat-header {
  background: rgba(13,20,31,.96);
  border-bottom-color: #253244;
}

.chat-title strong {
  color: #f0f6f8;
}

.chat-title span {
  color: #8090a1;
}

.chat-actions button {
  border-color: #2a394c;
  background: #131e2b;
  color: #9fb0c0;
}

.chat-actions button:hover {
  border-color: rgba(18,184,166,.5);
  color: #5de1d4;
  background: #152534;
}

.messages {
  background:
    radial-gradient(circle at 10% 0%, rgba(18,184,166,.035), transparent 26%),
    radial-gradient(circle at 90% 100%, rgba(45,129,255,.035), transparent 28%);
}

.empty-state {
  color: #78899a;
}

.empty-state strong {
  color: #dfe8ed;
}

.empty-icon {
  background: #13252b;
  box-shadow: inset 0 0 0 1px rgba(18,184,166,.18);
}

/* Balões */
.message-row {
  margin: 8px 0;
}

.message-bubble {
  max-width: min(76%, 700px);
  border-radius: 16px;
  border-color: #263448;
  background: linear-gradient(180deg, #172230, #141d2a);
  color: #e8f0f3;
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
}

.message-row.in .message-bubble {
  border-color: #28394b;
  border-top-left-radius: 6px;
}

.message-row.out .message-bubble {
  background: linear-gradient(135deg, #0d9d91, #087c77);
  border-color: #12b8a6;
  color: #f5fffd;
  border-top-right-radius: 6px;
  box-shadow: 0 8px 24px rgba(18,184,166,.13);
}

.message-bubble:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(0,0,0,.24);
}

.message-sender {
  color: #7890a2;
}

.message-row.out .message-sender {
  color: rgba(239,255,252,.76);
}

.message-meta {
  color: #728396;
}

.message-row.out .message-meta,
.message-row.out .message-status {
  color: rgba(241,255,252,.78);
}

/* Composer */
.composer {
  background: #0c141f;
  border-top-color: #253244;
}

.composer textarea {
  background: #131e2b;
  border-color: #2a394c;
  color: #eaf2f5;
}

.composer textarea::placeholder {
  color: #718295;
}

.composer textarea:focus {
  border-color: #12b8a6;
  background: #152231;
  box-shadow: 0 0 0 3px rgba(18,184,166,.09);
}

.composer button {
  background: linear-gradient(135deg, #13c4b0, #078d82);
  box-shadow: 0 8px 20px rgba(18,184,166,.18);
}

.composer button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.composer button:disabled {
  background: #2b3948;
  color: #708093;
  box-shadow: none;
}

.composer-help {
  color: #66798c;
}

/* Painel do cliente */
.client-panel {
  background: #0d1520;
  border-left-color: #253244;
}

.client-header {
  background: #0e1723;
  border-bottom-color: #253244;
}

.client-avatar {
  background: linear-gradient(135deg, #153c41, #132a35);
  color: #64e8da;
  box-shadow: inset 0 0 0 1px rgba(18,184,166,.18), 0 10px 26px rgba(0,0,0,.2);
}

.client-header h2 {
  color: #edf4f7;
}

.badge {
  background: rgba(27,214,165,.13);
  color: #54e1bd;
}

.client-content {
  color: #9eacba;
}

.info-card {
  background: #121c29;
  border-color: #233144;
  box-shadow: 0 8px 22px rgba(0,0,0,.12);
}

.info-label,
.section-title {
  color: #718398;
}

.info-card strong,
.info-row strong {
  color: #e7eff3;
}

.info-row {
  border-bottom-color: #202c3c;
  color: #8192a4;
}

.online {
  color: #52dfbb !important;
}

/* Botões gerais */
.btn-primary {
  background: linear-gradient(135deg, #12b8a6, #078d82);
  box-shadow: 0 8px 20px rgba(18,184,166,.16);
}

.btn-secondary {
  background: #172332;
  color: #a4b3c2;
  border: 1px solid #2a394c;
}

.btn-secondary:hover {
  background: #1c2a3b;
  color: #d9e5ea;
  border-color: #3a4c63;
}

.btn-assumir {
  background: linear-gradient(135deg, #14baa8, #07897f);
  box-shadow: 0 6px 14px rgba(18,184,166,.15);
}

/* Usuários / Categorias / Relatórios */
.users-panel,
.categorias-panel,
.relatorios-panel {
  background: #0a111a;
}

.users-header,
.categorias-header,
.relatorios-header {
  background: #0e1622;
  border-bottom-color: #253244;
}

.users-header h1,
.categorias-header h1,
.relatorios-header h1,
.user-form-header h2,
.categoria-form-header h2,
.relatorio-box-header h2 {
  color: #edf4f7;
}

.users-header p,
.categorias-header p,
.relatorios-header p,
.user-form-header p,
.categoria-form-header p,
.relatorio-box-header p {
  color: #8192a4;
}

.users-table,
.user-form-panel,
.categoria-card,
.categoria-form-panel,
.relatorio-card,
.relatorio-box {
  background: #101925;
  border-color: #263447;
  box-shadow: 0 10px 26px rgba(0,0,0,.16);
}

.users-table-header {
  background: #151f2d;
  border-bottom-color: #2a394c;
  color: #8192a4;
}

.users-row {
  border-bottom-color: #223043;
}

.users-row,
.categoria-info h3,
.subcategoria-info strong,
.relatorio-table td {
  color: #dfe8ed;
}

.form-group label {
  color: #a6b5c3;
}

.form-group input,
.form-group select,
.categoria-form input,
.categoria-form textarea,
.categoria-form select {
  background: #121e2b;
  border-color: #2b3b4f;
  color: #e7eff3;
}

.form-group input:focus,
.form-group select:focus,
.categoria-form input:focus,
.categoria-form textarea:focus,
.categoria-form select:focus {
  border-color: #12b8a6;
  box-shadow: 0 0 0 3px rgba(18,184,166,.09);
}

.relatorio-periodo {
  background: #121e2b;
  border-color: #2a394c;
  color: #9eb0c0;
}

.relatorio-periodo:hover {
  background: #182635;
}

.relatorio-periodo.active {
  background: rgba(18,184,166,.13);
  border-color: rgba(18,184,166,.38);
  color: #66e5d8;
}

.relatorio-card span,
.relatorio-card small,
.relatorio-table th,
.relatorio-volume-label,
.relatorio-status-label {
  color: #8192a4;
}

.relatorio-card strong {
  color: #f0f6f8;
}

.relatorio-status-track {
  background: #1a2635;
}

.relatorio-status-fill,
.relatorio-volume-bar {
  background: linear-gradient(180deg, #1ad5c0, #0a9488);
  box-shadow: 0 6px 16px rgba(18,184,166,.16);
}

.relatorio-table th,
.relatorio-table td {
  border-bottom-color: #223043;
}

.relatorio-status-badge {
  background: rgba(27,214,165,.13);
  color: #54e1bd;
}

.relatorio-status-badge.aguardando {
  background: rgba(245,190,65,.13);
  color: #f1c763;
}

.relatorio-status-badge.encerrada {
  background: #1a2533;
  color: #96a5b4;
}

.categoria-status {
  background: rgba(27,214,165,.13);
  color: #54e1bd;
}

.categoria-status.inativa {
  background: rgba(236,92,104,.13);
  color: #f28e98;
}

.categoria-acoes button,
.subcategoria-acoes button {
  background: #172332;
  color: #a7b6c4;
  border: 1px solid #2a394c;
}

.categoria-acoes button:hover,
.subcategoria-acoes button:hover {
  background: #1d2b3c;
}

.categoria-acoes .btn-subcategoria {
  background: rgba(34,176,255,.10);
  color: #6fc8ff;
  border-color: rgba(34,176,255,.20);
}

.subcategoria-item {
  background: #131e2b;
  border-color: #263447;
}

.categorias-empty,
.users-empty,
.relatorio-empty {
  background: #101925;
  border-color: #263447;
  color: #8192a4 !important;
}

/* Status de erro */
.error {
  color: #f28e98;
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: #33455b transparent;
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: #2d3e53;
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: #41566f;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Responsivo: mantém a composição legível sem perder o tema */
@media (max-width: 1200px) {
  .app-shell { grid-template-columns: 220px 280px minmax(360px, 1fr) 260px; }
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 210px 280px minmax(360px, 1fr); }
  .client-panel { display: none; }
}

@media (max-width: 760px) {
  .chat-panel {
    min-height: 100dvh;
    height: 100dvh;
  }

  .message-bubble {
    max-width: 88%;
  }
}
