:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-alt: #182229;
  --border: #253038;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-dark: #008069;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --danger: #e05252;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: auto;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 340px;
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-card form { display: flex; flex-direction: column; gap: 6px; margin-top: 20px; }
.login-card label { font-size: 12px; color: var(--muted); margin-top: 8px; }
.login-card input {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.login-card button {
  margin-top: 18px;
  background: var(--accent);
  border: none;
  color: #06231c;
  font-weight: 600;
  padding: 11px;
  border-radius: 8px;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); color: #fff; }
.alert-error {
  background: rgba(224, 82, 82, 0.15);
  color: #ff9b9b;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 12px;
}
.alert-success {
  background: rgba(0, 168, 132, 0.15);
  color: var(--accent);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- App layout ---------- */
.app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 340px;
  min-width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { margin: 0; font-size: 18px; }
.sidebar-actions a {
  color: var(--muted);
  margin-left: 14px;
  font-size: 16px;
}
.sidebar-actions a:hover { color: var(--text); }

.brand-tabs, .filter-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.brand-tab, .filter-tab {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.brand-tab.active, .filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231c;
  font-weight: 600;
}

.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: var(--panel-alt); }
.conv-item.active { background: var(--panel-alt); border-left: 3px solid var(--accent); }
.conv-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--panel-alt);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0;
  border: 2px solid transparent;
}
.conv-info { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-size: 14px; font-weight: 600; }
.conv-time { font-size: 11px; color: var(--muted); }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.conv-preview {
  font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}
.conv-badges { display: flex; gap: 6px; align-items: center; }
.unread-badge {
  background: var(--accent); color: #06231c; font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px;
}
.brand-chip {
  font-size: 10px; padding: 2px 6px; border-radius: 8px; color: #06231c; font-weight: 600;
}
.agent-chip { font-size: 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 1px 6px; }
.empty-state { padding: 30px 16px; color: var(--muted); text-align: center; font-size: 13px; }

/* ---------- Chat panel ---------- */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  background-image: radial-gradient(circle at 25% 15%, rgba(0,168,132,0.05), transparent 40%);
}
.chat-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}
.chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.chat-header-name { font-size: 15px; font-weight: 600; }
.chat-header-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
#assignSelect {
  background: var(--panel-alt); color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px; font-size: 12px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bubble {
  max-width: 60%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.bubble-meta { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }

.composer {
  display: flex; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel);
}
.composer input {
  flex: 1; background: var(--panel-alt); border: 1px solid var(--border);
  color: var(--text); padding: 11px 14px; border-radius: 20px; font-size: 14px;
}
.composer button {
  background: var(--accent); border: none; color: #06231c; font-weight: 600;
  padding: 0 22px; border-radius: 20px; cursor: pointer;
}
.composer button:hover { background: var(--accent-dark); color: #fff; }

/* ---------- Settings ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar-back { color: var(--muted); }
.topbar h2 { margin: 0; font-size: 16px; }
.settings-wrap { max-width: 720px; margin: 0 auto; padding: 30px 20px; overflow-y: auto; height: calc(100vh - 57px); }
.settings-section { margin-bottom: 34px; }
.settings-section h3 { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.settings-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 13px; }
.settings-table th, .settings-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.settings-table th { color: var(--muted); font-weight: 500; }
.color-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; }
.settings-form, .inline-form { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--border); padding: 16px; border-radius: 10px; }
.inline-form { flex-direction: row; align-items: center; padding: 10px; }
.settings-form label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.settings-form input, .settings-form select, .inline-form input {
  background: var(--panel-alt); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 6px; font-size: 13px;
}
.settings-form button, .inline-form button {
  margin-top: 12px; background: var(--accent); border: none; color: #06231c; font-weight: 600;
  padding: 9px; border-radius: 6px; cursor: pointer;
}
.btn-danger-sm { background: var(--danger); color: #fff; border: none; padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; }
.btn-secondary-sm { background: var(--panel-alt); border: 1px solid var(--border); color: var(--text); padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; }

@media (max-width: 760px) {
  .sidebar { position: absolute; z-index: 5; height: 100%; width: 100%; }
  .app.chat-open .sidebar { display: none; }
}
