:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1d2939;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #1f4e8c;
  --primary-hover: #183e70;
  --primary-soft: #e8eff8;
  --danger: #c93a3a;
  --success: #1e8a5a;
  --warning: #b7791f;
  --sidebar: #12263f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }

/* ---------- Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; padding: 20px 12px;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; padding: 0 10px 20px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; color: #8aa0bb; font-size: 12px; }
.brand img { display: block; height: 32px; width: auto; margin-bottom: 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: #cbd5e1; text-decoration: none;
  padding: 10px 12px; border-radius: 8px; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .spacer { flex: 1; }
.sidebar .logout { background: none; border: 0; color: #8aa0bb; cursor: pointer; text-align: left; padding: 10px 12px; font: inherit; }
.sidebar .logout:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }

/* ---------- Componentes */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 4px 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 500; margin-bottom: 6px; }
label.field > small, .help { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; border: 1px solid #d0d5dd; border-radius: 8px; padding: 9px 11px; font: inherit; color: var(--text); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; }
textarea.code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; min-height: 420px; white-space: pre; tab-size: 2; }
.checkbox { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f9fafb; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f2f4f7; color: #475467; }
.badge.draft { background: #f2f4f7; color: #475467; }
.badge.scheduled { background: #fef6e7; color: #93600a; }
.badge.sending { background: #e8eff8; color: var(--primary); }
.badge.paused { background: #fef6e7; color: #93600a; }
.badge.sent, .badge.active { background: #e7f6ee; color: var(--success); }
.badge.cancelled, .badge.failed, .badge.bounced { background: #fdecec; color: var(--danger); }

.progress { height: 6px; background: #eef1f5; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--primary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 14px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 14px; color: var(--muted); }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.choice {
  border: 2px solid var(--border); border-radius: var(--radius); padding: 18px; cursor: pointer; background: #fff; text-align: left; font: inherit; color: inherit;
}
.choice:hover { border-color: #b8c7dc; }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); }
.choice strong { display: block; margin-bottom: 4px; }
.choice span { color: var(--muted); font-size: 13px; }

.preview-frame { width: 100%; height: 640px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.list-checks { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.list-checks .checkbox { margin: 6px 0; }
.list-checks .count { color: var(--muted); margin-left: auto; font-size: 12px; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert.info { background: #eef4fb; border-color: #c9d9ee; color: #1f4e8c; }
.alert.warn { background: #fef6e7; border-color: #f4d9a6; color: #7a4f09; }
.alert.error { background: #fdecec; border-color: #f3c3c3; color: #8f2424; }
.alert.ok { background: #e7f6ee; border-color: #b9e2cb; color: #155f3e; }

.vars { display: flex; flex-wrap: wrap; gap: 6px; }
.vars code { background: #f2f4f7; padding: 3px 7px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.vars code:hover { background: var(--primary-soft); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.right { text-align: right; }
.ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 100; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 860px; }
.modal header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; }
.modal .body { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal .close { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- Toast */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1d2939; color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }

/* ---------- Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #12263f, #1f4e8c); }
.login-card { background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-logo { display: block; height: 44px; width: auto; margin: 0 0 24px; }
.login-card h1 { margin-bottom: 4px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 12px 0 4px; }
  .brand small { display: none; }
  .brand img { height: 24px; margin-bottom: 0; }
  .nav { display: flex; }
  .nav a span { display: none; }
  .sidebar .spacer { display: none; }
  .main { padding: 20px 16px 60px; }
  .grid.cols-2, .grid.cols-3, .editor-split { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
