:root {
  /* Light Mode (WhatsApp-like) */
  --bg-app: #f0f2f5;
  --bg-chat: #efeae2;
  --bg-header: #ffffff;
  --bg-input: #ffffff;
  --bg-bubble-sent: #dcf8c6;
  --bg-bubble-recv: #ffffff;

  --text-primary: #41525d;
  --text-secondary: #667781;
  --text-on-sent: #111b21;

  --border-color: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);

  --primary-color: #00a884;
  --danger-color: #ea0038;
  --focus-ring: rgba(0, 168, 132, 0.4);
}

html[data-theme="dark"] {
  /* Dark Mode (WhatsApp-like) */
  --bg-app: #111b21;
  --bg-chat: #0b141a;
  --bg-header: #202c33;
  --bg-input: #2a3942;
  --bg-bubble-sent: #005c4b;
  --bg-bubble-recv: #202c33;

  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-on-sent: #e9edef;

  --border-color: rgba(134, 150, 160, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);

  --primary-color: #00a884;
  --danger-color: #ff5c73;
  --focus-ring: rgba(0, 168, 132, 0.4);
}

/* Reset & Base */
* {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-app);
  color: var(--text-primary);
  transition: background 0.3s, color 0.3s;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

/* Utilities */
/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px !important;
  height: 6px !important;
}

::-webkit-scrollbar-track {
  background: transparent !important;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

html[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
  padding-top: 80px;
  /* Space for fixed navbar */
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-secondary);
  font-size: 0.9em;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flex-1 {
  flex: 1;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-2 {
  gap: 8px;
}

.gap-4 {
  gap: 16px;
}

/* Navbar */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
}

.nav-brand {
  font-weight: 800;
  font-size: 20px;
  color: var(--primary-color);
  margin-right: 32px;
  letter-spacing: -0.5px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: 20px;
  transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

html[data-theme="dark"] .nav-link:hover,
html[data-theme="dark"] .nav-link.active {
  background: rgba(255, 255, 255, 0.05);
}

.nav-user {
  font-size: 14px;
  font-weight: 600;
  margin-right: 12px;
  margin-left: 12px;
}

.nav-status {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 16px;
  font-weight: 600;
  margin-right: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 24px;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

html[data-theme="dark"] .btn {
  background: rgba(255, 255, 255, 0.08);
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

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

.btn-danger {
  background: rgba(234, 0, 56, 0.1);
  color: var(--danger-color);
}

html[data-theme="dark"] .btn-danger {
  background: rgba(255, 92, 115, 0.1);
}

.btn-icon {
  padding: 8px;
  border-radius: 50%;
  width: 36px;
  height: 36px;
}

/* Inputs */
input,
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  box-shadow: 0 0 0 2px var(--focus-ring);
  border-color: transparent;
}

/* Cards & Layouts */
.card {
  background: var(--bg-header);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 15px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 20px;
}

/* Login Layout */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-app);
}

.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-header);
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-color);
  text-align: center;
}

.login-title {
  font-size: 24px;
  font-weight: 300;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.login-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* Chat Layout (Agent) */
.chat-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  height: calc(100vh - 100px);
  gap: 16px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-header);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  gap: 12px;
  align-items: center;
}

.conv-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

html[data-theme="dark"] .conv-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.conv-item.active {
  background: rgba(0, 168, 132, 0.08);
}

.conv-avatar {
  width: 40px;
  height: 40px;
  background: #dfe5e7;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
}

html[data-theme="dark"] .conv-avatar {
  background: #374045;
}

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.conv-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.conv-msg {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  position: relative;
}

/* WhatsApp background pattern opacity */
.chat-main::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png");
  opacity: 0.06;
  pointer-events: none;
  filter: grayscale(100%);
}

html[data-theme="dark"] .chat-main::before {
  opacity: 0.04;
  filter: invert(1);
}

.chat-header {
  padding: 10px 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1;
}

/* Message Bubbles - WhatsApp Style */
.msg-row {
  display: flex;
  margin-bottom: 2px;
  padding: 0 8%;
}

.msg-row.msg-me {
  justify-content: flex-end;
}

.msg-row:not(.msg-me) {
  justify-content: flex-start;
}

.msg-bubble {
  max-width: 100%;
  padding: 6px 7px 8px 9px;
  border-radius: 7.5px;
  position: relative;
  font-size: 14.2px;
  line-height: 19px;
  filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.13));
  background: var(--bg-bubble-recv);
  color: var(--text-primary);
  word-wrap: break-word;
}

/* Tails */
.msg-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
}

/* Received Message Tail */
.msg-row:not(.msg-me) .msg-bubble {
  border-top-left-radius: 0;
  margin-left: 8px;
}

.msg-row:not(.msg-me) .msg-bubble::before {
  left: -8px;
  top: 0;
  border-top: 0;
  border-right: 8px solid var(--bg-bubble-recv);
  border-bottom: 10px solid transparent;
}

/* Sent Message Tail */
.msg-me .msg-bubble {
  background: var(--bg-bubble-sent);
  color: var(--text-on-sent);
  border-top-right-radius: 0;
  margin-right: 8px;
}

.msg-me .msg-bubble::before {
  right: -8px;
  top: 0;
  border-top: 0;
  border-left: 8px solid var(--bg-bubble-sent);
  border-bottom: 10px solid transparent;
}

/* Quoted Message Style */
.msg-quote {
  background: rgba(0, 0, 0, 0.05);
  border-left: 4px solid var(--primary-color);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

html[data-theme="dark"] .msg-quote {
  background: rgba(0, 0, 0, 0.2);
}

.quote-sender {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 2px;
  font-size: 12px;
}

.quote-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reply Preview Area */
.reply-preview {
  padding: 8px 16px;
  background: var(--bg-header);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.reply-content {
  background: rgba(0, 0, 0, 0.05);
  border-left: 4px solid var(--primary-color);
  padding: 6px 10px;
  border-radius: 4px;
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-right: 12px;
  display: flex;
  flex-direction: column;
}

html[data-theme="dark"] .reply-content {
  background: rgba(255, 255, 255, 0.05);
}

.msg-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  float: right;
  margin-left: 8px;
  margin-top: 4px;
}

.date-divider {
  text-align: center;
  margin: 12px 0;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 8px;
  align-self: center;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

html[data-theme="dark"] .date-divider {
  background: rgba(0, 0, 0, 0.2);
  text-shadow: none;
}

.chat-footer {
  padding: 10px 16px;
  background: var(--bg-header);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 2;
}

/* Dashboard Grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px;
  text-align: center;
}

.stat-val {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary-color);
  margin: 8px 0;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Context Menu */
.ctx-menu {
  position: absolute;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  z-index: 1000;
  min-width: 160px;
  display: none;
}

.ctx-item {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-primary);
  transition: background 0.2s;
}

.ctx-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

html[data-theme="dark"] .ctx-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.ctx-item svg {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}
