:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --line: #e4ded1;
  --ink: #1f2420;
  --muted: #6f7268;
  --accent: #1f4d42;
  --accent-2: #2f6f5e;
  --accent-soft: #e3eee9;
  --bubble-in: #ffffff;
  --bubble-out: #dcebe3;
  --danger: #a23b3b;
  --warn: #b5651d;
  --radius: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
label { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label > input, label > textarea, label > select { font-weight: 400; color: var(--ink); font-size: 14px; }

/* Botones */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 9px; font-weight: 600; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:hover { border-color: #cfc7b6; background: #fff; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(0,0,0,.04); color: var(--ink); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.icon { padding: 6px 9px; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Marca */
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-family: var(--serif); font-size: 21px; letter-spacing: -.01em; }
.brand small { color: var(--muted); }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 10px 9px 11px 10px; border: 2.4px solid #f4f1ea; border-radius: 50% 50% 50% 4px; }
.brand.small .brand-mark { width: 34px; height: 34px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #e3eee9 0%, transparent 60%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px; display: grid; gap: 16px; box-shadow: 0 20px 60px -30px rgba(31,77,66,.35); }
.login-card .brand { margin-bottom: 8px; }
.form-error { color: var(--danger); min-height: 1em; margin: 0; font-size: 13px; }

/* Layout app */
.app { display: grid; grid-template-columns: 76px 1fr; height: 100vh; }
.rail { background: var(--accent); color: #d8e6e0; display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail .brand-mark { background: #f4f1ea; }
.rail .brand-mark::after { border-color: var(--accent); }
.rail .brand { margin-bottom: 14px; }
.rail-group { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 8px; margin-top: 4px; }
.rail-btn { position: relative; width: 62px; border: 0; background: transparent; color: inherit; display: grid; justify-items: center; gap: 3px; padding: 8px 0 7px; border-radius: 10px; font-size: 10.5px; font-weight: 600; letter-spacing: .01em; }
.rail-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.rail-btn.active { background: rgba(255,255,255,.14); color: #fff; }
.rail-foot { margin-top: auto; }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); background: #f4f1ea; color: var(--accent); font-weight: 700; }
.badge { position: absolute; top: 3px; right: 8px; background: #e9b44c; color: #2a1e05; font-style: normal; font-size: 10px; font-weight: 800; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.dot { position: absolute; top: 7px; right: 16px; width: 8px; height: 8px; border-radius: 50%; background: #c9c9c9; }
.dot.on { background: #6fdc9b; } .dot.qr { background: #e9b44c; } .dot.off { background: #e66; }

/* Vista chats */
.view { min-width: 0; height: 100vh; overflow: hidden; }
.chats { display: grid; grid-template-columns: 340px 1fr auto; grid-template-rows: 100%; }
.list-col { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.list-head h1 { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 9px 8px 10px; color: var(--muted); font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs b { font-weight: 700; font-size: 11px; background: var(--bg); padding: 1px 6px; border-radius: 8px; margin-left: 2px; }
.tabs b:empty { display: none; }
.search { padding: 10px 12px; }
.search input { background: var(--bg); border-color: transparent; }
.conv-list { list-style: none; margin: 0; padding: 0 6px 10px; overflow-y: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; align-items: center; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--accent-soft); }
.conv .top { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.conv .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .meta { display: grid; justify-items: end; gap: 4px; font-size: 11.5px; color: var(--muted); }
.conv .unread { background: var(--accent); color: #fff; font-weight: 700; font-size: 11px; min-width: 19px; height: 19px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px; }
.conv .sub { display: flex; gap: 6px; margin-top: 3px; align-items: center; min-width: 0; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 20px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.tag i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.tag.queue { background: #fbefd9; color: #8a5a10; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 15px; flex: none; }
.empty-list { color: var(--muted); text-align: center; padding: 40px 20px; font-size: 13px; }
.demo-box { margin: 10px; padding: 12px; border: 1px dashed #d8b46a; background: #fdf6e6; border-radius: 10px; font-size: 12.5px; }
.demo-box p { margin: 4px 0 8px; color: var(--muted); }

.chat-col { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background:
  radial-gradient(circle at 1px 1px, rgba(31,77,66,.07) 1px, transparent 0) 0 0 / 18px 18px, var(--bg); }
.empty-chat { margin: auto; text-align: center; max-width: 340px; color: var(--muted); }
.empty-chat h2 { font-family: var(--serif); color: var(--ink); font-weight: 600; margin: 14px 0 6px; }
.empty-illus { width: 84px; height: 84px; margin: 0 auto; border-radius: 26px; background: var(--accent-soft); position: relative; }
.empty-illus::after { content: ""; position: absolute; inset: 24px 22px 26px 24px; border: 3px solid var(--accent-2); border-radius: 50% 50% 50% 6px; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 14px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.who { display: flex; gap: 11px; align-items: center; min-width: 0; }
.who strong { display: block; font-size: 15px; }
.who small { color: var(--muted); }
.chat-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-actions { margin-left: auto; display: flex; gap: 6px; }
.messages { flex: 1; overflow-y: auto; padding: 22px 6% 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(560px, 78%); padding: 8px 12px 6px; border-radius: 14px; background: var(--bubble-in); box-shadow: 0 1px 0 rgba(0,0,0,.05); white-space: pre-wrap; word-wrap: break-word; align-self: flex-start; border-top-left-radius: 4px; }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-left-radius: 14px; border-top-right-radius: 4px; }
.msg.auto { background: #efe9dc; border: 1px dashed #d6ccb7; }
.msg .foot { display: block; text-align: right; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.msg .by { font-size: 11px; font-weight: 700; color: var(--accent-2); display: block; margin-bottom: 1px; }
.sys { align-self: center; font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.7); padding: 3px 10px; border-radius: 10px; margin: 6px 0; }
.day { align-self: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 10px 0 4px; }
.composer { display: flex; gap: 10px; padding: 12px 18px 16px; background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; border-radius: 12px; }
.composer.disabled { opacity: .6; pointer-events: none; }

.info-col { width: 300px; border-left: 1px solid var(--line); background: var(--panel); padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.info-col header { display: flex; justify-content: space-between; align-items: center; }
.info-col h3, .info-col h4 { margin: 0; font-family: var(--serif); font-weight: 600; }
.info-col h4 { margin-top: 10px; font-size: 15px; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: 12.5px; }
.timeline li { border-left: 2px solid var(--line); padding-left: 10px; }
.timeline small { color: var(--muted); display: block; }

/* Páginas admin */
.page { overflow-y: auto; padding: 32px clamp(18px, 4vw, 48px); }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-family: var(--serif); font-weight: 600; font-size: 30px; margin: 0; letter-spacing: -.015em; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 640px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat .n { font-family: var(--serif); font-size: 40px; font-weight: 600; line-height: 1; }
.stat .l { color: var(--muted); font-weight: 600; font-size: 13px; margin-top: 6px; }
.bars { display: grid; gap: 10px; }
.bar { display: grid; grid-template-columns: 130px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { background: var(--bg); border-radius: 6px; height: 12px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 6px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.status-pill { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.status-pill.on { background: #dff3e7; color: #1f6b41; }
.status-pill.off { background: #eee; color: #777; }
.status-pill.inactive { background: #f6e1e1; color: var(--danger); }
.dep-card { display: grid; gap: 12px; border-left: 5px solid var(--c, var(--accent)); }
.dep-card .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dep-card h3 { margin: 0; font-size: 17px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border-radius: 20px; padding: 3px 10px; font-size: 12.5px; }
.muted { color: var(--muted); }
.qr-wrap { display: grid; grid-template-columns: auto 1fr; gap: 30px; align-items: center; }
.qr-box { width: 300px; height: 300px; border-radius: 16px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.qr-box img { width: 280px; height: 280px; image-rendering: pixelated; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.test-box { display: flex; gap: 8px; }
.result { margin-top: 10px; font-size: 13.5px; }
.form-grid { display: grid; gap: 14px; }

/* Modal */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(460px, 94vw); box-shadow: 0 30px 80px -20px rgba(0,0,0,.35); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(31,36,32,.35); backdrop-filter: blur(2px); }
#modalForm { padding: 22px; display: grid; gap: 14px; }
#modalForm h2 { margin: 0; font-family: var(--serif); font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* volver (solo mobile) */
.back-btn { display: none; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99; font-weight: 500; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

@media (max-width: 1100px) { .info-col { position: fixed; right: 0; top: 0; bottom: 0; z-index: 5; box-shadow: -10px 0 40px rgba(0,0,0,.1); } }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr 64px; }
  .rail { grid-row: 2; flex-direction: row; padding: 0 6px; justify-content: space-around; }
  .rail .brand, .rail-foot { display: none; }
  .rail-group { flex-direction: row; border: 0; padding: 0; margin: 0; }
  .rail-btn { width: 56px; }
  .view { height: calc(100vh - 64px); }
  .chats { grid-template-columns: 1fr; }
  .chats.has-chat .list-col { display: none; }
  .chats:not(.has-chat) .chat-col { display: none; }
  .qr-wrap { grid-template-columns: 1fr; }
  .back-btn { display: inline-block; font-size: 22px; line-height: 1; }
  .chat-actions { margin-left: 0; }
}
