:root {
  --wa: #25d366;
  --wa-dark: #075e54;
  --wa-mid: #128c7e;
  --bg: #eef2f0;
  --panel: #ffffff;
  --ink: #1a2b24;
  --muted: #6b7f76;
  --line: #dce5e1;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --bottom-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app-shell {
  min-height: 100%;
  display: flex;
}

.sidebar,
.sidebar-offcanvas {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #064e46 0%, #0a6b5f 100%);
  color: #fff;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  flex: 0 0 var(--sidebar-w);
}

.sidebar-offcanvas {
  background: linear-gradient(180deg, #064e46 0%, #0a6b5f 100%);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.1rem 0.9rem;
  font-weight: 700;
  font-size: 1.1rem;
}

.sidebar-brand i {
  font-size: 1.35rem;
  color: var(--wa);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  font-weight: 500;
}

.side-link i { font-size: 1.1rem; width: 1.25rem; text-align: center; }

.side-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.side-link.active {
  background: rgba(37, 211, 102, 0.22);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--wa);
}

.sidebar-foot {
  padding: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}

.status-pill.ok { background: rgba(37,211,102,0.2); color: #b8f5d0; }
.status-pill.warn { background: rgba(255,193,7,0.2); color: #ffe08a; }

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-title {
  font-size: 1.15rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.content {
  padding: 1rem;
  padding-bottom: calc(1rem + var(--bottom-h));
  width: 100%;
  max-width: 980px;
}

.content:has(.chat-shell) {
  max-width: none;
  width: 100%;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  padding-top: 0.5rem;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topbar-h) - var(--bottom-h) - 0.5rem);
}

@media (min-width: 992px) {
  .content {
    padding: 1.25rem 1.5rem 1.5rem;
    padding-bottom: 1.5rem;
  }
  .content:has(.chat-shell) {
    max-width: none;
    width: 100%;
    min-height: calc(100vh - var(--topbar-h) - 1rem);
    padding: 0.75rem 1rem 1rem;
  }
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-h);
  background: #fff;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
}

.bottom-nav a i { font-size: 1.2rem; }
.bottom-nav a.active { color: var(--wa-mid); }

.btn-wa {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--wa-mid);
  --bs-btn-border-color: var(--wa-mid);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #0b6b5f;
  --bs-btn-hover-border-color: #0b6b5f;
  --bs-btn-active-bg: #0a5c52;
  --bs-btn-disabled-bg: #9bb8b3;
  --bs-btn-disabled-border-color: #9bb8b3;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}

.stat-box .label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-box .value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 0.2rem;
}

.type-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.15rem;
}

.type-tab {
  flex: 1 0 auto;
  min-width: 4.6rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0.65rem 0.4rem;
  text-align: center;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.type-tab i {
  display: block;
  font-size: 1.15rem;
  margin-bottom: 0.2rem;
}

.type-tab.active {
  border-color: var(--wa-mid);
  background: rgba(18, 140, 126, 0.08);
  color: var(--wa-dark);
}

.contact-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
}

.contact-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.contact-chip:hover,
.contact-chip.active {
  border-color: var(--wa-mid);
  background: rgba(18, 140, 126, 0.1);
  color: var(--wa-dark);
}

.msg-list { display: flex; flex-direction: column; gap: 0.65rem; }

.msg-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
}

.msg-item .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.msg-item .body {
  font-size: 0.92rem;
  word-break: break-word;
}

.msg-item .when {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.35rem;
}

.sticky-send {
  position: sticky;
  bottom: calc(var(--bottom-h) + 0.5rem);
  z-index: 50;
}

@media (min-width: 992px) {
  .sticky-send { bottom: 1rem; }
}

.form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}

.form-control, .form-select {
  border-radius: 10px;
  border-color: var(--line);
  padding: 0.65rem 0.8rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--wa-mid);
  box-shadow: 0 0 0 0.2rem rgba(18, 140, 126, 0.15);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.side-link {
  position: relative;
}

.nav-badge {
  margin-left: auto;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #ff3b30;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.nav-badge.bottom {
  position: absolute;
  top: -4px;
  right: -10px;
  margin-left: 0;
}

