:root {
  --bg: #f3f1ec; --panel: #ffffff; --ink: #1d2320; --muted: #6b746f; --line: #e3e0d8;
  --brand: #0b3d2e; --brand-2: #127a55; --accent: #1fa463; --in: #ffffff; --out: #d9f5e3;
  --danger: #c0392b; --warn: #b9770e; --radius: 14px;
  --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1412; --panel: #171e1b; --ink: #e8ece9; --muted: #95a29b; --line: #26302c;
    --in: #1f2925; --out: #124432; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 980px; margin: 0 auto; background: var(--bg); }
.hidden { display: none !important; }

/* Barra superior */
.topbar { background: var(--brand); color: #fff; padding: calc(10px + var(--safe-top)) 12px 10px; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; letter-spacing: .2px; }
.topbar .sub { font-size: 12px; opacity: .8; font-weight: 400; display: block; }
.icon-btn { background: transparent; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: #f1c40f; display: inline-block; margin-left: 6px; vertical-align: middle; }
.conn.on { background: #2ecc71; }

/* Filtros y búsqueda */
.filters { display: flex; gap: 8px; padding: 10px 12px 6px; overflow-x: auto; flex-shrink: 0; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; white-space: nowrap; font-size: 13px; }
.chip.on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.search { padding: 4px 12px 8px; flex-shrink: 0; }
.search input { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 9px 14px; outline: none; }

/* Lista de conversaciones */
.list { flex: 1; overflow-y: auto; background: var(--panel); }
.row { display: flex; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.row:active { background: rgba(0,0,0,.04); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; font-size: 17px; }
.row .main { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.row .bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.row .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; font-weight: 700; }
.tag { font-size: 11px; border-radius: 6px; padding: 1px 6px; color: #fff; margin-right: 6px; }
.empty { text-align: center; color: var(--muted); padding: 50px 24px; }

/* Chat */
.chat-head { cursor: pointer; flex: 1; min-width: 0; }
.chat-head .title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .sub { font-size: 12px; opacity: .85; }
.window { font-size: 12px; padding: 6px 12px; text-align: center; flex-shrink: 0; }
.window.open { background: #e6f6ec; color: #145a32; }
.window.closed { background: #fdecea; color: #922b21; }
@media (prefers-color-scheme: dark) { .window.open { background: #12352a; color: #a9dfbf; } .window.closed { background: #3d1d1a; color: #f5b7b1; } }
.messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg { max-width: 82%; padding: 7px 10px 5px; border-radius: 12px; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; overflow-wrap: anywhere; position: relative; }
.msg .txt { white-space: pre-wrap; }
.msg.in { background: var(--in); align-self: flex-start; border-top-left-radius: 4px; }
.msg.out { background: var(--out); align-self: flex-end; border-top-right-radius: 4px; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg .src { font-size: 10px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.msg .ticks.read { color: #2e86de; }
.msg .err { color: var(--danger); font-size: 12px; margin-top: 4px; }
.msg img, .msg video { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; max-height: 340px; }
.msg audio { width: 240px; max-width: 100%; }
.msg .doc { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 8px; background: rgba(0,0,0,.05); text-decoration: none; color: inherit; margin-bottom: 4px; }
.msg .quote { border-left: 3px solid var(--accent); background: rgba(0,0,0,.05); padding: 4px 8px; border-radius: 6px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.msg a { color: var(--brand-2); }

/* Composer */
.composer { display: flex; gap: 6px; padding: 8px 8px calc(8px + var(--safe-bottom)); align-items: flex-end; background: var(--bg); flex-shrink: 0; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 22px; padding: 10px 14px; max-height: 140px; background: var(--panel); outline: none; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; font-size: 19px; flex-shrink: 0; background: var(--panel); }
.round.send { background: var(--accent); color: #fff; }
.round.rec { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.replying { padding: 6px 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.replying span { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Paneles y modales */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); width: 100%; max-width: 640px; max-height: 88dvh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-bottom)); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--brand-2); color: #fff; font-weight: 600; width: 100%; margin-top: 8px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.menu-item { display: flex; gap: 12px; align-items: center; padding: 13px 4px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv b { color: var(--muted); font-weight: 500; }
.order { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; font-size: 14px; }
.order .h { display: flex; justify-content: space-between; font-weight: 600; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.tpl-preview { background: var(--out); border-radius: 10px; padding: 10px; white-space: pre-wrap; font-size: 14px; }

/* Login */
.login { flex: 1; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, var(--brand), #145c43); }
.login form { background: var(--panel); padding: 26px 22px; border-radius: 18px; width: 100%; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.show { opacity: .95; }
.fab { position: fixed; right: max(18px, calc(50vw - 472px)); bottom: calc(22px + var(--safe-bottom)); width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; border: 0; font-size: 26px; box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.load-more { align-self: center; margin: 6px; }

/* ---------- v1.1: equipos ---------- */
.tabs { display: flex; background: var(--brand); flex-shrink: 0; }
.tabs button { flex: 1; background: none; border: 0; color: rgba(255,255,255,.75); padding: 10px 4px 11px; font-weight: 600; border-bottom: 3px solid transparent; }
.tabs button.on { color: #fff; border-bottom-color: #7ee2a8; }
.tabs .cnt:not(:empty) { background: #7ee2a8; color: var(--brand); border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.chip.sm { padding: 4px 10px; font-size: 12px; }
.tag.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.row .right { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.who { width: 22px; height: 22px; border-radius: 50%; background: var(--line); color: var(--ink); font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.who.none { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.assignbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.assignbar .chip.on { background: #e6f6ec; border-color: #a9dfbf; color: #145a32; }
.win { font-size: 12px; padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.win.open { color: #145a32; background: #e6f6ec; }
.win.closed { color: #922b21; background: #fdecea; cursor: pointer; }
@media (prefers-color-scheme: dark) { .win.open, .assignbar .chip.on { background: #12352a; color: #a9dfbf; border-color: #1e5c45; } .win.closed { background: #3d1d1a; color: #f5b7b1; } }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: rgba(0,0,0,.04); padding: 3px 10px; border-radius: 8px; margin: 4px 0; text-align: center; max-width: 90%; }
.msg.note { align-self: center; background: #fff6d6; border: 1px dashed #e0c25c; max-width: 90%; color: #5c4a00; }
@media (prefers-color-scheme: dark) { .msg.note { background: #3a3215; color: #f3e3a3; border-color: #7a6520; } }
.msg .who-n { font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.msg .by { font-size: 11px; font-weight: 600; color: var(--brand-2); }
.composer.note-mode textarea { background: #fff6d6; border-color: #e0c25c; }
@media (prefers-color-scheme: dark) { .composer.note-mode textarea { background: #3a3215; } }
.round.on { background: #f7dc6f; }
.qr { background: var(--panel); border-top: 1px solid var(--line); max-height: 220px; overflow-y: auto; flex-shrink: 0; }
.qi { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.qi b { color: var(--brand-2); margin-right: 6px; }
.qi.muted, .muted { color: var(--muted); }
.adm section { border-bottom: 8px solid var(--bg); }
.adm h3 { margin: 0; padding: 14px 14px 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.pad { padding: 10px 14px 14px; }
.row.inv { opacity: .8; }
.hours { margin: 6px 0 10px; }
.hrow { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.hrow label { width: 70px; }
.hrow input[type=time] { border: 1px solid var(--line); border-radius: 8px; padding: 5px; background: var(--bg); }
.acc-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; display: grid; gap: 6px; }
.acc-row select { border: 1px solid var(--line); border-radius: 8px; padding: 7px; background: var(--bg); }
.acc-row .small { font-size: 13px; color: var(--muted); }
.qrow { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.qrow b { color: var(--brand-2); }
code { background: var(--bg); padding: 2px 4px; border-radius: 4px; }
