:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #1f6f50;
  --primary-soft: #e6f2ec;
  --accent: #c9a35e;
  --danger: #b3452f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

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

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

/* Sidebar */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 14px; width: 16px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.online { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Content */
.content { flex: 1; padding: 28px 32px; min-width: 0; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.topbar h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--text-muted); font-size: 13px; }

.badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.view.hidden { display: none; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-delta { font-size: 12px; color: var(--text-muted); }
.stat-delta.up { color: var(--primary); }

/* Panels */
.panel-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel h2 { margin: 0 0 14px; font-size: 15px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-header h2 { margin: 0; }

/* Funnel */
.funnel-row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar { background: var(--bg); border-radius: 6px; overflow: hidden; height: 26px; }
.bar-fill {
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  border-radius: 6px;
  min-width: 34px;
}

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { font-size: 13px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.timeline li:last-child { border-bottom: none; padding-bottom: 0; }

/* Table */
.search {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  width: 220px;
}

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 8px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.tag.novo { background: #eef2ff; color: #4338ca; }
.tag.conversa { background: #fff7e6; color: #a16207; }
.tag.qualificado { background: var(--primary-soft); color: var(--primary); }
.tag.agendado { background: #e6f2ec; color: var(--primary); }
.tag.perdido { background: #fdecea; color: var(--danger); }
.tag.confirmado { background: var(--primary-soft); color: var(--primary); }
.tag.pendente { background: #fff7e6; color: #a16207; }

/* Chat */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100vh - 160px); }
.chat-list { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.chat-list .panel-header { padding: 16px 16px 12px; margin-bottom: 0; }
.chat-thread-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.chat-thread-list li {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.chat-thread-list li:hover { background: var(--bg); }
.chat-thread-list li.active { background: var(--primary-soft); }
.chat-thread-list .thread-name { font-weight: 600; display: block; margin-bottom: 2px; }
.chat-thread-list .thread-preview { color: var(--text-muted); font-size: 12px; }

.chat-window { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-window-header { padding: 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 70%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; }
.msg.lead { background: var(--bg); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.agent { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 3px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; }
  .nav { flex-direction: row; overflow-x: auto; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
}
