:root {
  --bg: #0b141a;
  --bg-elevated: #111b21;
  --bg-panel: #202c33;
  --bg-hover: #2a3942;
  --border: #2f3b43;
  --text: #e9edef;
  --text-muted: #8696a0;
  --accent: #00a884;
  --accent-dark: #008f72;
  --danger: #ea4335;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --chat-bg: #0b141a;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --bubble-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --sidebar-width: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  overflow: hidden;
}

.app-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.15rem 1.1rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 0.75rem;
  flex: 1;
  overflow-y: auto;
}

.sidebar-section {
  margin: 0.65rem 0 0.35rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar-section:first-child {
  margin-top: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link span {
  font-size: 0.95rem;
}

.sidebar-link:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sidebar-link.active {
  color: var(--text);
  background: rgba(0, 168, 132, 0.15);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-link-btn {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sidebar-link-logout {
  color: #ffb4a9;
}
.sidebar-link-logout:hover {
  background: rgba(255, 100, 90, 0.12);
  color: #ffc9c2;
}

.sidebar-bottom {
  padding: 0.85rem 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.65rem;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.sidebar-user-name {
  color: var(--text);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.logo-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--accent); display: inline-block;
}
.logo-dot.lg { width: 18px; height: 18px; }

.btn {
  border: 0; border-radius: 8px; padding: 0.55rem 1rem;
  font: inherit; cursor: pointer; transition: 0.15s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: rgba(234, 67, 53, 0.15); color: #ff8a80; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.9rem; }
.btn-block { width: 100%; }

.login-page {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(circle at top, #1f2c34, var(--bg));
}
.login-card {
  width: min(420px, 92vw); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow);
}
.login-header { text-align: center; margin-bottom: 1.5rem; }
.login-header h1 { margin: 0.75rem 0 0.25rem; }
.login-header p { margin: 0; color: var(--text-muted); }
.login-form label { display: grid; gap: 0.35rem; margin-bottom: 1rem; color: var(--text-muted); font-size: 0.92rem; }
.login-form input,
.modal input,
.modal textarea,
.modal select,
#send-message-form input,
#send-message-form textarea,
.search-box input,
.chat-composer textarea {
  width: 100%; background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 0.9rem; font: inherit;
}
.form-error { color: #ff8a80; font-size: 0.9rem; }

.is-hidden { display: none !important; }

.wa-status { background: #182229; border-bottom: 1px solid var(--border); }
.wa-status-inner {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 1.25rem; flex-wrap: wrap;
}
.wa-status-inner #wa-account { flex: 1; min-width: 180px; }
.btn-link-wa-empty { margin-top: 1.25rem; padding: 0.7rem 1.5rem; }
.status-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.25rem 0.65rem; border-radius: 999px; font-size: 0.85rem; background: var(--bg-hover);
}
.status-pill.online { color: #7dffb3; }
.status-pill.offline { color: #ffb4a9; }

.wa-nav-status {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.65rem; border-radius: 8px; font-size: 0.78rem;
  background: rgba(0, 168, 132, 0.12); color: #7dffb3;
  line-height: 1.3;
}
.wa-nav-status::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
}

.wa-qr-dialog { width: min(380px, 92vw); }
.wa-qr-dialog-body { padding: 1.25rem; display: grid; gap: 0.85rem; text-align: center; }
.wa-qr-dialog-body h3 { margin: 0; }
.wa-qr-hint { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.wa-qr-img {
  justify-self: center; background: #fff; padding: 0.75rem; border-radius: 12px;
  width: min(280px, 80vw); height: auto;
}

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.chat-sidebar {
  flex: 0 0 auto;
  width: var(--chat-sidebar-width, 360px);
  min-width: 260px;
  max-width: 50%;
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-splitter {
  flex: 0 0 5px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 2;
  transition: background 0.15s ease;
}

.chat-splitter::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  right: -4px;
}

.chat-splitter:hover,
.chat-splitter.is-dragging {
  background: var(--accent);
}

body.is-resizing-chat {
  cursor: col-resize !important;
  user-select: none;
}

body.is-resizing-chat * {
  cursor: col-resize !important;
}
.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem; border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { margin: 0; font-size: 1.05rem; }
.search-box { padding: 0.5rem 0.85rem 0.75rem; }
.search-box input {
  background: var(--bg-panel); border: none; border-radius: 8px;
  padding: 0.55rem 0.85rem 0.55rem 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238696a0' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 0.65rem center;
}
.conversation-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.conversation-item {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.7rem 1rem; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.conversation-item:hover,
.conversation-item.active { background: var(--bg-hover); }
.conv-avatar {
  flex-shrink: 0; width: 49px; height: 49px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: 1.1rem; color: #fff;
}
.conv-body { flex: 1; min-width: 0; display: grid; gap: 0.15rem; }
.conversation-item strong {
  font-size: 1rem; font-weight: 400; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-item small,
.conversation-preview { color: var(--text-muted); font-size: 0.8rem; }
.conversation-preview {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.conversation-meta {
  display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
}
.unread-badge {
  background: var(--accent); color: #111b21; border-radius: 999px;
  min-width: 1.25rem; height: 1.25rem; padding: 0 0.35rem;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 600; flex-shrink: 0;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 280px;
  flex: 1;
  background: var(--chat-bg);
}
.chat-empty {
  margin: auto; text-align: center; color: var(--text-muted); max-width: 460px; padding: 2rem;
  border-bottom: 6px solid var(--accent);
}
.chat-empty-icon { color: var(--text-muted); opacity: 0.35; margin-bottom: 1.25rem; }
.chat-empty h3 { color: var(--text); font-weight: 300; font-size: 2rem; margin: 0 0 1rem; }
.chat-empty p { line-height: 1.6; margin: 0; font-size: 0.92rem; }

.chat-active { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.chat-header {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.65rem 1rem 0.65rem 1.25rem; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  min-height: 60px;
}
.chat-header-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; color: #fff; flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info strong {
  display: block; font-size: 1rem; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-info small {
  display: block; color: var(--text-muted); margin-top: 0.1rem; font-size: 0.8rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-actions {
  display: flex; align-items: center; gap: 0.15rem; margin-left: auto;
}
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: grid; place-items: center; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn-sm { width: 32px; height: 32px; font-size: 1.25rem; }

.header-menu-wrap { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
  min-width: 220px; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 0.35rem 0;
}
.dropdown-item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); padding: 0.65rem 1rem; font: inherit; cursor: pointer;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: #ff8a80; }
.dropdown-divider { border: 0; border-top: 1px solid var(--border); margin: 0.35rem 0; }

.chat-search-bar {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 1rem; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.chat-search-bar input {
  flex: 1; border: none; background: transparent; color: var(--text); font: inherit;
  padding: 0.35rem 0;
}
.chat-search-bar input:focus { outline: none; }
.chat-search-empty {
  text-align: center; color: var(--text-muted); padding: 2rem; margin: 0;
}
mark.search-hit { background: rgba(255, 214, 102, 0.35); color: inherit; padding: 0 0.1rem; border-radius: 2px; }

.contact-info-dialog { width: min(360px, 92vw); }
.contact-info-body { padding: 1.5rem; text-align: center; position: relative; }
.contact-info-close { position: absolute; top: 0.75rem; right: 0.75rem; }
.contact-info-avatar {
  width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 1rem;
  display: grid; place-items: center; font-size: 2.2rem; font-weight: 600; color: #fff;
}
.contact-info-body h3 { margin: 0 0 0.25rem; font-weight: 400; font-size: 1.35rem; }
.contact-info-phone { margin: 0 0 1.25rem; color: var(--text-muted); }
.contact-info-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem;
  margin: 0; padding: 1rem 0 0; border-top: 1px solid var(--border); text-align: center;
}
.contact-info-stats dt { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.contact-info-stats dd { margin: 0; font-size: 1.1rem; font-weight: 500; }

.chat-messages-wrap {
  flex: 1; min-height: 0; overflow: hidden;
  background-color: var(--chat-bg);
  background-image: url('/img/wa-wallpaper.svg');
  background-size: 400px 400px;
  background-repeat: repeat;
}
.chat-messages {
  height: 100%; overflow: auto; padding: 1.25rem 5% 1rem;
  display: flex; flex-direction: column; gap: 0.12rem;
}

.message-row {
  display: flex; max-width: 65%; margin-bottom: 0.12rem;
}
.message-row.inbound { align-self: flex-start; }
.message-row.outbound { align-self: flex-end; margin-left: auto; }

.message-bubble {
  position: relative; padding: 0.38rem 0.55rem 0.28rem 0.65rem;
  line-height: 1.35; box-shadow: var(--bubble-shadow);
  max-width: 100%;
}
.message-row.inbound .message-bubble {
  background: var(--bubble-in);
  border-radius: 0 7.5px 7.5px 7.5px;
}
.message-row.inbound .message-bubble::before {
  content: '';
  position: absolute; top: 0; left: -8px;
  border-width: 0 8px 8px 0;
  border-style: solid;
  border-color: transparent var(--bubble-in) transparent transparent;
}
.message-row.outbound .message-bubble {
  background: var(--bubble-out);
  border-radius: 7.5px 0 7.5px 7.5px;
}
.message-row.outbound .message-bubble::before {
  content: '';
  position: absolute; top: 0; right: -8px;
  border-width: 8px 0 0 8px;
  border-style: solid;
  border-color: var(--bubble-out) transparent transparent transparent;
}

.message-sender {
  display: block; font-size: 0.72rem; font-weight: 600;
  color: rgba(255,255,255,0.75); margin-bottom: 0.15rem;
}
.message-text {
  display: inline; white-space: pre-wrap; word-break: break-word;
  font-size: 0.875rem; padding-right: 0.35rem;
}

.message-row.has-media {
  max-width: 75%;
}
.message-row.has-media .message-bubble {
  padding: 0.25rem 0.25rem 0.28rem;
  overflow: hidden;
}
.message-row.has-media .message-text {
  display: block;
  padding: 0.2rem 0.45rem 0;
}
.message-media-trigger {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  margin-bottom: 0.15rem;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.message-media-trigger:hover {
  opacity: 0.92;
}
.message-media-trigger img,
.message-media-trigger video {
  display: block;
  max-width: min(320px, 100%);
  max-height: 360px;
  width: auto;
  height: auto;
  border-radius: 6px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.15);
  pointer-events: none;
}
.message-media-trigger-video .message-media-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.message-media-trigger-audio,
.message-media-trigger-document {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.65rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  max-width: min(280px, 100%);
}
.message-media-file-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
}
.message-media-file-label {
  font-size: 0.875rem;
  color: #53bdeb;
  word-break: break-word;
}
.message-media-trigger:hover .message-media-file-label {
  text-decoration: underline;
}

.media-viewer-dialog {
  width: min(920px, 96vw);
  max-height: 92vh;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
}
.media-viewer-body {
  position: relative;
  padding: 1rem 1.25rem 1.25rem;
  display: grid;
  gap: 0.85rem;
  max-height: 92vh;
  overflow: auto;
}
.media-viewer-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 2;
}
.media-viewer-title {
  margin: 0;
  padding-right: 2.5rem;
  font-size: 1rem;
  font-weight: 600;
  word-break: break-word;
}
.media-viewer-content {
  display: grid;
  place-items: center;
  min-height: 120px;
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 0.75rem;
  overflow: auto;
}
.media-viewer-image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 8px;
}
.media-viewer-video {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
  background: #000;
}
.media-viewer-audio {
  width: min(480px, 100%);
}
.media-viewer-frame {
  width: 100%;
  min-height: 70vh;
  border: 0;
  border-radius: 8px;
  background: #fff;
}
.media-viewer-fallback {
  text-align: center;
  padding: 1.5rem 1rem;
}
.media-viewer-fallback p {
  margin: 0.5rem 0 0;
}
.media-viewer-fallback-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.media-viewer-actions {
  display: flex;
  justify-content: flex-end;
}
.message-meta {
  float: right; margin-left: 0.5rem; margin-top: 0.35rem;
  display: inline-flex; align-items: center; gap: 0.2rem;
  position: relative; top: 0.25rem;
}
.message-meta time {
  font-size: 0.68rem; color: rgba(255,255,255,0.55); white-space: nowrap;
}

.chat-toolbar {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 0.45rem 0.75rem;
}
.chat-toolbar-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chat-toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent);
}
.quick-messages-scroll {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  max-height: 88px;
  overflow-y: auto;
  flex: 1;
  min-width: 0;
}
.chat-attachment-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}
.chat-attachment-thumb {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-attachment-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
}
.chat-attachment-name {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quick-messages-category {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-right: 0.15rem;
}
.quick-message-chip {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.quick-message-insert {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quick-message-insert:hover { background: var(--bg-hover); }
.quick-message-send {
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  width: 30px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.quick-message-send:hover { background: var(--bg-hover); }
.quick-message-send:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  padding: 0.55rem 1rem; background: var(--bg-elevated);
}
.composer-field {
  flex: 1; background: var(--bg-panel); border-radius: 8px;
  padding: 0.45rem 0.75rem;
}
.composer-field textarea {
  width: 100%; border: none; background: transparent; color: var(--text);
  resize: none; font: inherit; font-size: 0.95rem; line-height: 1.4;
  max-height: 120px; padding: 0.15rem 0;
}
.composer-field textarea:focus { outline: none; }
.btn-send {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0;
  transition: background 0.15s ease;
}
.btn-send:hover { background: var(--accent-dark); }

.page-content {
  padding: 1.25rem 1.5rem 1.5rem;
  width: 100%;
  max-width: none;
  margin: 0;
  flex: 1;
  overflow: auto;
  box-sizing: border-box;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  width: 100%;
}
.page-header h1 { margin: 0 0 0.35rem; }
.page-header p { margin: 0; color: var(--text-muted); }
.table-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  width: 100%;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.data-table th,
.data-table td { padding: 0.9rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }
.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.8rem;
  background: var(--bg-hover);
}
.badge.admin { color: #9ad7ff; }
.badge.agent { color: #c6f6b0; }
.badge.inactive { color: #ffb4a9; }

.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--bg-elevated); color: var(--text);
  width: min(460px, 92vw);
}
.modal::backdrop { background: rgba(0,0,0,0.55); }
.modal form { padding: 1.25rem; display: grid; gap: 0.85rem; }
.modal h3 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.form-hint { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.empty-row { text-align: center; color: var(--text-muted); padding: 2rem !important; }

.tabs-bar {
  display: flex; gap: 0.35rem; margin-bottom: 1rem;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.tab-btn {
  border: 0; background: transparent; color: var(--text-muted);
  padding: 0.65rem 1rem; font: inherit; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: block; }
.tab-panel.is-hidden { display: none; }

.page-header-actions { display: flex; align-items: center; gap: 0.5rem; }

.settings-layout {
  display: grid;
  gap: 1.25rem;
}
.settings-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.settings-card-header {
  padding: 1.1rem 1.25rem 0.35rem;
  border-bottom: 1px solid var(--border);
}
.settings-card-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}
.settings-card-header p {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.settings-card-body {
  padding: 1.1rem 1.25rem 1.25rem;
  display: grid;
  gap: 0.9rem;
}
.settings-card-body label {
  display: grid;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.settings-card-body input,
.settings-card-body textarea,
.settings-card-body select {
  width: 100%;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font: inherit;
}
.settings-card-body textarea { resize: vertical; min-height: 120px; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}
.toggle-row {
  display: flex !important;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 0.95rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.toggle-row input { width: auto; margin-top: 0.2rem; }
.toggle-row span { display: grid; gap: 0.2rem; }
.toggle-row strong { color: var(--text); font-weight: 600; }
.toggle-row small { color: var(--text-muted); font-size: 0.85rem; }
.label-optional { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.settings-actions-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.test-result {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.test-result.is-success { color: #7dffb3; }
.test-result.is-error { color: #ff8a80; }
.settings-test-prompt {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.5rem;
  padding: 0.95rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.settings-api-example {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.settings-api-example pre {
  margin: 0.5rem 0 0;
  overflow: auto;
  font-size: 0.82rem;
  line-height: 1.45;
}
.settings-api-example code {
  white-space: pre;
}
.test-prompt-result {
  padding: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.test-prompt-result p {
  margin: 0.35rem 0 0;
  white-space: pre-wrap;
  color: var(--text);
}
.settings-footer {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 1rem;
}
.form-success {
  margin: 0;
  color: #7dffb3;
  font-size: 0.9rem;
}

.ai-bot-table .cell-message {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-bot-table th:nth-child(1),
.ai-bot-table td:nth-child(1) { width: 8%; }
.ai-bot-table th:nth-child(2),
.ai-bot-table td:nth-child(2) { width: 24%; }
.ai-bot-table th:nth-child(3),
.ai-bot-table td:nth-child(3) { width: 28%; }
.ai-bot-table th:nth-child(4),
.ai-bot-table td:nth-child(4) { width: 14%; }
.ai-bot-table th:nth-child(5),
.ai-bot-table td:nth-child(5) { width: 12%; }
.ai-bot-table th:nth-child(6),
.ai-bot-table td:nth-child(6) { width: 14%; }

.ai-bot-table .cell-actions {
  white-space: nowrap;
}

.ai-bot-table tr.row-inactive td {
  opacity: 0.65;
}

.modal-wide {
  width: min(560px, 92vw);
}

.rule-reply-row {
  display: grid;
  gap: 0.5rem;
}

.rule-reply-row label {
  margin: 0;
}

.knowledge-format-card {
  margin-bottom: 1.25rem;
}

.json-example {
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #9ad7ff;
  overflow: auto;
  white-space: pre-wrap;
}

#knowledge-form input[type="file"] {
  width: 100%;
  background: var(--bg-panel);
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  font: inherit;
}

#knowledge-form textarea {
  width: 100%;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  resize: vertical;
}

.ai-bot-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.ai-bot-simulator-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 520px;
}

.ai-bot-chat {
  flex: 1;
  min-height: 320px;
  max-height: 480px;
  overflow: auto;
  padding: 1rem;
  background: var(--chat-bg);
  background-image: url('/img/wa-wallpaper.svg');
  background-size: 400px 400px;
  background-repeat: repeat;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ai-bot-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 320px;
  line-height: 1.5;
}

.ai-bot-message {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 85%;
}

.ai-bot-message.inbound {
  align-self: flex-start;
}

.ai-bot-message.outbound {
  align-self: flex-end;
}

.ai-bot-message-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0 0.35rem;
}

.ai-bot-bubble {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
  box-shadow: var(--bubble-shadow);
}

.ai-bot-message.inbound .ai-bot-bubble {
  background: var(--bubble-in);
  border-radius: 0 8px 8px 8px;
}

.ai-bot-message.outbound .ai-bot-bubble {
  background: var(--bubble-out);
  border-radius: 8px 0 8px 8px;
}

.ai-bot-composer {
  display: grid;
  gap: 0.75rem;
}

.ai-bot-composer label {
  display: grid;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.ai-bot-composer textarea {
  width: 100%;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  resize: vertical;
}

.ai-bot-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  :root { --sidebar-width: 72px; }
  .sidebar-brand strong,
  .sidebar-link span,
  .sidebar-section,
  .sidebar-user-name,
  .sidebar-user-role {
    display: none;
  }
  .sidebar-brand {
    justify-content: center;
    padding: 1rem 0.5rem;
  }
  .sidebar-link {
    justify-content: center;
    padding: 0.7rem;
  }
  .sidebar-link.active {
    box-shadow: inset 0 3px 0 var(--accent);
  }
  .wa-nav-status {
    justify-content: center;
    font-size: 0;
    padding: 0.55rem;
  }
  .wa-nav-status::before {
    margin: 0;
  }
  .chat-layout { flex-direction: column; }
  .chat-sidebar {
    width: 100% !important;
    max-width: none;
    max-height: 42vh;
  }
  .chat-splitter {
    flex: 0 0 4px;
    cursor: row-resize;
  }
  .chat-splitter::after {
    left: 0;
    right: 0;
    top: -4px;
    bottom: -4px;
  }
  .chat-panel { min-width: 0; }
  .settings-grid { grid-template-columns: 1fr; }
  .ai-bot-layout { grid-template-columns: 1fr; }
}
