:root {
  --primary:    #011724;
  --secondary:  #39B285;
  --tertiary:   #0C3637;
  --bg:         #F0F0F0;
  --white:      #ffffff;
  --text:       #011724;
  --text-muted: #6B7280;
  --border:     #E5E7EB;
  --danger:     #EF4444;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(0,0,0,0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── LOGIN ─────────────────────────────────────────────────────────────── */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--tertiary) 100%);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.35);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo svg { display: block; margin: 0 auto 0.75rem; }

.login-logo h1 {
  font-size: 1.4rem;
  color: var(--primary);
  font-weight: 700;
}

.login-logo p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ── DASHBOARD ─────────────────────────────────────────────────────────── */

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

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--primary);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 20;
}

.sidebar-brand {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand-name { font-weight: 700; font-size: 1rem; color: var(--white); }
.sidebar-brand-sub  { font-size: 0.7rem; color: var(--secondary); margin-top: 1px; }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  user-select: none;
  border-right: 3px solid transparent;
}

.nav-item:hover { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.05); }
.nav-item.active {
  color: var(--secondary);
  background: rgba(57,178,133,0.12);
  border-right-color: var(--secondary);
}

.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* Main */
.main-content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h2 { font-size: 1.05rem; color: var(--primary); font-weight: 600; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}

.tab-content { padding: 1.5rem 2rem; }

/* ── STATS ─────────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--tertiary);
}

.stat-card.accent { border-top-color: var(--secondary); }

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.stat-card.accent .stat-value { color: var(--secondary); }

/* ── CARDS ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-header h3 { font-size: 0.95rem; color: var(--primary); font-weight: 600; }

.card-hint {
  padding: 0.6rem 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(57,178,133,0.05);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── TABLES ─────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  background: var(--bg);
  padding: 0.6rem 1.25rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text);
}

tbody tr:hover td { background: rgba(57,178,133,0.04); }

/* ── BADGES ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: rgba(57,178,133,0.15); color: #2a8a64; }
.badge-muted   { background: var(--bg); color: var(--text-muted); }
.badge-danger  { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-info    { background: rgba(1,23,36,0.08); color: var(--tertiary); }

/* ── FORMS ─────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

input, select {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(57,178,133,0.15);
}

.input-sm { width: auto; padding: 0.4rem 0.7rem; }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary   { background: var(--secondary); color: var(--white); }
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger    { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,0.08); }

.btn-ghost     { background: transparent; color: rgba(255,255,255,0.7); border: 1px solid rgba(255,255,255,0.2); }
.btn-ghost:hover { background: rgba(255,255,255,0.08); color: var(--white); }

.btn-sm  { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn-icon { padding: 0.4rem; }

/* ── TOGGLE ─────────────────────────────────────────────────────────────── */

.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: 0.2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: var(--secondary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ── MODAL ─────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.25);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 1rem; color: var(--primary); }

.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  line-height: 1;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); }

.modal-body {
  padding: 1.5rem;
  max-height: 55vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ── CONEXAO ITEM ─────────────────────────────────────────────────────── */

.conexao-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
}

.conexao-item:hover { border-color: var(--secondary); background: rgba(57,178,133,0.04); }
.conexao-item input[type="checkbox"] { width: auto; }
.conexao-info { flex: 1; }
.conexao-nome { font-weight: 500; font-size: 0.88rem; }
.conexao-detalhe { font-size: 0.75rem; color: var(--text-muted); }

/* ── TEMPLATE CARDS ──────────────────────────────────────────────────── */

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .6rem;
  max-height: 220px;
  overflow-y: auto;
  padding: .25rem;
}

.template-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  cursor: pointer;
  transition: all .15s;
  background: var(--white);
  position: relative;
}

.template-card:hover { border-color: var(--secondary); background: rgba(57,178,133,.04); }
.template-card.selected {
  border-color: var(--secondary);
  background: rgba(57,178,133,.08);
  box-shadow: 0 0 0 3px rgba(57,178,133,.15);
}

.template-card-nome {
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: .3rem;
}

.template-card-preview {
  font-size: .73rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.template-card .check {
  position: absolute;
  top: .5rem; right: .5rem;
  width: 18px; height: 18px;
  background: var(--secondary);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: .7rem;
}
.template-card.selected .check { display: flex; }

/* ── MODAL ENVIAR ─────────────────────────────────────────────────────── */

.modal-send-header {
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--tertiary) 100%);
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  color: var(--white);
}

.modal-send-label {
  font-size: .75rem;
  color: rgba(255,255,255,.6);
  margin-bottom: .25rem;
}

.modal-send-phone {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.modal-send-header .modal-close {
  color: rgba(255,255,255,.7);
  background: rgba(255,255,255,.1);
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  padding: 0;
}
.modal-send-header .modal-close:hover { background: rgba(255,255,255,.2); color: white; }

.send-section-title {
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .5rem;
}

.send-textarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  padding: .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .88rem;
  font-family: inherit;
  color: var(--text);
  line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}

.send-textarea:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(57,178,133,.15);
  outline: none;
}

.char-count {
  font-size: .72rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: .3rem;
}

/* ── TEMPLATE MANAGEMENT ─────────────────────────────────────────────── */

.template-list-item {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.template-list-item:last-child { border-bottom: none; }

.template-list-item-info { flex: 1; }
.template-list-nome  { font-weight: 600; font-size: .9rem; margin-bottom: .2rem; }
.template-list-texto {
  font-size: .8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── TOAST ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  z-index: 200;
  animation: toastIn .25s ease, toastOut .3s ease 2.5s forwards;
}
.toast.success { background: var(--secondary); color: white; }
.toast.error   { background: var(--danger);    color: white; }

@keyframes toastIn  { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:none; } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform:translateY(8px); } }

/* Botão enviar rápido na tabela */
.btn-wa {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .3rem .65rem;
  background: rgba(57,178,133,.12);
  color: var(--secondary);
  border: 1px solid rgba(57,178,133,.3);
  border-radius: var(--radius);
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.btn-wa:hover { background: var(--secondary); color: white; }
.btn-wa.sent  { background: rgba(57,178,133,.08); color: var(--secondary); cursor: default; opacity: .7; }

.btn-sms {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .3rem .65rem;
  background: rgba(59,130,246,.12);
  color: #3B82F6;
  border: 1px solid rgba(59,130,246,.25);
  border-radius: 6px;
  font-size: .75rem; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.btn-sms:hover { background: #3B82F6; color: white; }

/* ── MISC ─────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }
.error-msg { color: var(--danger); font-size: 0.8rem; margin-top: 0.5rem; min-height: 1.2em; }
.empty-state { padding: 3rem 2rem; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

.filters { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.pagination { padding: 1rem 1.5rem; display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }

.refresh-info { font-size: 0.72rem; color: var(--text-muted); }

code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  background: var(--bg);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: var(--tertiary);
}
