:root {
  --bg: #e9eaec;            /* gris clarito */
  --panel: #ffffff;
  --panel2: #f4f5f7;
  --border: #d5d8dd;
  --text: #16181d;          /* negro */
  --muted: #6b7280;
  --accent: #f26522;        /* naranja Metal Design */
  --accent2: #d9550f;
  --accent-soft: rgba(242, 101, 34, .12);
  --green: #16a34a;
  --red: #dc2626;
  --blue: #2563eb;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px; /* base 14px (corrección UX #3) */
  line-height: 1.5;
}
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #f2f3f5 0%, #dcdde0 100%);
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 40px; width: 380px; text-align: center; box-shadow: 0 18px 50px rgba(0,0,0,.12);
}
.login-card .logo-img { width: 220px; margin: 0 auto 22px; display: block; }
.login-card h1 { font-size: 19px; margin-bottom: 4px; color: var(--text); }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 11px 14px; margin-bottom: 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text); font-size: 14px;
}
.login-card button {
  width: 100%; padding: 11px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--accent); color: #ffffff; font-weight: 700; font-size: 14px;
}
.login-card button:hover { background: var(--accent2); }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: #16181d; /* negro */
  border-right: 1px solid #000; padding: 20px 14px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .logo-img { width: 170px; margin-bottom: 22px; margin-left: 4px; filter: brightness(0) invert(1); opacity: .95; }
.sidebar .brand { font-weight: 700; font-size: 15px; line-height: 1.25; margin-bottom: 24px; color: #fff; display: none; }
.sidebar .brand span { color: var(--accent); font-weight: 600; font-size: 13px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav button {
  background: none; border: none; color: #a7adb8; text-align: left; padding: 10px 12px;
  border-radius: 8px; cursor: pointer; font-size: 14px; transition: all .15s;
}
.sidebar nav button:hover { background: #23262d; color: #fff; }
.sidebar nav button.active { background: var(--accent); color: #fff; font-weight: 600; }
.logout { background: none; border: 1px solid #33373f; color: #a7adb8; padding: 9px; border-radius: 8px; cursor: pointer; }
.logout:hover { color: var(--red); border-color: var(--red); }

#main { flex: 1; padding: 28px 32px; overflow-x: auto; }
.view h2 { font-size: 22px; margin-bottom: 4px; }
.view .view-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

/* ---------- Cards / grids ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.card .num { font-size: 28px; font-weight: 800; color: var(--accent); }
.card .lbl { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card.wide { grid-column: span 2; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.panel h3 { font-size: 15px; margin-bottom: 12px; color: var(--accent); }
.panel .hint { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td { max-width: 340px; word-break: break-word; }
tr:hover td { background: var(--panel2); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge.green { background: rgba(22,163,74,.12); color: var(--green); }
.badge.red { background: rgba(220,38,38,.12); color: var(--red); }
.badge.blue { background: rgba(37,99,235,.12); color: var(--blue); }
.badge.gold { background: var(--accent-soft); color: var(--accent2); }
.badge.gray { background: rgba(107,114,128,.14); color: var(--muted); }

/* ---------- Forms ---------- */
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 13.5px; font-family: inherit;
}
textarea { font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 12.5px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.form-row > div { flex: 1; min-width: 180px; }

.btn {
  background: var(--accent); color: #fff; border: none; padding: 10px 18px; border-radius: 8px;
  font-weight: 700; font-size: 14px; cursor: pointer; transition: all .15s;
  min-height: 40px; /* botones ≥ 36-40px (corrección UX #3) */
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--accent2); }
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent2); }
.btn.danger { background: rgba(220,38,38,.1); color: var(--red); border: 1px solid rgba(220,38,38,.35); }
.btn.small { padding: 5px 10px; font-size: 12.5px; min-height: 34px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Dropdown "Más acciones" ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 240px; padding: 6px; overflow: hidden;
}
.menu-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 10px 12px; font-size: 13.5px; border-radius: 7px; cursor: pointer; color: var(--text);
}
.menu-item:hover { background: var(--panel2); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: rgba(220,38,38,.08); }

/* ---------- Modal (transferencia, confirmaciones) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--panel); border-radius: 14px; padding: 22px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { margin-bottom: 6px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.modal select, .modal input[type="text"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--panel2); color: var(--text);
}

/* ---------- Notas internas ---------- */
.note-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-top: 6px; background: var(--panel2); }
.note-body { font-size: 13px; margin-top: 2px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }

/* ---------- Chat simulator ---------- */
.sim-layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
.sim-chatlist { max-height: 420px; overflow-y: auto; }
.sim-chatlist .sim-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px;
}
.sim-chatlist .sim-item:hover { background: var(--panel2); }
.sim-chatlist .sim-item.active { border-color: var(--accent); background: var(--accent-soft); }
.sim-item .n { font-weight: 600; font-size: 13.5px; }
.sim-item .p { color: var(--muted); font-size: 11.5px; }
.chat-window {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  height: 460px; display: flex; flex-direction: column; overflow: hidden;
}
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-head .n { font-weight: 700; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: #fbfbfc; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot { align-self: flex-start; background: var(--panel2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg .tag { display: block; font-size: 10.5px; opacity: .7; margin-bottom: 3px; font-weight: 600; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }

.decision-box {
  margin-top: 16px; background: #16181d; border: 1px solid #000; border-radius: 10px;
  padding: 14px; font-size: 12.5px; font-family: monospace; line-height: 1.55; overflow-x: auto; color: #e6e9ef;
}
.decision-box pre { white-space: pre-wrap; word-break: break-word; }
.decision-box .k { color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: #16181d; border: 1px solid var(--accent);
  color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13.5px; z-index: 999;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.err { border-color: var(--red); }

code { background: var(--panel2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }

.mono { font-family: 'Cascadia Code', monospace; font-size: 12px; }

/* ---------- Bandeja de conversaciones ---------- */
.chips-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
  padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.unread-badge {
  display: inline-block; min-width: 18px; height: 18px; line-height: 18px; text-align: center;
  background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; margin-left: 6px;
}
.sim-item.has-unread .n { font-weight: 700; }
.empty-state { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty-icon { font-size: 40px; margin-bottom: 10px; }
.conv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.next-step {
  background: var(--accent-soft); border: 1px solid rgba(242,101,34,.25); color: var(--accent2);
  padding: 9px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 10px;
}
.lead-strip { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }

/* ---------- Usuario ---------- */
.user-chip {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 8px; font-size: 12.5px; color: var(--text);
}
.user-chip .u-name { font-weight: 700; }
.user-chip .u-role { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; z-index: 500; padding: 24px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: 100%; max-width: 640px; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,.2);
}
.modal h3 { margin-bottom: 16px; font-size: 16px; color: var(--accent); }

/* ---------- Dashboard operativo ---------- */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.status-item { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status-item .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; width: 100%; }
.status-item.err { border-color: rgba(220,38,38,.4); }

/* ---------- Tabla contactos ---------- */
.row-sel td { background: var(--accent-soft); }
tr.row-sel:hover td { background: var(--accent-soft); }

/* ---------- QR ---------- */
.qr { font-family: 'Cascadia Code', monospace; font-size: 10px; line-height: 1.05; background: #fff; color: #000; padding: 14px; border-radius: 10px; display: inline-block; max-width: 100%; overflow: auto; }
