:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e2e5e9;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --error: #dc2626;
  --chart-bar: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1d2025;
    --text: #e7e9ec;
    --muted: #9aa1ac;
    --border: #2a2e35;
    --accent: #3b82f6;
    --accent-text: #ffffff;
    --chart-bar: #3987e5;
  }
}

* { box-sizing: border-box; }

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

h1 { font-size: 1.4rem; font-weight: 700; margin: 0 0 1.25rem; letter-spacing: -0.01em; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 0.85rem; }

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem 0.9rem;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.4rem; }
.brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; letter-spacing: -0.01em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--accent); color: var(--accent-text); }
.nav-icon { width: 1.15rem; height: 1.15rem; flex-shrink: 0; display: flex; }
.nav-icon svg { width: 100%; height: 100%; }
.logout-form { margin: 0; }

main {
  flex: 1;
  min-width: 0;
  max-width: 900px;
  padding: 2rem 2rem 4rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.settings-form { display: flex; flex-direction: column; gap: 0.85rem; }
.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}
input[type="text"], input[type="password"], textarea {
  font-size: 0.95rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
textarea { resize: vertical; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  color: var(--text) !important;
  font-size: 0.95rem !important;
}
.checkbox-label input[type="checkbox"] { width: 1.05rem; height: 1.05rem; }

.guide {
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.guide summary { cursor: pointer; color: var(--text); font-weight: 600; }
.guide ol { padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.6rem; }

.copy-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.copy-row code { flex: 1; min-width: 0; }

/* Gráfico de mensagens por dia */
.chart-container { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-bar { fill: var(--chart-bar); cursor: pointer; transition: opacity 0.15s; }
.chart-bar:hover { opacity: 0.8; }
.chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 10px; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  white-space: nowrap;
  transform: translateY(-100%);
  z-index: 10;
}

/* Lista de números permitidos */
.allowlist-add-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.allowlist-add-row input {
  flex: 1;
  min-width: 160px;
  font-size: 0.95rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.allowlist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.allowlist-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.allowlist-number { font-weight: 600; font-variant-numeric: tabular-nums; }
.allowlist-name { color: var(--muted); flex: 1; }
.allowlist-remove { margin-left: auto; color: var(--error); }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

button, .button {
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  display: inline-block;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.link-button { background: none; color: var(--muted); padding: 0; text-decoration: underline; cursor: pointer; }

.feedback { min-height: 1.2rem; font-size: 0.85rem; margin: 0; }
.feedback.success { color: var(--ok); }
.feedback.error { color: var(--error); }

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--error); }

code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
  word-break: break-all;
}

.status-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.status-item { display: flex; align-items: center; gap: 0.75rem; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: rgba(22, 163, 74, 0.15); color: var(--ok); }
.badge.warn { background: rgba(217, 119, 6, 0.15); color: var(--warn); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table tbody tr:hover { background: var(--bg); }
.inline-form { display: inline; }

.avatar {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.contact-cell { display: flex; align-items: center; gap: 0.7rem; text-decoration: none; color: var(--text); }
.contact-cell-text { display: flex; flex-direction: column; }
.contact-name { font-weight: 600; }
.contact-sub { font-size: 0.78rem; color: var(--muted); }

.thread-header { display: flex; align-items: center; gap: 0.75rem; }

.thread { display: flex; flex-direction: column; gap: 0.6rem; }
.bubble { max-width: 75%; padding: 0.55rem 0.8rem; border-radius: 12px; }
.bubble.user { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.bubble.assistant { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.bubble-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.bubble-time { font-size: 0.7rem; opacity: 0.7; margin-top: 0.25rem; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-card h1 { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    padding: 0.6rem 0.8rem;
    gap: 0.75rem;
  }
  .sidebar .brand { padding: 0; }
  .brand-name { display: none; }
  .sidebar-nav { flex-direction: row; flex: 1; }
  .nav-label { display: none; }
  .nav-link { padding: 0.5rem; }
  .logout-form { margin-left: auto; }
  main { padding: 1.25rem 1rem 3rem; }
  .bubble { max-width: 90%; }
}
