:root {
  color-scheme: light;
  --bg: #f7f5f2;
  --panel: #ffffff;
  --ink: #1f2320;
  --muted: #6b7269;
  --border: #e4e1db;
  --accent: #2f5d4f;
  --hot: #c1502e;
  --warm: #c78a2b;
  --cold: #5b7a8c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

.screen { height: 100%; }
[hidden] { display: none !important; }

.login-box {
  max-width: 320px;
  margin: 15vh auto;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.login-box input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.login-box button {
  padding: 10px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.error { color: var(--hot); font-size: 13px; margin: 0; }

.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 15px; margin: 0; }
.wa-status { font-size: 12px; color: var(--muted); flex: 1; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
}

.qr-panel {
  padding: 20px;
  text-align: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.qr-panel img { width: 220px; height: 220px; margin-top: 12px; }

.main-layout { display: flex; height: calc(100% - 52px); }
.sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--panel);
}
.sidebar-section { padding: 12px; border-bottom: 1px solid var(--border); }
.sidebar-section h2 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }

.alerts-list, .leads-list { display: flex; flex-direction: column; gap: 6px; }
.alert-item {
  padding: 8px 10px;
  background: #fbeee9;
  border: 1px solid #f0d4c8;
  border-radius: 8px;
  font-size: 12px;
}
.alert-resolve { border: none; background: none; color: var(--accent); cursor: pointer; font-size: 11px; margin-top: 4px; }

.lead-item {
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
}
.lead-item:hover { background: #f0eee9; }
.lead-item.active { background: #e9efec; border-color: var(--accent); }
.lead-item .lead-top { display: flex; justify-content: space-between; align-items: center; }
.lead-item .lead-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  color: white;
  background: var(--muted);
}
.badge-hot { background: var(--hot); }
.badge-warm { background: var(--warm); }
.badge-cold { background: var(--cold); }
.badge-handoff { background: var(--hot); margin-left: 8px; }

.conversation-pane { flex: 1; display: flex; flex-direction: column; }
.empty-state { margin: auto; color: var(--muted); font-size: 14px; }

.conversation { display: flex; flex-direction: column; height: 100%; }
.conversation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.conv-meta { flex: 1; font-size: 12px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; }
.msg-LEAD { align-self: flex-start; background: #eceae5; }
.msg-AI { align-self: flex-end; background: #dcebe4; }
.msg-HUMAN { align-self: flex-end; background: #d8e3ee; }
.msg-SYSTEM { align-self: center; background: #f5e9d9; font-size: 11px; color: var(--muted); }

.reply-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--panel); }
.reply-form input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.reply-form button { padding: 10px 16px; background: var(--accent); color: white; border: none; border-radius: 8px; cursor: pointer; }

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.settings-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-row h2 { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.settings-wa-controls { display: flex; align-items: center; gap: 12px; }
.settings-panel textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
.settings-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.settings-actions button {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
