/* ============================================================
   Mailer — sistema de diseño
   Paleta: papel cálido + tinta profunda + coral (acción),
   con colores semánticos consistentes en toda la app:
   coral=acción/urgente · azul=borradores · ámbar=esperando
   verde=hecho/ok · violeta=promos · gris=neutro
   ============================================================ */

:root {
  /* superficie */
  --bg: #f5f3ef;
  --panel: #ffffff;
  --panel-soft: #faf8f5;
  --line: #e7e2d9;
  --line-strong: #d8d2c6;

  /* texto */
  --ink: #22262e;
  --ink-soft: #4b5158;
  --muted: #8a857c;

  /* marca */
  --brand: #d9552c;          /* coral Mailer: acciones principales */
  --brand-dark: #b64621;
  --brand-soft: #fdeee7;
  --brand-ink: #ffffff;
  --top: #191f29;            /* tinta de cabecera */
  --top-soft: #232b38;

  /* semánticos */
  --ok: #177e6a;      --ok-soft: #e1f1ed;
  --warn: #b3790f;    --warn-soft: #faf0da;
  --bad: #c23a3a;     --bad-soft: #fbe8e6;
  --info: #3064c9;    --info-soft: #e8eefb;
  --promo: #7d4fb3;   --promo-soft: #f1eafa;

  --pill: #efece6;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(25, 31, 41, .05), 0 4px 14px rgba(25, 31, 41, .05);
  --shadow-lift: 0 4px 10px rgba(25, 31, 41, .08), 0 12px 30px rgba(25, 31, 41, .09);
  font-size: 15px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: none; }
code { background: var(--pill); border-radius: 5px; padding: 1px 6px; font-size: .85em; }

