:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #697386;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, .09);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, .12), transparent 38%),
    linear-gradient(315deg, rgba(22, 163, 74, .10), transparent 36%),
    #f8fafc;
}
.login-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 18px;
  padding: 30px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0891b2);
  font-weight: 800;
}
.login-card h1 { margin: 16px 0 6px; }
.login-card p { color: var(--muted); margin: 0; }
.login-form { display: grid; gap: 16px; margin-top: 28px; }
.login-form label, .field label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 650;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.login-form button, .primary-btn, .reply-box button {
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  font-weight: 750;
}
.login-form button:hover, .primary-btn:hover, .reply-box button:hover { background: var(--primary-strong); }
.form-error { min-height: 20px; color: var(--red) !important; font-size: 13px; }

.app { display: grid; grid-template-columns: 268px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: #0f172a;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; color: #94a3b8; margin-top: 2px; }
.nav { display: grid; gap: 8px; }
.nav-item, .ghost-btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 12px;
  color: #cbd5e1;
  background: transparent;
  text-align: left;
}
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(148, 163, 184, .16); }
.ghost-btn { margin-top: auto; border: 1px solid rgba(148, 163, 184, .25); text-align: center; }

.workspace { padding: 24px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: clamp(24px, 3vw, 36px); letter-spacing: 0; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.top-actions { display: flex; gap: 10px; align-items: center; }
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(22, 163, 74, .22);
  color: #166534;
  background: #dcfce7;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
}
.icon-btn, .chip, .secondary-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
}
.secondary-btn.active { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.secondary-btn:disabled { opacity: .5; cursor: not-allowed; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.kpi {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 25px rgba(15, 23, 42, .05);
  text-align: left;
}
.kpi span { color: var(--muted); font-size: 13px; font-weight: 700; }
.kpi strong { display: block; font-size: 28px; margin-top: 8px; letter-spacing: 0; }
.kpi:hover { border-color: rgba(37, 99, 235, .45); transform: translateY(-1px); }

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: end;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 16px;
}
.field { min-width: 150px; }
.field.grow { flex: 1; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(400px, 1fr) minmax(280px, 380px);
  gap: 16px;
  align-items: stretch;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 560px;
  box-shadow: 0 8px 25px rgba(15, 23, 42, .05);
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }

.conversation-list, .message-list {
  height: 496px;
  overflow: auto;
}
.conversation, .message-row {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: #fff;
  text-align: left;
}
.conversation:hover, .conversation.active { background: #f8fbff; }
.row-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  margin-right: 10px;
}
.platform-whatsapp { background: #16a34a; }
.platform-telegram { background: #0284c7; }
.platform-instagram { background: linear-gradient(135deg, #f97316, #db2777, #7c3aed); }
.conversation-title { display: flex; align-items: center; min-width: 0; }
.conversation-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview, .message-row p { color: var(--muted); margin: 8px 0 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pill {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
}
.unread { background: #fee2e2; color: #991b1b; }

.thread-panel { display: flex; flex-direction: column; min-height: 560px; }
.thread-messages {
  flex: 1;
  overflow: auto;
  padding: 18px;
  background: linear-gradient(#ffffff, #f8fafc);
}
.empty-state { color: var(--muted); display: grid; place-items: center; text-align: center; }
.bubble {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 14px;
  margin: 10px 0;
  line-height: 1.45;
  white-space: pre-wrap;
}
.bubble.in { background: #eef2ff; border-top-left-radius: 4px; }
.bubble.out { margin-left: auto; background: #dcfce7; border-top-right-radius: 4px; }
.bubble small { display: block; color: var(--muted); margin-top: 6px; font-size: 11px; }
.reply-box {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.reply-box textarea { resize: vertical; min-height: 48px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  background: #111827;
  color: #fff;
  padding: 14px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .content-grid { grid-template-columns: 330px 1fr; }
  .message-panel { grid-column: 1 / -1; min-height: 340px; }
  .message-list { height: 280px; }
}

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px; }
  .nav { grid-template-columns: repeat(2, 1fr); }
  .workspace { padding: 14px; }
  .topbar, .filter-bar { flex-direction: column; align-items: stretch; }
  .kpi-grid, .content-grid { grid-template-columns: 1fr; }
  .panel { min-height: 420px; }
  .conversation-list, .message-list { height: 360px; }
  .reply-box { grid-template-columns: 1fr; }
  .bubble { max-width: 92%; }
}
