/* Estética agriNews (misma que el subidor de newsletters) */
:root {
  --bg: #f6f8f5;
  --panel: #ffffff;
  --ink: #373735;
  --muted: #6e6e6a;
  --line: #e2e5e1;
  --brand: #189618;
  --brand-2: #24a024;
  --brand-3: #2caf2c;
  --brand-4: #39c43c;
  --brand-txt: #137a13;
  --brand-soft: #ecf8ec;
  --out: #e4f5e4;
  --note: #fff4dc;
  --danger: #b3261e;
  --warn: #8a5a00;
  --blue: #2a7de1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(55,55,53,.04);
  font-family: "Poppins", "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-txt); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Botones e inputs */
.btn { border: 1px solid var(--line); background: #fff; padding: 9px 15px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500; text-decoration: none; color: var(--ink); transition: .15s; }
.btn:hover { border-color: var(--brand-3); color: var(--brand-txt); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-txt); border-color: var(--brand-txt); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; background: #fff; outline: none; color: var(--ink); }
.input:focus { outline: 2px solid var(--brand-3); outline-offset: -1px; border-color: var(--brand-3); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* Ojo para ver la contraseña */
.agn-ojo-w { position: relative; display: block; width: 100%; }
.agn-ojo-w input { padding-right: 52px !important; }
.agn-ojo { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; background: none; border-radius: 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; padding: 0; }
.agn-ojo:hover { color: var(--brand-txt); background: var(--brand-soft); }
.agn-ojo svg { width: 21px; height: 21px; }

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 480px; background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--brand-4); border-radius: var(--radius); padding: 36px 34px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 25px; font-weight: 700; }
.login-card .logo { display: block; height: 46px; width: auto; margin: 0 0 22px; }
.login-card .input { padding: 13px 15px; font-size: 16px; margin-bottom: 0; }
.login-card .btn.primary { width: 100%; justify-content: center; padding: 14px; font-size: 16.5px; border-radius: 10px; }
.logo-dot { display: none; }

/* Cabecera */
#app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
nav.side { background: #fff; border-top: 4px solid var(--brand-4); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 22px; padding: 10px 24px; }
nav.side .brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink); margin-right: 10px; }
nav.side .brand img { height: 32px; width: auto; display: block; }
nav.side .brand span { font-size: 15px; font-weight: 500; color: var(--muted); padding-left: 14px; border-left: 1px solid var(--line); white-space: nowrap; }
nav.side a[data-view] { display: flex; align-items: center; gap: 7px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 15px; padding: 6px 2px; border-bottom: 2px solid transparent; white-space: nowrap; }
nav.side a[data-view]:hover { color: var(--ink); }
nav.side a[data-view].active { color: var(--brand-txt); font-weight: 600; border-bottom-color: var(--brand-4); }
nav.side .spacer { flex: 1; }
nav.side .me { font-size: 13.5px; color: var(--muted); text-align: right; line-height: 1.4; }
nav.side .me #me-name { color: var(--ink); font-weight: 500; }
nav.side .me button { background: none; border: 0; color: var(--brand-txt); padding: 0; cursor: pointer; font-weight: 500; font-size: 13px; }
nav.side .me button:hover { text-decoration: underline; }
.badge { background: var(--brand); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 700; }
main { overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.page { flex: 1; overflow: auto; padding: 28px 32px; max-width: 1240px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; font-weight: 700; margin-right: auto; }
.banner { background: var(--note); color: var(--warn); border-bottom: 1px solid #f2e2b3; padding: 9px 24px; font-size: 13.5px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Chat */
.chat { display: grid; grid-template-columns: 330px 1fr 290px; height: 100%; min-height: 0; }
.chat.no-details { grid-template-columns: 330px 1fr; }
.conv-list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.conv-list .head { padding: 14px; border-bottom: 1px solid var(--line); }
.filters { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip.active { background: var(--brand-soft); border-color: var(--brand-3); color: var(--brand-txt); font-weight: 600; }
.conv-items { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #f0f1ee; cursor: pointer; }
.conv:hover { background: #f8faf8; }
.conv.active { background: var(--brand-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-txt); display: grid; place-items: center; font-weight: 700; flex: none; }
.conv .meta { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 11px; color: var(--muted); flex: none; }
.conv .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.conv .preview span:first-child { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv .tags { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 8px; border-radius: 999px; color: #fff; font-weight: 600; }
.tag button { background: none; border: 0; color: inherit; cursor: pointer; padding: 0; font-size: 13px; line-height: 1; }

.thread { display: flex; flex-direction: column; min-height: 0; background: #f0f3ef url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23dfe4dc'/%3E%3C/svg%3E"); }
.thread-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.thread-head .who { flex: 1; min-width: 0; }
.thread-head .who b { display: block; }
.messages { flex: 1; overflow-y: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 6px; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px; }
.msg { max-width: 72%; padding: 8px 10px 6px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg.in { align-self: flex-start; }
.msg.note { align-self: center; background: var(--note); font-size: 13px; max-width: 80%; }
.msg.system { align-self: center; background: rgba(255,255,255,.7); color: var(--muted); font-size: 12px; box-shadow: none; }
.msg .foot { font-size: 11px; color: var(--muted); text-align: right; margin-top: 3px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg .label { font-size: 11px; font-weight: 700; color: var(--brand-txt); margin-bottom: 3px; }
.msg img, .msg video { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 260px; }
.tick { font-size: 12px; letter-spacing: -3px; }
.tick.read { color: var(--blue); }
.tick.failed { color: var(--danger); letter-spacing: 0; }
.day-sep { align-self: center; background: rgba(255,255,255,.85); padding: 3px 10px; border-radius: 8px; font-size: 11px; color: var(--muted); margin: 8px 0; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 14px; }
.composer .tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.composer .tabs button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; }
.composer .tabs button.active { background: var(--brand-soft); color: var(--brand-txt); font-weight: 600; }
.composer.note-mode textarea { background: var(--note); }
.composer textarea { resize: none; min-height: 42px; max-height: 160px; }
.window-closed { background: #fff8e6; border: 1px solid #f2e2b3; border-radius: 8px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; font-size: 13px; }

.details { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 18px; }
.details h3 { margin: 0 0 2px; font-size: 16px; }
.details section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.details section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 70px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.ok { background: var(--brand-soft); color: var(--brand-txt); }
.pill.warn { background: #fff1d1; color: var(--warn); }
.pill.bad { background: #fde3e0; color: var(--danger); }
.pill.grey { background: #eef0ed; color: var(--muted); }

/* Tablas */
table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #fafbf9; text-transform: uppercase; letter-spacing: .05em; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click:hover td { background: #f8faf8; cursor: pointer; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* Campañas */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 12px 0; }
.stat { background: #fafbf9; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 6px; background: #eceee9; border-radius: 99px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }

/* Plantillas */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tpl { padding: 16px; }
.tpl h4 { margin: 0; font-size: 15px; word-break: break-all; }
.wa-preview { background: #e9efe6; border-radius: 10px; padding: 12px; margin-top: 10px; }
.wa-preview .msg { max-width: 100%; }
.wa-btn { display: block; text-align: center; color: var(--blue); background: #fff; border-radius: 8px; padding: 7px; margin-top: 4px; font-size: 13px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(55,55,53,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; border-top: 4px solid var(--brand-4); width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h3 { margin: 0; font-size: 17px; flex: 1; }
.modal header button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal .body { padding: 18px 20px; overflow-y: auto; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.split { display: grid; grid-template-columns: 1fr 300px; gap: 20px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }
.hint { background: #f4f7f3; border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.hint code { background: #fff; padding: 0 4px; border-radius: 4px; color: var(--ink); }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-picker label { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); padding: 3px 8px; border-radius: 999px; font-size: 12px; }
.tag-picker input { margin: 0; }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.error { background: var(--danger); }

@media (max-width: 1200px) {
  nav.side .brand span { display: none; }
  .chat { grid-template-columns: 300px 1fr; }
  .chat .details { display: none; }
}
@media (max-width: 800px) {
  nav.side { overflow-x: auto; padding: 8px 12px; gap: 14px; }
  nav.side .brand span, nav.side .spacer, nav.side .me { display: none; }
  nav.side .brand img { height: 26px; }
  .chat { grid-template-columns: 1fr; }
  .chat.has-active .conv-list { display: none; }
  .chat:not(.has-active) .thread { display: none; }
  .split, .stats { grid-template-columns: 1fr; }
}