/* ---------- cabecera ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(180deg, var(--top-soft), var(--top));
  color: #fff;
  padding: 10px 22px;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 2px 14px rgba(15, 19, 26, .28);
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 19px; letter-spacing: .2px;
  color: #fff; cursor: pointer; user-select: none;
}
.logo:hover { text-decoration: none; }
.logo .logo-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #f0824f);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; box-shadow: 0 2px 8px rgba(217, 85, 44, .45);
}
.logo span.tag { display: none; }

.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; }
.topbar nav button {
  background: transparent; border: 0; color: #b9c0cb;
  padding: 8px 13px; border-radius: 10px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s, color .15s;
}
.topbar nav button .nav-ico { font-size: 15px; opacity: .95; }
.topbar nav button:hover { background: rgba(255,255,255,.07); color: #fff; }
.topbar nav button.active { background: var(--brand); color: #fff; box-shadow: 0 2px 10px rgba(217,85,44,.35); }
.topbar .spacer { flex: 1; }
.topbar .sync-btn {
  background: rgba(255,255,255,.09); color: #fff;
  border: 1px solid rgba(255,255,255,.14);
  padding: 8px 16px; border-radius: 10px; font-weight: 500;
  transition: background .15s;
}
.topbar .sync-btn:hover { background: rgba(255,255,255,.16); }
.topbar .sync-btn:disabled { opacity: .5; cursor: wait; }

.main { max-width: 1280px; margin: 0 auto; padding: 26px 22px 70px; }

/* ---------- paneles y jerarquía ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.panel h3 { margin: 18px 0 10px; font-size: 14px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
label.field input, label.field select, label.field textarea {
  padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; font-size: 14px; color: var(--ink); font-weight: 400;
  transition: border-color .15s, box-shadow .15s;
}
label.field input:focus, label.field select:focus, label.field textarea:focus,
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; }

/* ---------- botones ---------- */
.btn {
  background: var(--brand); color: var(--brand-ink);
  border: 0; padding: 9px 18px; border-radius: 10px; font-weight: 600;
  transition: background .15s, transform .05s, box-shadow .15s;
  box-shadow: 0 1px 3px rgba(217,85,44,.3);
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #f1eee8; color: var(--ink-soft); box-shadow: none; border: 1px solid var(--line); font-weight: 500; }
.btn.secondary:hover { background: #e9e5dd; }
.btn.danger { background: var(--bad-soft); color: var(--bad); box-shadow: none; border: 1px solid #f3cdc9; }
.btn.danger:hover { background: #f6d8d5; }
.btn.ok { background: var(--ok); color: #fff; box-shadow: 0 1px 3px rgba(23,126,106,.3); }
.btn.ok:hover { background: #106958; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }

.muted { color: var(--muted); font-size: 13px; }

/* ---------- pills / estados ---------- */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--pill); color: var(--ink-soft);
  font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.5;
}
.pill.needs_reply { background: var(--brand-soft); color: var(--brand-dark); }
.pill.draft_ready { background: var(--info-soft); color: var(--info); }
.pill.waiting { background: var(--warn-soft); color: var(--warn); }
.pill.fyi { background: var(--pill); color: var(--muted); }
.pill.promo { background: var(--promo-soft); color: var(--promo); }
.pill.done, .pill.sent, .pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.new { background: #e5eef0; color: #3d6a75; }
.pill.high { background: var(--bad-soft); color: var(--bad); }
.pill.medium { background: var(--warn-soft); color: var(--warn); }
.pill.low { background: var(--pill); color: var(--muted); }
.pill.running { background: var(--info-soft); color: var(--info); }
.pill.paused, .pill.draft { background: var(--warn-soft); color: var(--warn); }
.pill.failed, .pill.canceled, .pill.error { background: var(--bad-soft); color: var(--bad); }

/* ---------- tablas ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  padding: 8px; border-bottom: 2px solid var(--line);
}
table.data td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-word; overflow-wrap: anywhere; }
table.data tr:hover td { background: var(--panel-soft); }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--top); color: #fff; padding: 12px 22px; border-radius: 12px;
  z-index: 100; box-shadow: var(--shadow-lift); max-width: 80vw; font-size: 14px;
}
.toast.error { background: var(--bad); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 40px 36px; width: 360px; text-align: center; box-shadow: var(--shadow-lift);
}
.login-box .logo-mark {
  width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--brand), #f0824f);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  box-shadow: 0 6px 18px rgba(217,85,44,.35);
}
.login-box h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
.login-box input { width: 100%; margin: 16px 0; padding: 11px 13px; border: 1px solid var(--line-strong); border-radius: 10px; }
.login-box .btn { width: 100%; padding: 11px; }

/* ---------- dashboard ---------- */
.dash-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 980px) { .dash-kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .1s;
  display: flex; flex-direction: column; gap: 6px;
}
.kpi:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.kpi .kpi-ico {
  width: 38px; height: 38px; border-radius: 11px; font-size: 18px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 4px;
}
.kpi .kpi-num { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.kpi .kpi-label { font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.kpi.coral .kpi-ico { background: var(--brand-soft); }
.kpi.coral .kpi-num { color: var(--brand-dark); }
.kpi.blue .kpi-ico { background: var(--info-soft); }
.kpi.blue .kpi-num { color: var(--info); }
.kpi.amber .kpi-ico { background: var(--warn-soft); }
.kpi.amber .kpi-num { color: var(--warn); }
.kpi.violet .kpi-ico { background: var(--promo-soft); }
.kpi.violet .kpi-num { color: var(--promo); }

.dash-cols { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .dash-cols { grid-template-columns: 1fr; } }

.dash-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px;
}
.dash-item:last-child { border-bottom: 0; }
.dash-item:hover { background: var(--panel-soft); }
.dash-item .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.dot.high { background: var(--bad); }
.dot.medium { background: var(--warn); }
.dot.low { background: var(--line-strong); }
.dash-item .di-title { font-weight: 600; font-size: 14px; }
.dash-item .di-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.progress { height: 8px; border-radius: 999px; background: var(--pill); overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), #f0824f); transition: width .3s; }
.progress.done > i { background: var(--ok); }

.banner {
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 18px;
  display: flex; gap: 12px; align-items: center; font-size: 14px; font-weight: 500;
  border: 1px solid;
}
.banner.warn { background: var(--warn-soft); border-color: #ecd9ae; color: #7c5407; }
.banner.bad { background: var(--bad-soft); border-color: #f3cdc9; color: #8f2626; }

/* ---------- inbox ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: var(--ink-soft); font-weight: 500;
  transition: all .12s;
}
.filters button:hover { border-color: var(--line-strong); background: var(--panel-soft); }
.filters button.active { background: var(--top); color: #fff; border-color: var(--top); }
.filters .count { opacity: .6; margin-left: 5px; font-weight: 600; }
.filters select, .filters input { background: var(--panel); font-size: 13px; color: var(--ink-soft); }

.thread-row {
  display: flex; gap: 14px; padding: 13px 16px 13px 13px;
  border-bottom: 1px solid var(--line); cursor: pointer; align-items: baseline;
  border-left: 3px solid transparent;
  transition: background .1s;
}
.thread-row:hover { background: var(--panel-soft); }
.thread-row.prio-high { border-left-color: var(--bad); }
.thread-row.prio-medium { border-left-color: var(--warn); }
.thread-row .from { width: 200px; flex-shrink: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.thread-row .subject { flex: 1; min-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.thread-row .subject strong { font-weight: 600; }
.thread-row .subject .reason { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: 3px; white-space: normal; line-height: 1.45; }
.thread-row .meta { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.thread-row .date { color: var(--muted); font-size: 12px; width: 78px; text-align: right; flex-shrink: 0; }

/* ---------- hilo / borrador ---------- */
.msg { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.msg .msg-head { padding: 9px 14px; background: var(--panel-soft); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.msg .msg-body { padding: 14px; white-space: pre-wrap; font-size: 14px; max-height: 380px; overflow-y: auto; line-height: 1.55; }

/* cabecera (asunto/datos) | análisis, lado a lado */
.thread-top { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .thread-top { grid-template-columns: 1fr; } }
.thread-top > .panel { margin: 0; }

/* dos columnas: original | traducción */
.bilingual { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
@media (max-width: 820px) { .bilingual { grid-template-columns: 1fr; } }
.bilingual > div { min-width: 0; }
.bilingual .col-orig { border-right: 1px solid var(--line); }
@media (max-width: 820px) { .bilingual .col-orig { border-right: 0; border-bottom: 1px solid var(--line); } }
.col-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 14px 0; }
.col-label.es { color: var(--brand-dark); }
.tr-loading { color: var(--muted); font-size: 13px; padding: 14px; font-style: italic; }
.msg.sent { border-color: #cfd9f2; }
.msg.sent .msg-head { background: var(--info-soft); }
.draft-editor textarea { width: 100%; min-height: 260px; line-height: 1.5; }
.draft-editor input[type=text] { width: 100%; }
.explain { background: var(--panel-soft); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-size: 13px; margin-top: 12px; line-height: 1.5; }
.explain ul { margin: 6px 0; padding-left: 18px; }
.warnbox { background: var(--warn-soft); border: 1px solid #ecd9ae; border-radius: 12px; padding: 12px 14px; font-size: 13px; color: #7c5407; margin: 10px 0; line-height: 1.5; }
.backlink { display: inline-block; margin-bottom: 14px; font-weight: 500; }
.backlink:hover { text-decoration: underline; }

/* ---------- drag reorder ---------- */
.drag-handle { cursor: grab; color: var(--muted); font-size: 16px; line-height: 1; user-select: none; padding: 4px; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: .45; background: var(--info-soft) !important; }

/* ---------- editor de texto (campañas) ---------- */
.rte { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.rte-toolbar {
  display: flex; gap: 2px; flex-wrap: wrap; align-items: center;
  padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--panel-soft);
}
.rte-toolbar button {
  border: 0; background: transparent; border-radius: 6px; padding: 5px 9px;
  font-size: 13.5px; color: var(--ink-soft); min-width: 30px;
}
.rte-toolbar button:hover { background: #e9e5dd; }
.rte-toolbar select { border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-size: 12.5px; background: #fff; }
.rte-toolbar .sep { width: 1px; height: 20px; background: var(--line-strong); margin: 0 5px; }
.rte-body { min-height: 260px; max-height: 520px; overflow-y: auto; padding: 14px 16px; font-size: 14px; line-height: 1.55; outline: none; }
.rte-body:focus { background: #fffdfa; }
.rte-body p { margin: 0 0 10px; }
.rte-html { width: 100%; min-height: 260px; border: 0; padding: 12px; font-family: ui-monospace, monospace; font-size: 12.5px; display: none; }
