:root {
  --bg: #eef1ec;
  --panel: #ffffff;
  --panel-2: #f7f8f4;
  --ink: #17251e;
  --muted: #68766e;
  --line: #dfe5de;
  --brand: #1d4d3e;
  --brand-2: #2f7a60;
  --accent: #d7f06a;
  --danger: #b42318;
  --warn: #9a6700;
  --ok: #1f7a3f;
  --shadow: 0 16px 45px rgba(23, 37, 30, .08);
  --radius: 18px;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: var(--sans); background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #dcebdc, transparent 45%), radial-gradient(circle at 80% 90%, #e8e3cf, transparent 40%), var(--bg); }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 34px; box-shadow: var(--shadow); }
.brand-mark { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.03em; font-size: 20px; }
.brand-mark span { color: var(--brand-2); }
.brand-mark .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px #eff7cf; }
.login-card h1 { font-size: 30px; letter-spacing: -.04em; margin: 28px 0 8px; }
.login-card p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 24px; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 700; color: #425047; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 11px 12px; outline: none; color: var(--ink); }
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(47,122,96,.12); }
.btn { border: 0; border-radius: 10px; padding: 11px 15px; font-weight: 750; font-size: 13px; background: var(--panel-2); color: var(--ink); }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.green { background: var(--accent); color: #1c2a20; }
.btn.danger { background: #fbe9e7; color: var(--danger); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 7px 10px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.login-note { font-size: 11px; color: var(--muted); margin-top: 16px; line-height: 1.5; }

/* Shell */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #14241d; color: #dce7df; padding: 22px 16px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand-mark { color: #fff; padding: 6px 10px 24px; }
.sidebar .brand-mark span { color: #cfe5d8; }
.nav-item { display: flex; align-items: center; gap: 11px; border: 0; background: transparent; color: #aebfb4; padding: 11px 12px; border-radius: 10px; text-align: left; font-weight: 650; font-size: 13px; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: #e9f4d2; color: #17251e; }
.nav-item .ico { width: 18px; text-align: center; font-size: 16px; }
.sidebar .spacer { flex: 1; }
.sidebar .independence { border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 11px; font-size: 10.5px; color: #aebfb4; line-height: 1.45; }
.sidebar .independence b { color: #d9efc1; display: block; margin-bottom: 3px; }
.sidebar .logout { color: #f1c7bd; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 34px 10px; }
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 12.5px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: #e6efe9; color: #285b48; padding: 7px 10px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.content { padding: 12px 34px 50px; max-width: 1500px; }

/* Utilities */
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgba(23,37,30,.03); }
.card-pad { padding: 20px; }
.card h2, .card h3 { margin: 0 0 5px; letter-spacing: -.03em; }
.card h2 { font-size: 18px; }
.card h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 22px 0 12px; }
.section-title h2 { margin: 0; font-size: 19px; letter-spacing: -.03em; }
.section-title p { margin: 0; color: var(--muted); font-size: 12px; }
.metric { padding: 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.metric .label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.metric .num { font-size: 32px; font-weight: 800; letter-spacing: -.05em; margin-top: 8px; }
.metric .hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
.metric.highlight { background: linear-gradient(135deg, #1d4d3e, #2c6b55); color: #fff; border-color: transparent; }
.metric.highlight .label, .metric.highlight .hint { color: #cfe0d7; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid #eef1ed; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .email { font-weight: 650; color: #243c30; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 10.5px; font-weight: 750; background: #eef1ed; color: #526157; white-space: nowrap; }
.badge.activo { background: #e6f4e8; color: var(--ok); }
.badge.riesgo { background: #fff4d6; color: var(--warn); }
.badge.invalido, .badge.baja { background: #fbe9e7; color: var(--danger); }
.badge.pendiente, .badge.desconocido { background: #e8eef8; color: #355a86; }
.badge.programada, .badge.enviada { background: #e6f4e8; color: var(--ok); }
.badge.borrador, .badge.cancelada { background: #eef1ed; color: #68766e; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.notice { border: 1px solid #e5e3c9; background: #fbf8e8; color: #5c542d; border-radius: 12px; padding: 12px 14px; font-size: 12px; line-height: 1.5; }
.notice.danger { border-color: #f2d3ce; background: #fff2f0; color: #7a2a20; }
.import-box { border: 1px dashed #b8c7bb; border-radius: 14px; padding: 14px; background: #fbfcf8; }
.import-box textarea { min-height: 100px; font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }
.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-row input[type=file] { font-size: 12px; }
.checkline { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: #4e5d54; line-height: 1.45; }
.checkline input { margin-top: 2px; }
.progress { height: 6px; border-radius: 99px; background: #e7ece6; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; width: 0; background: var(--brand-2); transition: width .3s; }
.campaign-list { display: grid; gap: 12px; }
.campaign { border: 1px solid var(--line); border-radius: 14px; padding: 16px; background: #fff; }
.campaign .title { font-weight: 750; font-size: 14px; }
.campaign .meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.campaign .actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.profile-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fbfcf8; margin-bottom: 8px; }
.profile-card b { font-size: 13px; }
.profile-card .small { margin-top: 3px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.code { background: #f2f5ef; border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

/* Dialog */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 30px 90px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(13, 24, 18, .55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 19px; letter-spacing: -.03em; }
.dialog-body { padding: 20px 22px; overflow: auto; max-height: calc(100vh - 170px); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fbfcf8; }
.icon-btn { border: 0; background: transparent; font-size: 22px; color: var(--muted); line-height: 1; }
.preview-frame { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; background: #14241d; color: #fff; border-radius: 12px; padding: 13px 16px; font-size: 13px; box-shadow: var(--shadow); max-width: min(420px, calc(100vw - 40px)); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .25s; }
.toast.show { transform: none; opacity: 1; }
.toast.error { background: #7a2a20; }

@media (max-width: 980px) {
  .app { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 16px 10px; }
  .sidebar .brand-mark { font-size: 0; padding: 4px 6px 18px; justify-content: center; }
  .sidebar .brand-mark .dot { width: 12px; height: 12px; }
  .nav-item { justify-content: center; font-size: 0; padding: 12px 6px; }
  .nav-item .ico { font-size: 18px; }
  .sidebar .independence, .sidebar .logout span { display: none; }
  .topbar, .content { padding-left: 20px; padding-right: 20px; }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .app { display: block; }
  .sidebar { position: fixed; bottom: 0; top: auto; height: auto; width: 100%; z-index: 20; flex-direction: row; justify-content: space-around; padding: 8px; gap: 0; }
  .sidebar .brand-mark, .sidebar .independence, .sidebar .logout { display: none; }
  .nav-item { flex-direction: column; gap: 3px; font-size: 9px; padding: 7px 9px; flex: 1; }
  .nav-item .ico { font-size: 16px; }
  .main { padding-bottom: 72px; }
  .topbar { padding-top: 18px; }
  .topbar h1 { font-size: 22px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .content { padding: 8px 15px 34px; }
  .metric .num { font-size: 27px; }
  .dialog-body { padding: 16px; }
  .dialog-head, .dialog-foot { padding: 14px 16px; }
}

.spam-head { display:flex; align-items:center; gap:16px; margin-bottom:14px; }
.spam-score { min-width:86px; height:86px; border-radius:22px; display:grid; place-items:center; font-size:24px; font-weight:850; letter-spacing:-.05em; background:#eef1ed; color:#68766e; }
.spam-score.good { background:#e6f4e8; color:#1f7a3f; }
.spam-score.bad { background:#fbe9e7; color:#b42318; }
.spam-score.unknown { background:#e8eef8; color:#355a86; }
.spam-checks { display:grid; gap:8px; }
.spam-line { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:10px 12px; border:1px solid var(--line); border-radius:10px; font-size:12.5px; color:#4e5d54; }
.spam-line b { color:var(--ink); text-align:right; }
.duplicate-group { border:1px solid var(--line); border-radius:12px; padding:12px; margin-bottom:10px; background:#fbfcf8; }
.duplicate-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:8px; }
.duplicate-head b { font-size:13px; color:#243c30; word-break:break-all; }
.duplicate-row { display:grid; grid-template-columns:minmax(0,1fr) auto auto; gap:10px; align-items:center; padding:7px 0; border-top:1px solid #edf1eb; font-size:12px; color:#4e5d54; }
.editor-toolbar { display:flex; align-items:center; gap:4px; flex-wrap:wrap; padding:8px; border:1px solid var(--line); border-bottom:0; border-radius:10px 10px 0 0; background:#f7f9f4; }
.editor-btn { border:1px solid transparent; background:transparent; border-radius:7px; min-width:32px; height:30px; padding:0 8px; color:#425047; font-size:12px; font-weight:700; }
.editor-btn:hover { background:#fff; border-color:var(--line); color:var(--ink); }
.editor-sep { width:1px; height:20px; background:var(--line); margin:0 4px; }
.email-editor { min-height:280px; max-height:460px; overflow:auto; padding:20px; border:1px solid var(--line); border-radius:0 0 10px 10px; background:#fff; font-family:Arial,Helvetica,sans-serif; font-size:14px; line-height:1.6; color:#17251e; }
.email-editor:focus { outline:2px solid rgba(47,122,96,.25); outline-offset:0; }
.email-editor h1 { font-size:26px; line-height:1.15; margin:0 0 12px; }
.email-editor h2 { font-size:21px; line-height:1.2; margin:0 0 10px; }
.email-editor p { margin:0 0 12px; }
.email-editor a { color:#1d4d3e; text-decoration:underline; }
.email-editor img { max-width:100%; height:auto; border-radius:8px; margin:8px 0; }
.email-editor ul,.email-editor ol { margin:0 0 12px 22px; padding:0; }
.email-editor blockquote { border-left:3px solid #b8c7bb; margin:8px 0; padding-left:12px; color:#5e6c64; }
#campaignHtml { border-radius:10px; }
.modal-backdrop { position:fixed; inset:0; z-index:1200; background:rgba(13,24,18,.55); backdrop-filter:blur(3px); }
#campaignDialog[open] { position:fixed; z-index:1201; top:50%; left:50%; transform:translate(-50%,-50%); margin:0; }
/* Los diálogos internos de TinyMCE deben quedar por encima del modal de campaña */
.tox .tox-dialog-wrap { z-index: 2000 !important; }
.tox .tox-dialog { z-index: 2001 !important; }