:root {
  --wa-green: #25d366;
  --wa-teal: #075e54;
  --wa-teal-2: #128c7e;
  --bg: #f1f3f6;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e3e8ef;
  --sidebar: #0f1b2d;
  --sidebar-ink: #c7d2e0;
  --sidebar-active: #15324f;
  --amber-bg: #fef3c7; --amber-ink: #92400e;
  --red-bg: #fee2e2; --red-ink: #b91c1c;
  --green-bg: #dcfce7; --green-ink: #15803d;
  --blue-bg: #dbeafe; --blue-ink: #1d4ed8;
  --gray-bg: #eef1f5; --gray-ink: #64748b;
  --purple-bg: #ede9fe; --purple-ink: #6d28d9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--wa-green), var(--wa-teal-2));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px;
}
.brand .name { font-weight: 700; color: #fff; font-size: 16px; letter-spacing: .2px; }
.brand .sub { font-size: 11px; color: #6b7f99; margin-top: 1px; }

.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: var(--sidebar-ink); cursor: pointer; font-weight: 500; user-select: none;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #16273d; color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; opacity: .9; }
.nav-item.soon { opacity: .5; cursor: default; }
.nav-item.soon:hover { background: transparent; color: var(--sidebar-ink); }
.nav-tag { margin-left: auto; font-size: 10px; background: #1e3a5f; padding: 2px 6px; border-radius: 6px; }
.sidebar-foot { margin-top: auto; }
.back-btn {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 9px;
  color: var(--sidebar-ink); cursor: pointer; font-weight: 500; border: 1px solid #1e3147;
  text-decoration: none;
}
.back-btn:hover { background: #16273d; color: #fff; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 28px; gap: 16px;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.content { padding: 26px 28px; overflow-y: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 9px;
  font-weight: 600; font-size: 13.5px; border: 1px solid transparent; cursor: pointer;
  transition: filter .15s, background .15s, box-shadow .15s; font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary:disabled { background: #cbd5e1; color: #fff; box-shadow: none; text-shadow: none; opacity: 1; }
.btn-primary { background: var(--wa-green); color: #ffffff; box-shadow: var(--shadow); text-shadow: 0 1px 0 rgba(0,0,0,.14); }
.btn-primary:not(:disabled):hover { filter: brightness(.96); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #f8fafc; }
.btn-danger { background: #fff; color: var(--red-ink); border-color: #f3c0c0; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- Cards & forms ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card:has(table.tpl) { overflow-x: auto; }
.section { padding: 20px 22px; }
.section + .section { border-top: 1px solid var(--line); }
.section-title { font-weight: 700; font-size: 14.5px; margin: 0 0 4px; }
.section-hint { color: var(--muted); font-size: 12.5px; margin: 0 0 16px; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
label.lbl { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.req { color: #ef4444; }
input[type=text], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-family: inherit; font-size: 14px; color: var(--ink); background: #fff; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--wa-green); box-shadow: 0 0 0 3px rgba(37,211,102,.15);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.counter { float: right; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.counter.over { color: #ef4444; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.help { font-size: 12px; color: var(--muted); margin-top: 5px; }

.create-grid { display: grid; grid-template-columns: minmax(0,1fr) 380px; gap: 22px; align-items: start; }
.preview-col { position: sticky; top: 90px; }

/* ---------- Category boxes ---------- */
.cat-box { padding: 11px 13px; border-radius: 9px; font-size: 12.5px; margin-top: 9px; line-height: 1.45; }
.cat-utility { background: #eff4ff; color: #1d4ed8; border: 1px solid #c7d2fe; }
.cat-marketing { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.cat-auth { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }

/* ---------- Variable chips / examples ---------- */
.var-add { float: right; }
.examples { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.example-row { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 10px; }
.example-row .vk { font-weight: 700; color: var(--wa-teal-2); font-size: 13px; text-align: center; }

/* ---------- Issues ---------- */
.issues { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.issue { padding: 10px 13px; border-radius: 9px; font-size: 12.5px; line-height: 1.4; border: 1px solid; }
.issue.BLOCK { background: var(--red-bg); color: var(--red-ink); border-color: #f3c0c0; }
.issue.WARNING { background: var(--amber-bg); color: var(--amber-ink); border-color: #fde68a; }
.issue.CONFIRM { background: #f5f3ff; color: var(--purple-ink); border-color: #ddd6fe; }

/* ---------- WhatsApp preview ---------- */
.wa-preview { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.wa-head { background: var(--wa-teal-2); color: #fff; padding: 12px 16px; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.wa-body {
  background: #e5ddd5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='%23d8cfc4' fill-opacity='0.4'%3E%3Ccircle cx='15' cy='15' r='1.5'/%3E%3Ccircle cx='45' cy='35' r='1.5'/%3E%3C/g%3E%3C/svg%3E");
  padding: 18px 14px; min-height: 230px;
}
.bubble {
  background: #fff; border-radius: 10px; padding: 8px 10px 6px; max-width: 87%;
  box-shadow: 0 1px 1px rgba(0,0,0,.13); position: relative; font-size: 13.5px; line-height: 1.45;
}
.bubble::before {
  content: ''; position: absolute; left: -7px; top: 0; width: 0; height: 0;
  border-top: 8px solid #fff; border-left: 8px solid transparent;
}
.bubble .b-header { font-weight: 700; margin-bottom: 4px; }
.bubble .b-media {
  background: #cfd8dc; border-radius: 7px; height: 120px; margin-bottom: 7px;
  display: grid; place-items: center; color: #607d8b; font-size: 12px; font-weight: 600;
}
.bubble .b-body { white-space: pre-wrap; word-break: break-word; }
.bubble .b-footer { color: #667781; font-size: 11.5px; margin-top: 5px; }
.bubble .b-time { font-size: 10.5px; color: #8a9aa5; text-align: right; margin-top: 2px; }
.bubble .b-btn { border-top: 1px solid #e9edef; margin: 6px -10px 0; padding: 7px 0 2px; text-align: center; color: #027eb5; font-weight: 600; font-size: 13px; }
.var-token { color: var(--wa-teal-2); background: #e7f7ee; border-radius: 4px; padding: 0 3px; font-weight: 600; }

/* ---------- Channel selector ---------- */
.chan-card { border: 1px solid var(--line); border-radius: 10px; padding: 13px 14px; margin-top: 14px; }
.chan-title { font-weight: 700; font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 7px; }
.chan-item { display: flex; align-items: center; gap: 10px; padding: 7px 4px; cursor: pointer; }
.chan-item input { width: 17px; height: 17px; accent-color: var(--wa-green); }
.chan-item .cn { font-weight: 600; }
.chan-item .cp { color: var(--muted); font-size: 12px; }
.dup-note { font-size: 11.5px; color: var(--muted); margin-top: 8px; line-height: 1.4; }

/* ---------- Botones editor ---------- */
.btns-editor { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.btn-row { display: flex; gap: 8px; align-items: center; }
.btn-row input, .btn-row select { margin: 0; }
.btn-row > input[type=text] { flex: 1 1 auto; min-width: 0; }
.btn-row > select, .btn-row > .btn-sm { flex: 0 0 auto; }

/* ---------- Table / coverage ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar .search { flex: 1; max-width: 380px; }
table.tpl { width: 100%; border-collapse: collapse; background: #fff; }
.tpl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.tpl td { padding: 16px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tpl .t-prev { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tpl tr:last-child td { border-bottom: none; }
.tpl .t-name { font-weight: 700; font-family: ui-monospace, monospace; font-size: 13px; }
.tpl .t-prev { color: var(--muted); font-size: 12.5px; max-width: 240px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge.cat-MARKETING { background: var(--purple-bg); color: var(--purple-ink); }
.badge.cat-UTILITY { background: var(--blue-bg); color: var(--blue-ink); }
.badge.cat-AUTHENTICATION { background: #fff4e5; color: #9a5b00; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip.APPROVED { background: var(--green-bg); color: var(--green-ink); } .chip.APPROVED .dot { background: var(--green-ink); }
.chip.PENDING { background: var(--amber-bg); color: var(--amber-ink); } .chip.PENDING .dot { background: var(--amber-ink); }
.chip.REJECTED { background: var(--red-bg); color: var(--red-ink); } .chip.REJECTED .dot { background: var(--red-ink); }
.chip.NO_EXISTE { background: var(--gray-bg); color: var(--gray-ink); } .chip.NO_EXISTE .dot { background: #94a3b8; }
.chip.PAUSED { background: var(--purple-bg); color: var(--purple-ink); } .chip.PAUSED .dot { background: var(--purple-ink); }
.chip.sending { background: var(--blue-bg); color: var(--blue-ink); } .chip.sending .dot { background: var(--blue-ink); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.uuid { font-family: ui-monospace, monospace; font-size: 10px; color: var(--muted); opacity: .7; margin-top: 3px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; padding: 1px 4px; border-radius: 5px; }
.uuid:hover { opacity: 1; color: var(--wa-teal-2); background: #e7f7ee; }
.uuid .copy-ico { font-size: 10px; opacity: .55; }
.actions-cell { position: relative; text-align: right; white-space: nowrap; }
.kebab { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--muted); padding: 4px 9px; border-radius: 7px; line-height: 1; }
.kebab:hover { background: var(--gray-bg); color: var(--ink); }
.actions-menu { position: absolute; right: 12px; top: 40px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 30; min-width: 150px; overflow: hidden; }
.action-item { display: flex; align-items: center; gap: 9px; padding: 11px 14px; cursor: pointer; font-size: 13.5px; font-weight: 500; }
.action-item:hover { background: var(--gray-bg); }
.action-item.danger { color: var(--red-ink); }
.action-item.danger:hover { background: var(--red-bg); }
.cov { font-weight: 700; font-size: 12px; padding: 3px 10px; border-radius: 20px; display: inline-block; }
.cov.full { color: var(--green-ink); background: var(--green-bg); } .cov.partial { color: var(--amber-ink); background: var(--amber-bg); }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(0,0,0,.15); border-top-color: var(--wa-teal-2); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 24px; right: 24px; background: #0f1b2d; color: #fff; padding: 13px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; z-index: 50; max-width: 360px; }
.toast.err { background: #7f1d1d; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,27,45,.55); display: grid; place-items: center; z-index: 40; padding: 20px; }
/* 2026-07-07 (reporte de Marco): un modal más alto que la pantalla quedaba CORTADO sin barra de
   desplazamiento (caso Ajustes con la doble key). El cuerpo scrollea; cabecera y pie quedan fijos. */
.modal { background: #fff; border-radius: 14px; max-width: 480px; width: 100%; box-shadow: var(--shadow-lg); overflow: hidden; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal-head { padding: 18px 22px; font-weight: 700; font-size: 16px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.modal-body { padding: 20px 22px; line-height: 1.5; font-size: 13.5px; color: #334155; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { padding: 16px 22px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); flex-shrink: 0; }
.progress-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.progress-row:last-child { border-bottom: none; }
.progress-row .pn { font-weight: 600; flex: 1; }

/* Costos (modal movido al panel principal): clases que originalmente viven en agents.css */
.tool-item { display: flex; gap: 11px; align-items: flex-start; padding: 12px 13px; border: 1px solid var(--line); border-radius: 11px; margin-bottom: 9px; background: var(--panel); max-width: 720px; }
.tool-item:hover { border-color: #cbd5e1; background: #f8fafc; }
.tool-item .ti-name { font-weight: 600; font-size: 13.5px; font-family: ui-monospace, monospace; }
.tool-item .ti-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.sec-eyebrow { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px; }
.sec-eyebrow:first-child { margin-top: 0; }
