:root {
  --bg: #0b0e14;
  --bg-soft: #0e1219;
  --bg-panel: #12161f;
  --bg-panel-2: #171c27;
  --bg-raised: #1b202c;
  --border: rgba(255, 255, 255, 0.07);
  --border-soft: rgba(255, 255, 255, 0.045);
  --text: #eef1f8;
  --text-dim: #8992a8;
  --text-faint: #5b6478;
  --accent: #6d8dff;
  --accent-2: #34d399;
  --accent-soft: rgba(109, 141, 255, 0.12);
  --danger: #f5697a;
  --danger-soft: rgba(245, 105, 122, 0.12);
  --warn: #f5b04a;
  --warn-soft: rgba(245, 176, 74, 0.12);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.45), 0 2px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(109, 141, 255, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, rgba(52, 211, 153, 0.05), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
}

::selection { background: rgba(109, 141, 255, 0.35); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 20px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); background-clip: padding-box; }

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 22px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: white;
  background: linear-gradient(135deg, var(--accent), #8a6dff);
  box-shadow: 0 4px 14px -4px rgba(109, 141, 255, 0.6);
  flex-shrink: 0;
}
.brand-text {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}
.brand-text b { color: var(--text); font-weight: 700; }

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

.sidebar a {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.sidebar a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }

.sidebar a:hover { background: rgba(255, 255, 255, 0.045); color: var(--text); }
.sidebar a.active {
  background: var(--accent-soft);
  color: #b7c6ff;
  font-weight: 600;
}
.sidebar a.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 4px;
  border-top: 1px solid var(--border-soft);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
  flex-shrink: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  padding: 6px;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-faint); }

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s var(--ease), color 0.12s var(--ease), border-color 0.12s var(--ease);
}
.logout-btn svg { width: 15px; height: 15px; }
.logout-btn:hover { background: var(--danger-soft); color: #ff9aa6; border-color: rgba(245, 105, 122, 0.3); }

/* ---------- Content ---------- */
.content {
  flex: 1;
  padding: 32px 40px 56px;
  max-width: 1400px;
  overflow-x: auto;
}

h1 { font-size: 21px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 14.5px; font-weight: 700; margin: 0 0 14px; letter-spacing: -0.005em; }
.subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
}
th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
tbody tr { transition: background 0.12s var(--ease); }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, #7c98ff, var(--accent));
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 6px 16px -6px rgba(109, 141, 255, 0.55);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease), filter 0.12s var(--ease);
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset, 0 10px 22px -6px rgba(109, 141, 255, 0.6); }
.btn:active { transform: translateY(0); }

.btn.secondary {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}
.btn.secondary:hover { background: #212736; box-shadow: none; }

.btn.danger { background: linear-gradient(180deg, #ff8393, var(--danger)); box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset, 0 6px 16px -6px rgba(245, 105, 122, 0.5); }
.btn.success { background: linear-gradient(180deg, #4fe3ab, var(--accent-2)); box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset, 0 6px 16px -6px rgba(52, 211, 153, 0.5); }
.btn.small { padding: 6px 11px; font-size: 12px; border-radius: 7px; }

/* ---------- Forms ---------- */
input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(109, 141, 255, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238992a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px; }

label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
label:first-child { margin-top: 0; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.form-grid .full { grid-column: 1 / -1; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-direction: row;
  text-transform: none;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  margin-top: 16px;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.sms { background: var(--accent-soft); color: #a9bbff; }
.badge.whatsapp { background: rgba(52, 211, 153, 0.14); color: #6fe8b9; }

.flash {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: #6fe8b9;
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 13.5px;
}
.flash.error {
  background: var(--danger-soft);
  border-color: rgba(245, 105, 122, 0.35);
  color: #ff9aa6;
}

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

/* ---------- Kanban ---------- */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(280px, 1fr));
  gap: 20px;
  align-items: start;
}
.kanban-col {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 14px;
  min-height: 220px;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.kanban-col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px 14px;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.kanban-col-header .count {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-weight: 600;
}
.kanban-cards { display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.kanban-card {
  background: linear-gradient(180deg, var(--bg-raised), var(--bg-panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  cursor: grab;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}
.kanban-card:hover { border-color: rgba(109, 141, 255, 0.4); transform: translateY(-2px); box-shadow: var(--shadow); }
.kanban-card.dragging { opacity: 0.35; }
.kanban-card .card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
  gap: 8px;
}
.kanban-card .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kanban-card .time { color: var(--text-faint); font-size: 11px; margin-top: 8px; }
.kanban-card .preview {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.45;
}
.kanban-col.drop-target { border-color: rgba(109, 141, 255, 0.5); background: var(--accent-soft); }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 13, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.15s var(--ease);
}
.modal-overlay.open { display: flex; }
.modal {
  background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.97) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-close {
  float: right;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.modal-close:hover { background: var(--danger-soft); color: #ff9aa6; }

.thread-msg {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 11px 13px;
  margin: 9px 0;
  font-size: 13px;
  line-height: 1.5;
}
.thread-msg .meta { color: var(--text-faint); font-size: 11px; margin-bottom: 5px; font-weight: 600; letter-spacing: 0.02em; }
.thread-msg.outgoing { border-left: 3px solid var(--accent-2); }
.thread-msg.incoming { border-left: 3px solid var(--accent); }

.helptext { color: var(--text-dim); font-size: 12.5px; margin-top: 6px; line-height: 1.5; }
code.inline {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12px;
  color: #a9bbff;
}
.webhook-url {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-top: 8px;
  word-break: break-all;
  color: #a9bbff;
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 48px 20px;
  font-size: 13.5px;
}

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.tabs a {
  padding: 10px 16px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s var(--ease), border-color 0.12s var(--ease);
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: #b7c6ff; border-color: var(--accent); }

.status-pill { padding: 3px 10px; border-radius: 20px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.status-pill.borrador { background: rgba(137, 146, 168, 0.14); color: var(--text-dim); }
.status-pill.enviado { background: rgba(52, 211, 153, 0.14); color: #6fe8b9; }
.status-pill.enviando { background: var(--warn-soft); color: var(--warn); }
.status-pill.error { background: var(--danger-soft); color: #ff9aa6; }

/* ---------- Auth pages ---------- */
.auth-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(109, 141, 255, 0.1), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(52, 211, 153, 0.06), transparent 55%),
    var(--bg);
}
.auth-wrap { width: 100%; padding: 24px; }
.auth-card {
  max-width: 380px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 30px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { padding: 0 0 22px; }
.auth-card h1 { text-align: left; }
.auth-footnote { text-align: center; margin-top: 18px; }
.auth-footnote a { color: var(--accent); text-decoration: none; }
.auth-footnote a:hover { text-decoration: underline; }
