@import url('https://fonts.bunny.net/css?family=inter:400,500,600,700,800');

:root {
  /* Marca (verde WhatsApp) sobre tema oscuro */
  --brand-500:#00a884; --brand-600:#00a884; --brand-700:#06cf9c;
  --brand-100:rgba(6,207,156,.15); --brand-tint-text:#06cf9c;
  --canvas:#0b141a; --surface:#111b21; --surface-2:#1b2730;
  --text-900:#e9edef; --text-800:#e9edef; --text-700:#d1d7db; --text-600:#aebac1;
  --muted:#8696a0; --muted-400:#667781;
  --border:#24333d; --border-300:#2f4450; --fill:#1b2730;
  --danger:#f15c6d; --danger-bg:rgba(241,92,109,.15); --danger-700:#f15c6d;
  --ok:#06cf9c; --ok-bg:rgba(6,207,156,.15); --ok-700:#06cf9c;
  --warn:#f0b429; --warn-bg:rgba(240,180,41,.15);
  --radius:12px; --radius-lg:16px;
  --shadow-soft:0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--text-800);
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; font-feature-settings:'cv02','cv03','cv04','cv11';
}
.ico-svg { flex-shrink: 0; vertical-align: -0.18em; }
[hidden] { display: none !important; }
a { color: var(--brand-700); }

/* ===== Botones ===== */
button {
  cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600;
  border-radius: var(--radius); padding: 9px 16px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-700);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s, border-color .15s, filter .15s;
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--brand-600); border-color: var(--brand-600); color: #04231b; }
button.primary:hover { background: var(--brand-700); filter: none; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: var(--border); }
button.danger:hover { background: var(--danger-bg); filter: none; }
button.icon { padding: 7px; border: none; background: transparent; color: var(--muted); }
button.icon:hover { background: var(--fill); color: var(--text-700); filter: none; }
button.sm { padding: 6px 10px; font-size: 13px; }

/* ===== Inputs ===== */
input, select {
  font-family: inherit; font-size: 14px; width: 100%;
  background: var(--surface-2); color: var(--text-800);
  border: 1px solid var(--border-300); border-radius: var(--radius);
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }
label { font-size: 13px; font-weight: 500; color: var(--text-700); }
.hint { color: var(--muted); font-size: 12px; }
::placeholder { color: var(--muted-400); }

/* ===== LOGIN (split screen) ===== */
.login { position: fixed; inset: 0; display: flex; background: var(--surface); z-index: 100; }
.login-brand {
  width: 45%; padding: 48px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #00a884, #075e54 60%, #0b3b32);
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-brand .circle { position: absolute; border-radius: 50%; background: rgba(255,255,255,.08); }
.login-brand .c1 { width: 380px; height: 380px; right: -120px; top: -120px; }
.login-brand .c2 { width: 260px; height: 260px; left: -90px; bottom: -80px; background: rgba(255,255,255,.05); }
.login-brand .logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; position: relative; }
.login-brand h1 { font-size: 34px; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 14px; position: relative; }
.login-brand p { color: rgba(255,255,255,.85); position: relative; margin: 0; max-width: 30ch; }
.login-brand .foot { color: rgba(255,255,255,.65); font-size: 12px; position: relative; }
.login-form { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--canvas); }
.login-card { width: 100%; max-width: 360px; }
.login-card h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; color: var(--text-900); margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; }
.login-card .field { margin-bottom: 18px; }
.login-card label { display: block; margin-bottom: 6px; }
.login-card button { width: 100%; padding: 12px; font-size: 15px; }
.login-foot { text-align: center; color: var(--muted-400); font-size: 12px; margin-top: 22px; }
@media (max-width: 820px) { .login-brand { display: none; } }

.alert-err { background: var(--danger-bg); color: var(--danger-700); border: 1px solid rgba(241,92,109,.4); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 16px; }

/* ===== Header ===== */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 62px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand .mark {
  width: 38px; height: 38px; border-radius: 11px; color: #04231b;
  background: linear-gradient(135deg, #06cf9c, #00a884);
  display: flex; align-items: center; justify-content: center;
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 800; color: var(--text-900); letter-spacing: -.01em; }
.brand .tag { margin: 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted-400); }
.dot.on { background: var(--ok); } .dot.off { background: var(--danger); }

