* { box-sizing: border-box; }
:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --side: #0f172a;
  --side-2: #1e293b;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a; --success-soft: #dcfce7;
  --warning: #d97706; --warning-soft: #fef3c7;
  --danger: #dc2626; --danger-soft: #fee2e2;
  --primary-soft: #e0ecff;
}
html, body { height: 100%; margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
input, textarea, select { width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 84px; }
button { cursor: pointer; font-family: inherit; border: 0; border-radius: 9px; padding: 10px 16px; font-size: 14px; font-weight: 600; background: var(--primary); color: #fff; }
button:active { transform: translateY(1px); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); padding: 6px 12px; font-weight: 500; }
.icon-btn { background: transparent; color: var(--muted); padding: 4px 8px; font-size: 16px; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; font-size: 14px; }
code { background: #eef2ff; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* Login */
.login { height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a, #1e3a8a); }
.login-card { background: #fff; padding: 30px; border-radius: 16px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.login-brand .logo { width: 46px; height: 46px; border-radius: 12px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.login-brand b { display: block; font-size: 16px; }
.login-brand span { font-size: 12px; color: var(--muted); }
.login-card button { width: 100%; margin-top: 16px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.login-help { font-size: 11px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

/* App shell */
.app { height: 100%; display: grid; grid-template-columns: 220px 1fr; }
.sidebar { background: var(--side); color: #cbd5e1; display: flex; flex-direction: column; }
.side-brand { padding: 20px 20px 16px; font-weight: 800; font-size: 18px; color: #fff; }
.side-brand span { font-weight: 400; font-size: 13px; color: #94a3b8; }
.side-nav { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.side-nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; color: #cbd5e1; padding: 11px 12px; border-radius: 9px; font-weight: 500; }
.side-nav button i { font-style: normal; width: 18px; text-align: center; opacity: .9; }
.side-nav button:hover { background: var(--side-2); color: #fff; }
.side-nav button.active { background: var(--primary); color: #fff; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.side-foot { padding: 14px 16px; border-top: 1px solid #1e293b; display: flex; align-items: center; justify-content: space-between; font-size: 13px; }

.main { display: flex; flex-direction: column; overflow: hidden; }
.main-head { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 22px; }
.main-body { flex: 1; overflow: hidden; position: relative; }
.section { height: 100%; overflow: hidden; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; padding: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin: 0 0 16px; }
.section > .card:first-child { margin-top: 0; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.quick-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; background: var(--bg); color: var(--text); border: 1px solid var(--border); padding: 14px; text-align: left; }
.quick-btn b { font-size: 14px; }
.quick-btn span { font-size: 12px; color: var(--muted); font-weight: 400; }

/* Split (clientes / notificaciones) */
.split { height: 100%; display: grid; grid-template-columns: 340px 1fr; overflow: hidden; }
.split.rev { grid-template-columns: 1fr 340px; }
.split > .side { background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.split.rev > .side { border-right: 0; border-left: 1px solid var(--border); }
.split > .content { overflow-y: auto; padding: 20px; }
.split.rev > .content { padding: 20px; }

.search { display: flex; gap: 8px; padding: 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 2; }
.search input { flex: 1; }
.result-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.result-item:hover { background: #f8fafc; }
.result-item.active { background: var(--primary-soft); }
.result-item .name { font-weight: 600; font-size: 14px; }
.result-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Cliente detalle */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.subtitle { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 6px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warning-soft); color: var(--warning); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--primary-soft); color: var(--primary-dark); }
.flow { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.flow .item { border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.flow .item h3 { font-size: 14px; margin: 0 0 6px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; }

/* Conexiones */
.toolbar { padding: 16px 20px 0; }
.search.inline { padding: 0; border: 0; background: transparent; }
#svcList { padding: 16px 20px; overflow-y: auto; height: calc(100% - 70px); }

/* Mensajes */
.chat-layout { height: 100%; display: grid; grid-template-columns: 300px 1fr 320px; overflow: hidden; }
.conv-list { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.mini-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.inbox { overflow-y: auto; flex: 1; }
.conv { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.conv:hover { background: #f8fafc; }
.conv.active { background: var(--primary-soft); }
.conv .avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.conv .body { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 11px; color: var(--muted); }
.conv .preview { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.chat { display: flex; flex-direction: column; overflow: hidden; background: #efeae2; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 700; }
.chat-sub { font-size: 12px; color: var(--muted); }
.chat-header select { width: auto; height: 34px; padding: 0 8px; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 65%; padding: 8px 12px; border-radius: 12px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); font-size: 14px; word-break: break-word; }
.msg .meta { font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg.them { align-self: flex-start; }
.msg.mine { align-self: flex-end; background: #d9fdd3; }
.msg.system { align-self: center; background: var(--warning-soft); color: var(--warning); font-size: 12px; }
.composer { display: flex; gap: 8px; padding: 10px; background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; max-height: 120px; min-height: 44px; }
.composer button { padding: 0 22px; }
.context { background: var(--surface); border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; font-size: 13px; }

/* Notificaciones */
.actions-row { display: flex; gap: 10px; margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.notice { font-size: 13px; margin-top: 10px; color: var(--muted); }
.campaigns .camp { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.campaigns .camp .t { font-weight: 700; font-size: 14px; }
.campaigns .camp .b { color: var(--muted); font-size: 13px; margin: 4px 0; }
.campaigns .camp .m { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: #fff; border-radius: 16px; padding: 24px; width: 430px; max-width: 92vw; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 64px 1fr; }
  .side-brand span, .side-nav span, .side-foot span { display: none; }
  .split, .split.rev { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 240px 1fr; }
  .context { display: none; }
}
