:root {
  --wa-green: #25D366;
  --wa-teal: #128C7E;
  --wa-teal-dark: #075E54;
  --sidebar-width: 230px;
  --bg-body: #f0f2f5;
  --bg-card: #ffffff;
  --text-main: #1c1e21;
  --border-color: #e9edef;
  --chat-bg: #efeae2;
  --bubble-out: #d9fdd3;
  --bubble-in: #ffffff;
}

[data-bs-theme="dark"] {
  --bg-body: #111b21;
  --bg-card: #202c33;
  --text-main: #e9edef;
  --border-color: #2a3942;
  --chat-bg: #0b141a;
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
}

* { box-sizing: border-box; }

body {
  background: var(--bg-body);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app-wrapper { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--wa-teal-dark);
  color: #fff;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 1.1rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex; align-items: center; gap: .5rem;
}
.sidebar-nav { padding: .5rem 0; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: .6rem;
  padding: .65rem 1.1rem;
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .92rem;
  transition: background .15s;
}
.sidebar-nav li a:hover, .sidebar-nav li a.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

/* ---- Main content ---- */
.main-content { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: .7rem 1.25rem;
  position: sticky; top: 0; z-index: 10;
}
.page-content { padding: 1.25rem; flex-grow: 1; }

.card { background: var(--bg-card); border-color: var(--border-color); color: var(--text-main); }
.table { color: var(--text-main); }
[data-bs-theme="dark"] .table-light { --bs-table-bg: #263640; --bs-table-color: #e9edef; }

/* ---- Stat cards ---- */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: .6rem;
  padding: 1rem;
  display: flex; align-items: center; gap: 1rem;
}
.stat-icon { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; }
.stat-label { font-size: .78rem; color: #8696a0; }

/* ---- Login page ---- */
.login-body {
  background: linear-gradient(135deg, var(--wa-teal-dark), var(--wa-teal));
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 1rem;
  padding: 2.2rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-icon { font-size: 2.6rem; color: var(--wa-green); }

/* ---- Chat layout ---- */
.chat-layout {
  display: flex;
  height: calc(100vh - 110px);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: .6rem;
  overflow: hidden;
}
.chat-list {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
}
.chat-list-items { overflow-y: auto; flex-grow: 1; }
.chat-list-item {
  display: flex; gap: .7rem; align-items: center;
  padding: .7rem 1rem;
  text-decoration: none;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
}
.chat-list-item:hover, .chat-list-item.active { background: var(--bg-body); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--wa-teal);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0;
}
.chat-thread { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-thread-header {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border-color);
}
.chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3C/svg%3E");
}
.msg-row { display: flex; margin-bottom: .5rem; }
.msg-row.out { justify-content: flex-end; }
.msg-bubble {
  max-width: 65%;
  padding: .5rem .7rem;
  border-radius: .5rem;
  box-shadow: 0 1px 1px rgba(0,0,0,.1);
  font-size: .92rem;
  background: var(--bubble-in);
  color: var(--text-main);
}
.msg-row.out .msg-bubble { background: var(--bubble-out); }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-meta { font-size: .68rem; color: #8696a0; text-align: right; margin-top: .2rem; }
.msg-card {
  border-left: 3px solid var(--wa-teal);
  background: rgba(18,140,126,.06);
  border-radius: .3rem;
  padding: .4rem .5rem .3rem;
  margin-bottom: .3rem;
}
.msg-row.out .msg-card { border-left-color: var(--wa-teal-dark); background: rgba(7,94,84,.08); }
.msg-card-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .02em;
  font-weight: 700;
  color: var(--wa-teal);
  margin-bottom: .25rem;
}
[data-bs-theme="dark"] .msg-card-label { color: #6fd3c7; }
.chat-media-img { max-width: 240px; border-radius: .4rem; display: block; margin-bottom: .3rem; }
.chat-media-doc { display: block; margin-bottom: .3rem; }
.chat-input-bar {
  display: flex; gap: .5rem;
  padding: .7rem 1rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

.log-payload {
  background: var(--bg-body);
  padding: .7rem; border-radius: .4rem;
  max-height: 300px; overflow: auto;
  font-size: .75rem;
}

/* ---- Responsive ---- */
@media (max-width: 992px) {
  .sidebar { position: fixed; left: -100%; z-index: 1050; transition: left .2s; }
  .sidebar.show { left: 0; }
  .chat-layout { height: calc(100vh - 160px); flex-direction: column; }
  .chat-list { width: 100%; height: 40%; border-right: none; border-bottom: 1px solid var(--border-color); }
  .chat-list.hide-on-mobile-chat { display: none; }
}