.nav-ico-wrap {
  position: relative;
  display: inline-flex;
}

.toast-host {
  position: fixed;
  top: calc(var(--topbar-h) + 0.5rem);
  right: 0.75rem;
  left: 0.75rem;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: 420px;
  margin-left: auto;
}

@media (min-width: 992px) {
  .toast-host {
    left: auto;
    width: 360px;
  }
}

.app-toast {
  pointer-events: auto;
  display: block;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--wa);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  animation: toast-in 0.2s ease;
}

.app-toast.hide {
  opacity: 0;
  transform: translateY(-6px);
  transition: 0.25s ease;
}

.app-toast .toast-title {
  font-weight: 700;
  font-size: 0.9rem;
}

.app-toast .toast-body {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.15rem;
  word-break: break-word;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
}

.form-check-input:checked {
  background-color: var(--wa-mid);
  border-color: var(--wa-mid);
}

.select2-container--bootstrap-5 .select2-selection {
  min-height: 42px;
  border-radius: 10px;
  border-color: var(--line);
}

.select2-container--bootstrap-5 .select2-dropdown {
  border-color: var(--line);
  border-radius: 10px;
}

/* Chat list */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.chat-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
}

.chat-row:hover {
  border-color: var(--wa-mid);
  background: #f7fbf9;
}

.chat-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #d9efe6;
  color: var(--wa-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  font-size: 1.25rem;
}

.chat-avatar.sm {
  width: 38px;
  height: 38px;
  font-size: 1.05rem;
}

.chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #25d366;
  color: #053;
  font-size: 0.65rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-main { flex: 1; min-width: 0; }
.chat-top, .chat-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.chat-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-time {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}
.chat-preview {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  min-width: 0;
}
.chat-preview span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-phone {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 0.15rem;
}
.chat-chevron { color: #b7c6bf; flex-shrink: 0; }

/* Conversation */
.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #e5ddd5;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  background: #f0f2f5;
  border-bottom: 1px solid var(--line);
}

.btn-back-chat {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--wa-mid);
  color: #fff;
  text-decoration: none;
  font-size: 1.2rem;
  box-shadow: 0 2px 8px rgba(7, 94, 84, 0.25);
}
.btn-back-chat:hover {
  background: var(--wa-dark);
  color: #fff;
}

.loc-map {
  height: 180px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #dfece7;
}

.place-results {
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 160px;
  overflow-y: auto;
}

.place-item {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.82rem;
  color: var(--ink);
}
.place-item:hover,
.place-item.active {
  border-color: var(--wa-mid);
  background: rgba(18, 140, 126, 0.08);
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 280px;
  max-height: calc(100vh - 320px);
}

.bubble-row {
  display: flex;
}
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }

.bubble {
  max-width: min(85%, 420px);
  border-radius: 12px;
  padding: 0.45rem 0.65rem 0.35rem;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
  word-break: break-word;
}
.bubble-row.in .bubble {
  background: #fff;
  border-top-left-radius: 4px;
}
.bubble-row.out .bubble {
  background: #d9fdd3;
  border-top-right-radius: 4px;
}
.bubble.err {
  background: #ffe8e6 !important;
}

.bubble-type {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.bubble-text { font-size: 0.95rem; line-height: 1.35; }
.bubble-meta {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.chat-composer {
  background: #f0f2f5;
  border-top: 1px solid var(--line);
  padding: 0.55rem 0.65rem 0.7rem;
}

.attach-bar {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  margin-bottom: 0.45rem;
  -webkit-overflow-scrolling: touch;
}

.attach-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.attach-btn.active {
  background: var(--wa-mid);
  border-color: var(--wa-mid);
  color: #fff;
}

.composer-row {
  display: flex;
  gap: 0.45rem;
  align-items: flex-end;
}
.composer-row textarea {
  resize: none;
  min-height: 42px;
  max-height: 120px;
  border-radius: 18px;
}
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.empty-state.soft {
  background: transparent;
  border: 0;
  color: #6b6258;
  margin: auto;
}
