:root {
  --bg: #0b1418;
  --panel: #111b21;
  --panel-alt: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --text-muted: #8696a0;
  --accent: #00a884;
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
  --danger: #f15c6d;
  --warning: #d9a441;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand .logo {
  height: 24px;
  width: auto;
}

.brand h1 {
  font-weight: 500;
  color: var(--text-muted);
}

.stats {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
}

.stats b { color: var(--text); font-weight: 600; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.user-name {
  font-size: 13px;
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel-alt);
  border-radius: 8px;
  padding: 3px;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.tab:hover { color: var(--text); }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; }

.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.main.view[hidden] { display: none; }

.admin-view { overflow-y: auto; }

.admin-panel {
  flex: 1;
  padding: 24px 28px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.admin-header h2 {
  font-size: 17px;
  margin: 0 0 6px;
}

.admin-hint {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 720px;
  line-height: 1.5;
  margin: 0 0 14px;
}

.admin-header input[type="text"] {
  width: 100%;
  max-width: 380px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 13px;
  margin-bottom: 14px;
}

.admin-header .filter-row {
  margin-bottom: 14px;
  gap: 12px;
}

.admin-header .filter-row input[type="date"] {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--panel-alt);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.admin-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--panel-alt); }

.admin-table .muted { color: var(--text-muted); }

.admin-table .pessoa-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.admin-table input[type="text"].inline-input,
.admin-table input[type="number"].inline-input {
  padding: 5px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  width: 100%;
}

.admin-table .search-box { position: relative; width: 220px; }

.admin-table .search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 5;
  margin-top: 2px;
}

.admin-table .search-result-item {
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.admin-table .search-result-item:last-child { border-bottom: none; }
.admin-table .search-result-item:hover { background: var(--panel-alt); }
.admin-table .search-result-item .tel { color: var(--text-muted); font-size: 11px; }

.btn {
  background: var(--accent);
  color: #06231c;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel-alt); color: var(--text); }
.btn.danger { background: none; color: var(--danger); border: 1px solid rgba(241, 92, 109, 0.4); }
.btn + .btn { margin-left: 6px; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.conversations {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.conversations-header {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.conversations-header input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 13px;
}

.filters {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.filters .filter-row:first-child {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.filters input,
.filters select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 12px;
  width: 100%;
}

.clear-filters {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
}

.clear-filters:hover {
  text-decoration: underline;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--panel-alt);
  position: sticky;
  top: 0;
  z-index: 1;
}

.group-header .group-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--panel);
  padding: 1px 7px;
  border-radius: 10px;
}

.conversation-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.conversation-item:hover { background: var(--panel-alt); }
.conversation-item.active { background: var(--panel-alt); border-left: 3px solid var(--accent); }

.conversation-item .name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item .meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.conversation-item .badges {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--panel-alt);
  color: var(--text-muted);
}

.badge.missed { background: rgba(241, 92, 109, 0.15); color: var(--danger); }

.timeline-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.timeline-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.timeline-header .name { font-size: 15px; font-weight: 600; }
.timeline-header .phone { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.empty-hint { color: var(--text-muted); font-size: 13px; }

.timeline {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.02) 0, transparent 40%),
    var(--bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day-divider {
  align-self: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--panel-alt);
  padding: 3px 10px;
  border-radius: 8px;
  margin: 12px 0 6px;
}

.msg {
  max-width: 60%;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.4;
  position: relative;
}

.msg.in { align-self: flex-start; background: var(--bubble-in); }
.msg.out { align-self: flex-end; background: var(--bubble-out); }

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

.msg .text { white-space: pre-wrap; word-break: break-word; }

.msg .time {
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}

.call-event {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--panel-alt);
  padding: 5px 12px;
  border-radius: 12px;
  margin: 4px 0;
}

.call-event.missed { color: var(--danger); }
.call-event .icon { font-size: 13px; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---- Dashboard "Agente IA" ---- */

.agente-panel { max-width: 1200px; }

.agente-section-header {
  margin-top: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.agente-section-header h3 { font-size: 14px; margin: 0; font-weight: 600; }
.agente-section-header .filter-row { margin: 0; flex-wrap: wrap; }
.agente-section-header select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.alert-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(217, 164, 65, 0.12);
  border: 1px solid rgba(217, 164, 65, 0.35);
  color: var(--warning);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
}

.alert-banner.critical {
  background: rgba(241, 92, 109, 0.1);
  border-color: rgba(241, 92, 109, 0.35);
  color: var(--danger);
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-tile .stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-tile.stat-warning { border-color: rgba(217, 164, 65, 0.5); }
.stat-tile.stat-warning .stat-value { color: var(--warning); }
.stat-tile.stat-critical { border-color: rgba(241, 92, 109, 0.5); }
.stat-tile.stat-critical .stat-value { color: var(--danger); }

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 8px;
}

.chart-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.chart-card-header h3 { font-size: 13px; margin: 0; font-weight: 600; }
.chart-card-header .muted { font-size: 11px; color: var(--text-muted); }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 100px;
}

.bar-chart .bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
  cursor: default;
}

.bar-chart .bar {
  width: 100%;
  max-width: 22px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}

.bar-chart .bar-col:hover .bar { filter: brightness(1.25); }

.bar-chart .bar-day {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
}

.bar-chart .bar-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
  z-index: 2;
}

.bar-chart .bar-col:hover .bar-tooltip { opacity: 1; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

.status-pill.ok { background: rgba(0, 168, 132, 0.15); color: var(--accent); }
.status-pill.warn { background: rgba(217, 164, 65, 0.15); color: var(--warning); }
.status-pill.error { background: rgba(241, 92, 109, 0.15); color: var(--danger); }
.status-pill.muted { background: var(--panel-alt); color: var(--text-muted); }

.admin-table .entrada-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-muted);
}