/* User menu */
.usermenu { position: relative; }
.usermenu-btn { display: flex; align-items: center; gap: 9px; padding: 5px 8px 5px 5px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-100); color: var(--brand-tint-text); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.usermenu-btn .uname { font-size: 14px; font-weight: 600; color: var(--text-700); }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); padding: 6px; z-index: 40;
}
.dropdown .dd-head { padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown .dd-head .n { font-weight: 600; color: var(--text-900); font-size: 14px; }
.dropdown .dd-head .e { font-size: 12px; color: var(--muted); }
.dropdown button { width: 100%; justify-content: flex-start; border: none; background: transparent; font-weight: 500; color: var(--text-700); padding: 9px 10px; }
.dropdown button:hover { background: var(--fill); filter: none; }
.chip-role { display: inline-block; margin-top: 8px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; text-transform: capitalize; }
.chip-role.admin { background: var(--danger-bg); color: var(--danger-700); }
.chip-role.user { background: var(--brand-100); color: var(--brand-tint-text); }

/* Impersonation banner */
.imp-banner {
  background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid rgba(240,180,41,.4);
  padding: 8px 22px; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 12px;
}
.imp-banner button { padding: 5px 12px; font-size: 13px; }

/* ===== Main ===== */
main { max-width: 1120px; margin: 0 auto; padding: 22px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar-right { display: flex; align-items: center; gap: 14px; }
.msg { min-height: 18px; margin: 8px 0 16px; font-size: 13px; }
.msg.err { color: var(--danger); } .msg.ok { color: var(--ok-700); }

/* Lightbox (foto en grande) */
.clickable { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }

/* Toast (por encima de modales) */
.toast {
  position: fixed; top: 18px; right: 18px; z-index: 200; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--muted);
  border-radius: 12px; padding: 12px 16px; font-size: 14px; color: var(--text-800);
  box-shadow: var(--shadow-soft); animation: toast-in .18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card-empty { text-align: center; color: var(--muted); padding: 44px; background: var(--surface); border: 1px dashed var(--border-300); border-radius: var(--radius-lg); }

/* Tarjeta de monitoreo */
.contact {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-soft);
  display: flex; flex-direction: column; gap: 12px;
}
.plat { position: absolute; top: 12px; right: 14px; font-size: 10px; font-weight: 700; letter-spacing: .3px;
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; background: var(--fill); color: var(--muted); }
.plat.wa { color: var(--ok-700); background: var(--ok-bg); }
.plat.ig { color: #c07be0; background: rgba(192,123,224,.15); }
.contact-head { display: flex; gap: 12px; align-items: center; }
.contact .cavatar { width: 58px; height: 58px; border-radius: 50%; background: var(--fill) center/cover no-repeat;
  border: 2px solid var(--border); flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--muted-400); }
.contact-head .info { flex: 1; min-width: 0; }
.contact-head .name { font-weight: 700; font-size: 15px; color: var(--text-900); }
.contact-head .num { color: var(--muted); font-size: 12px; }
.presence-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--fill); color: var(--muted); white-space: nowrap; }
.presence-badge.online { background: var(--ok-bg); color: var(--ok-700); }
.presence-badge.typing { background: var(--warn-bg); color: var(--warn); }
.meta { font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.meta .line { display: flex; gap: 8px; }
.meta .k { color: var(--muted); min-width: 68px; }
.meta .v { color: var(--text-800); word-break: break-word; }
.err-text { color: var(--warn) !important; }
.contact-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.changes-count { font-size: 12px; color: var(--muted); }

/* QR card */
.qr-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; text-align: center; box-shadow: var(--shadow-soft); margin-bottom: 16px; }
.qr-card h2 { margin: 0 0 6px; font-size: 17px; color: var(--text-900); }
.qr-card p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.qr-card img { width: 240px; height: 240px; border-radius: 12px; background: #fff; padding: 8px; }

/* Presets/chips ajustes */
.settings { display: flex; flex-direction: column; gap: 14px; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 12px; font-size: 13px; border-radius: 999px; border: 1px solid var(--border-300); background: var(--surface-2); color: var(--text-700); }
.chip.active { background: var(--brand-600); border-color: var(--brand-600); color: #04231b; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: auto; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#jitter-wrap.off { opacity: .4; pointer-events: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.sep { border: none; border-top: 1px solid var(--border); margin: 2px 0; }

/* ===== Tabla usuarios ===== */
.table-wrap { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: var(--fill); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px 16px; font-weight: 600; }
tbody td { padding: 12px 16px; border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--fill); }
.u-cell { display: flex; align-items: center; gap: 10px; }
.actions-cell { display: flex; gap: 4px; justify-content: flex-end; }

/* ===== Modales ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); width: min(640px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.modal-box.wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; color: var(--text-900); }
.modal-content { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.add-block { display: flex; flex-direction: column; gap: 10px; }
.add-block .primary { align-self: flex-start; }

/* Timeline historial */
.timeline { overflow-y: auto; padding: 8px 20px 16px; }
.event { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.event:last-child { border: none; }
.event .ico { width: 26px; color: var(--brand-700); padding-top: 2px; display: flex; justify-content: center; }
.event .etype { font-weight: 600; font-size: 14px; color: var(--text-900); }
.event .edesc { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.event .etime { color: var(--muted-400); font-size: 11px; margin-top: 4px; }
.event .pics { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.event .pics img { width: 54px; height: 54px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.event .arrow { color: var(--muted-400); }
