:root {
  --bg: #f4f5f4; --panel: #ffffff; --panel-2: #f8faf9; --line: #e3e6e4;
  --fg: #16201d; --muted: #5d6b66; --accent: #0f766e; --accent-fg: #ffffff;
  --accent-soft: #ccfbf1; --in: #ffffff; --out: #d7f5ec; --danger: #b42318; --warn-bg: #fff4e5; --warn-fg: #8a4b00;
  --read: #0284c7; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
}
:root { color-scheme: light; }
/* Oscuro automático (si el teléfono/PC está en modo oscuro), salvo que el usuario elija "Claro" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412; --panel: #151d1a; --panel-2: #1a2420; --line: #26322d;
    --fg: #e6efec; --muted: #94a59f; --accent: #2dd4bf; --accent-fg: #062b26;
    --accent-soft: #123b35; --in: #1d2925; --out: #10443c; --danger: #f97066; --warn-bg: #3a2a10; --warn-fg: #fbc56a;
    --read: #38bdf8; --shadow: none;
    color-scheme: dark;
  }
}
/* Oscuro elegido a mano */
:root[data-theme="dark"] {
    --bg: #0e1412; --panel: #151d1a; --panel-2: #1a2420; --line: #26322d;
    --fg: #e6efec; --muted: #94a59f; --accent: #2dd4bf; --accent-fg: #062b26;
    --accent-soft: #123b35; --in: #1d2925; --out: #10443c; --danger: #f97066; --warn-bg: #3a2a10; --warn-fg: #fbc56a;
    --read: #38bdf8; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); } .small { font-size: 13px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.btn.primary:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn.icon { padding: 7px 10px; }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; }

/* AUTH */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card p { margin: 0; }
.auth-card label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
.auth-logo { border-radius: 14px; }

/* LAYOUT */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; gap: 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 7px; }
.nav { display: grid; gap: 4px; }
.nav-btn { text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.nav-btn:hover { background: var(--panel-2); }
.nav-btn.active { background: var(--accent-soft); font-weight: 600; }
.side-foot { margin-top: auto; display: grid; gap: 6px; }
.side-foot .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { min-width: 0; min-height: 0; overflow: hidden; }

/* INBOX */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100%; min-height: 0; }
.list-col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.list-head { padding: 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab { border: 1px solid var(--line); background: none; border-radius: 99px; padding: 4px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.conv-main { min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-prev { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-side { display: grid; justify-items: end; gap: 4px; font-size: 12px; color: var(--muted); }
.badge { background: var(--accent); color: var(--accent-fg); border-radius: 99px; min-width: 20px; padding: 1px 6px; text-align: center; font-weight: 700; font-size: 12px; }
.dots { display: flex; gap: 3px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.empty.big { display: grid; place-items: center; height: 100%; font-size: 16px; }

.chat-col { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.who { display: grid; min-width: 0; flex: 1; }
.who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions { display: flex; gap: 6px; align-items: center; }
.chat-actions select { width: auto; padding: 6px 8px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: 13px; cursor: pointer; background: none; }
.chip .dot { width: 9px; height: 9px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.banner { padding: 9px 14px; font-size: 14px; background: var(--warn-bg); color: var(--warn-fg); border-bottom: 1px solid var(--line); }
.banner.ok { background: var(--accent-soft); color: var(--fg); }
.messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 2px 10px; border-radius: 99px; margin: 8px 0; }
.msg { max-width: min(78%, 560px); padding: 8px 11px 6px; border-radius: 14px; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--in); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out); border-bottom-right-radius: 4px; }
.msg .meta { display: flex; justify-content: flex-end; gap: 5px; font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg .kind { font-size: 12px; color: var(--muted); font-style: italic; }
.tick.read { color: var(--read); } .tick.failed { color: var(--danger); }
.msg .err { color: var(--danger); font-size: 12px; }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; }
.composer.template input { flex: 1; }
.qr-pop { position: absolute; left: 12px; right: 12px; bottom: 64px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.15); max-height: 260px; overflow-y: auto; z-index: 5; }
.qr-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; cursor: pointer; }
.qr-item:hover, .qr-item.sel { background: var(--accent-soft); }
.qr-item b { color: var(--accent); }
.qr-item span { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* PANES */
.pane { padding: 20px; overflow-y: auto; height: 100%; }
.pane h2 { margin: 0 0 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.row-form { display: grid; gap: 8px; margin: 12px 0; }
.row-form.inline { grid-template-columns: 1fr 52px auto; }
.row-form.inline input[type=color] { padding: 2px; height: 40px; }
.grid-form { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); }
.item-list .grow { flex: 1; min-width: 0; }
.item-list .body { color: var(--muted); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table select { width: auto; padding: 4px 8px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.toast.bad { background: var(--danger); color: #fff; }

.only-mobile { display: none; }

/* MÓVIL / TABLET */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { flex-direction: row; align-items: center; padding: 8px 10px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand span { display: none; }
  .biz-picker { flex: 1; min-width: 120px; }
  .nav { display: flex; }
  .nav-btn span { display: none; }
  .side-foot { margin: 0; display: flex; }
  .side-foot .muted { display: none; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.show-chat .list-col { display: none; }
  .inbox:not(.show-chat) .chat-col { display: none; }
  .only-mobile { display: inline-block; }
  .pane { padding: 16px; }
  .msg { max-width: 88%; }
}

/* ARCHIVOS */
.media { margin: 2px 0 4px; }
.media img { display: block; max-width: min(320px, 100%); max-height: 360px; border-radius: 10px; cursor: zoom-in; object-fit: cover; background: var(--panel-2); }
.media-sticker img { max-width: 160px; background: transparent; cursor: default; }
.media audio { width: min(300px, 70vw); height: 40px; display: block; }
.media video { display: block; max-width: min(340px, 100%); max-height: 380px; border-radius: 10px; background: #000; }
.doc { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--fg); text-decoration: none; }
.doc span { font-weight: 600; overflow-wrap: anywhere; }
.caption { margin-top: 2px; }

/* ===== v2: equipo, roles, guía, avisos ===== */
.btn.big { padding: 12px 16px; font-size: 16px; }
.btn.on { color: var(--accent); }
.lead { margin: -8px 0 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.nav-btn { position: relative; display: flex; align-items: center; gap: 6px; }
.nav-badge { margin-left: auto; background: var(--accent); color: var(--accent-fg); border-radius: 99px; font-size: 11px; padding: 1px 7px; }
.side-foot .btn { justify-content: flex-start; text-align: left; }
.conv.waiting .conv-name::after { content: " •"; color: var(--accent); }
.composer.readonly { justify-content: center; padding: 14px; }
.composer.template { justify-content: center; }
.msg .by { font-weight: 600; margin-right: auto; padding-right: 8px; }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; margin-left: 6px; }
.avatar.small { width: 32px; height: 32px; font-size: 14px; flex: none; }
.item-list li > select { width: auto; max-width: 140px; padding: 5px 8px; }
details.more { position: relative; }
details.more > summary { list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more .menu { position: absolute; right: 0; top: 100%; z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.15); display: grid; padding: 4px; min-width: 170px; }
.add-box { margin-top: 12px; }
.add-box > summary { list-style: none; display: inline-block; }
.add-box > summary::-webkit-details-marker { display: none; }
.add-box[open] > summary { display: none; }
.row-form label, .field .label { display: grid; gap: 5px; font-size: 14px; font-weight: 500; }
.row-form.inline2 { grid-template-columns: 1fr auto; margin-top: 14px; }
.field { margin: 14px 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 6px 0; }
.seg button { border: 0; background: none; padding: 9px 14px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.check { display: flex !important; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: auto; }
.role { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.role.owner { background: var(--panel-2); }
.role-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.role-head .muted { margin-right: auto; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 12px; margin-top: 8px; }
.perm { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 4px 0; cursor: pointer; }
.perm input { width: 18px; height: 18px; accent-color: var(--accent); }
.perm.soon { color: var(--muted); }
.card.center { text-align: center; max-width: 520px; margin: 40px auto; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal-card { position: relative; background: var(--panel); color: var(--fg); border-radius: 16px; padding: 22px 20px 18px; width: 100%; max-width: 480px; max-height: 90dvh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card h2 { margin: 0 32px 12px 0; font-size: 19px; }
.modal-x { position: absolute; top: 10px; right: 10px; }
.cred { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 6px; margin: 10px 0; font-size: 16px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .5px; }
pre.share { white-space: pre-wrap; background: var(--panel-2); border-radius: 10px; padding: 10px; font: 13px/1.4 system-ui, sans-serif; color: var(--muted); margin: 0; }
.tpl-list { display: grid; gap: 8px; }
.tpl-item { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.tpl-item:hover { border-color: var(--accent); }
.tpl-item div { margin-top: 4px; white-space: pre-wrap; }
.tpl-preview { background: var(--out); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; margin-bottom: 12px; }
.guide { text-align: center; }
.guide-icon { font-size: 44px; margin: 4px 0 6px; }
.guide h3 { margin: 0 0 8px; font-size: 18px; }
.guide p { color: var(--muted); margin: 0 auto; max-width: 360px; }
.dots-row { display: flex; gap: 6px; justify-content: center; margin: 16px 0 4px; }
.gdot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.gdot.on { background: var(--accent); }

@media (max-width: 900px) {
  .nav-badge { position: absolute; top: 2px; right: 2px; }
  .side-foot .btn span { display: none; }
  #user-name { display: none; }
  .item-list li { flex-wrap: wrap; }
}

/* Selector de tema */
.theme-seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.theme-seg button { flex: 1; border: 0; background: none; padding: 6px 0; cursor: pointer; font-size: 15px; }
.theme-seg button.on { background: var(--accent-soft); }
@media (max-width: 900px) { .theme-seg { display: none; } #theme-mini { display: inline-block !important; } }
#theme-mini { display: none !important; }

/* ===== v3: ficha, asignar, horario, actividad ===== */
.note { color: var(--warn-fg); background: var(--warn-bg); border-radius: 6px; padding: 1px 6px; margin-top: 3px; justify-self: start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-assign { width: auto; max-width: 150px; padding: 6px 8px; }
.auto-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.auto-box p { margin: 4px 0 8px; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.hours-grid { display: grid; gap: 6px; margin-top: 6px; }
.hour-row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 8px; }
.hour-row .times { display: flex; align-items: center; gap: 6px; }
.hour-row input[type=time] { width: auto; padding: 6px 8px; }
.hour-row.closed .times { opacity: .4; pointer-events: none; }
.activity li { font-size: 14px; }
.activity time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg .auto { font-size: 11px; color: var(--muted); }
.ficha textarea { min-height: 90px; }
@media (max-width: 900px) { .hide-mobile { display: none; } .chat-head { flex-wrap: wrap; } #chat-assign { max-width: 120px; } }
#hours-card { grid-column: 1 / -1; }
#hours-card .auto-wrap { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
.hour-row .times { flex-wrap: wrap; }
.hour-row input[type=time] { width: 130px; }
@media (max-width: 520px) { .hour-row { grid-template-columns: 1fr; gap: 2px; } .hour-row input[type=time] { width: 120px; } }
/* Pestañas: que bajen de línea en vez de mostrar barra de desplazamiento */
.tabs { flex-wrap: wrap; overflow: visible; row-gap: 6px; }

/* ===== auditoría ===== */
.net-banner { background: var(--warn-bg); color: var(--warn-fg); padding: 8px 14px; font-size: 14px; text-align: center; border-bottom: 1px solid var(--line); }
.main { display: flex; flex-direction: column; }
.main > section { flex: 1; min-height: 0; }
.messages .older { align-self: center; margin-bottom: 6px; }
.msg .retry { margin-top: 6px; padding: 3px 10px; font-size: 12px; }

/* ===== v4: resumen, archivos, presencia, números ===== */
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.pane-head h2 { margin: 0; }
.lead { margin: 4px 0 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-align: left; box-shadow: var(--shadow); color: var(--fg); }
button.kpi { cursor: pointer; font: inherit; }
button.kpi:hover { border-color: var(--accent); }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1.2; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi.warn { background: var(--warn-bg); border-color: transparent; }
.kpi.warn .kpi-value, .kpi.warn .kpi-label, .kpi.warn .kpi-sub { color: var(--warn-fg); }
.chart { position: relative; margin-top: 8px; min-height: 60px; }
.chart svg { display: block; max-width: 100%; overflow: visible; }
.chart .bar { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-opacity: .5; stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--fg); fill-opacity: .04; }
.chart-tip { position: absolute; transform: translateX(-50%); background: var(--fg); color: var(--bg); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.chart-empty { padding: 30px 0; text-align: center; }
#members-card { grid-column: 1 / -1; }
.presence { color: var(--accent); margin-top: 2px; }
.presence.typing { font-style: italic; }
.chat.drop { outline: 3px dashed var(--accent); outline-offset: -6px; }
.att-preview { display: grid; place-items: center; background: var(--panel-2); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.att-img { max-width: 100%; max-height: 50vh; border-radius: 8px; }
.att-doc { padding: 18px; font-size: 15px; overflow-wrap: anywhere; }
.att-preview audio { width: 100%; }
.modal-body textarea, #modal-body textarea { margin-bottom: 10px; }
.num-facts { display: flex; flex-direction: column; gap: 3px; margin-top: 5px; align-items: flex-start; }
.pill.status-good { background: #dcfae6; color: #085d3a; border-color: transparent; }
.pill.status-warning { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }
.pill.status-critical { background: #fee4e2; color: #912018; border-color: transparent; }
:root[data-theme="dark"] .pill.status-good { background: #053321; color: #75e0a7; }
:root[data-theme="dark"] .pill.status-critical { background: #55160c; color: #fda29b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.status-good { background: #053321; color: #75e0a7; }
  :root:not([data-theme="light"]) .pill.status-critical { background: #55160c; color: #fda29b; }
}
.steps { margin: 12px 0; padding-left: 20px; display: grid; gap: 6px; }
.steps a { color: var(--accent); }
@media (max-width: 900px) { .kpi-value { font-size: 24px; } .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (min-width: 901px) {
  #pane-metrics .grid2 { grid-template-columns: 3fr 2fr; }
  #pane-metrics .grid2:has(#weekday-card[hidden]) > .card:first-child { grid-column: 1 / -1; }
}

/* ===== v5: fotos tipo WhatsApp, visor, avisos ===== */
.msg.has-media { padding: 4px 4px 5px; width: min(320px, 88%); }
.msg.has-media .media { margin: 0; }
.msg.has-media .media img, .msg.has-media .media video { width: 100%; max-width: 100%; max-height: 380px; border-radius: 10px; }
.msg.has-media .caption, .msg.has-media .meta, .msg.has-media .kind, .msg.has-media .err, .msg.has-media .by { padding: 0 6px; }
.msg.has-media .caption { margin-top: 5px; }
.msg.is-sticker { background: transparent; border: 0; box-shadow: none; width: auto; }
.msg.is-sticker .media img { width: 140px; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.95); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 56px 12px 16px; gap: 10px; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 130px); object-fit: contain; border-radius: 6px; cursor: zoom-out; }
.lb-bar { position: absolute; top: 10px; right: 12px; display: flex; gap: 8px; }
.lb-bar .btn { background: rgba(255,255,255,.14); color: #fff; border-color: transparent; }
.lb-caption { color: #fff; max-width: 640px; text-align: center; white-space: pre-wrap; font-size: 14px; }
.push-banner { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--accent-soft); color: var(--fg); font-size: 13px; border-bottom: 1px solid var(--line); }
.push-banner span { flex: 1; }
.aviso-estado { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; display: grid; gap: 3px; }
.aviso-estado.ok { background: var(--accent-soft); }
.aviso-estado.no { background: var(--warn-bg); color: var(--warn-fg); }
.avisos .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.avisos .switch { margin-bottom: 10px; font-size: 14px; }
.avisos .tips summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.avisos .tips ul { padding-left: 18px; margin: 8px 0 0; display: grid; gap: 6px; }
.guia-paso { display: flex; gap: 10px; align-items: flex-start; }
.guia-paso p { margin: 2px 0 10px; font-size: 15px; }
.guia-avisos > .btn.small { margin: 0 0 10px 38px; }
.guia-num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-weight: 700; }
.guia-img { display: block; width: 100%; max-width: 380px; margin: 0 auto 8px; border-radius: 12px; border: 1px solid var(--line); }
.avisos > .btn.small { margin-bottom: 10px; }

/* ===== Ajustes por pestañas ===== */
.subtabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; margin-bottom: 8px; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button { flex: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg); border-radius: 99px; padding: 8px 14px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.subtabs button.on { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.set-panel { max-width: 820px; display: grid; gap: 16px; }
.set-panel .card { margin-bottom: 0; }
.card.tab-off { display: none; }
#pane-settings #hours-card { grid-column: auto; }
.fix-steps { margin: 6px 0 8px; padding-left: 18px; display: grid; gap: 3px; }
.aviso-estado .btn.small { justify-self: start; }
.preview-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 14px; background: #4338ca; color: #fff; font-size: 14px; }
.preview-banner span { flex: 1; min-width: 200px; }
.preview-banner .btn { background: #fff; color: #312e81; border-color: transparent; font-weight: 600; }

/* ===== Auditoría visual (15-oct) ===== */
/* Botón ⋯ del menú (solo celular) */
#more-btn { display: none; }
.toast.bad { background: #b42318; color: #fff; }
a.btn { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.row-form .switch { display: flex; }
.conv.active .avatar { background: var(--panel); }
#qr-list .body { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
#admin-rows td:first-child { white-space: normal; min-width: 170px; max-width: 280px; }
.role-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.role-head > b + span { margin-right: auto; }
.hour-row .closed-label { display: none; }
.hour-row.closed .closed-label { display: inline; }
.menu-sheet { display: grid; gap: 8px; }
.menu-sheet .btn { justify-content: flex-start; text-align: left; padding: 12px 14px; font-size: 16px; display: flex; gap: 10px; }
.menu-sheet .who-am-i { color: var(--muted); font-size: 14px; padding: 4px 2px 8px; overflow-wrap: anywhere; }
.menu-sheet .theme-row { display: flex; gap: 6px; }
.menu-sheet .theme-row .btn { flex: 1; justify-content: center; }
.menu-sheet .theme-row .btn.on { background: var(--accent-soft); border-color: var(--accent); }
.toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
.composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.lb-bar { top: calc(10px + env(safe-area-inset-top)); }

@media (max-width: 900px) {
  /* Barra de arriba: sin scroll oculto; lo secundario va al menú ⋯ */
  .side { overflow: visible; padding-top: calc(8px + env(safe-area-inset-top)); }
  .side-foot > *:not(#more-btn) { display: none !important; }
  #more-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; font-size: 20px; }
  .biz-picker { min-width: 0; }
  .nav { gap: 2px; }
  .nav-btn { min-width: 40px; min-height: 40px; justify-content: center; padding: 8px; }
  /* iPhone no hace zoom si los campos miden 16px o más */
  input, select, textarea, .auth-card label, .row-form label { font-size: 16px; }
  /* Encabezado del chat en 2 filas ordenadas */
  .chat-head { flex-wrap: wrap; row-gap: 6px; padding: 8px 10px; }
  .chat-actions { order: 3; flex: 1 1 100%; }
  .chat-actions select { flex: 1; min-width: 0; }
  .who > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tag-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 6px 10px; }
  .tag-row::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  #msg-input::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .subtabs { flex-wrap: nowrap; }
  .toast { bottom: auto; top: calc(64px + env(safe-area-inset-top)); }
  .hour-row .closed-label { margin-left: 4px; }
}
@media (max-width: 900px) {
  .biz-picker { display: none !important; } /* el negocio se cambia desde el menú ⋯ */
  .brand { flex: none; }
  .nav { margin-left: auto; }
  .menu-sheet select { width: 100%; }
}
/* Botones cómodos para el dedo */
@media (pointer: coarse) {
  .tab, .chip, .btn.small, .btn.icon, .lb-bar .btn, .msg .retry, .older { min-height: 40px; }
  .btn.small, .btn.icon, .lb-bar .btn { min-width: 40px; }
  #back-btn { min-width: 44px; min-height: 44px; }
}
:root[data-theme="dark"] .msg.out .err { color: #fda29b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .msg.out .err { color: #fda29b; } }
.mobile-biz { display: none; }
.toast { pointer-events: none; }
.role-head .btn.ghost { border-color: var(--line); }
@media (max-width: 900px) {
  .mobile-biz:not([hidden]) { display: inline; font-size: 13px; max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .toast { top: auto; bottom: calc(78px + env(safe-area-inset-bottom)); }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; }
  #chat-assign { max-width: none; }
  .preview-banner { padding: 6px 10px; }
}
@media (max-width: 900px) {
  .side { gap: 4px; }
  .brand { flex: 0 1 auto; min-width: 0; overflow: hidden; }
  .brand img { flex: none; }
  .mobile-biz:not([hidden]) { max-width: none; min-width: 0; }
  .nav, .side-foot { flex: none; }
}

/* ===== v6: respuestas automáticas con botones ===== */
#auto-card .auto-wrap { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
.sub-h { margin: 22px 0 4px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 16px; }
.label { font-size: 14px; font-weight: 500; }
.rule-form .label { display: block; margin: 12px 0 5px; }
.rule-form .rule-on { margin: 14px 0 4px; }
.btn-editor { display: grid; gap: 8px; margin-top: 6px; }
.btn-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.btn-row input, .btn-row select { width: 100%; min-width: 0; }
.btn-editor .add-btn { justify-self: start; }
.wa-preview { background: #e9e2d8; border-radius: 12px; padding: 12px; }
.wa-bubble { background: #fff; color: #111b21; border-radius: 10px; border-top-left-radius: 2px; padding: 8px 10px; max-width: 320px; box-shadow: 0 1px 1px rgba(0,0,0,.12); }
.wa-bubble .caption { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.wa-btns { display: grid; gap: 0; margin-top: 6px; }
.wa-btn { display: block; text-align: center; padding: 7px 4px; border-top: 1px solid rgba(0,0,0,.08); color: #027eb5; font-weight: 600; font-size: 14px; }
.msg .wa-btn { color: inherit; opacity: .85; border-top-color: rgba(127,127,127,.25); }
:root[data-theme="dark"] .wa-preview { background: #0b141a; }
:root[data-theme="dark"] .wa-bubble { background: #202c33; color: #e9edef; }
:root[data-theme="dark"] .wa-bubble .wa-btn { color: #53bdeb; border-top-color: rgba(255,255,255,.1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wa-preview { background: #0b141a; }
  :root:not([data-theme="light"]) .wa-bubble { background: #202c33; color: #e9edef; }
  :root:not([data-theme="light"]) .wa-bubble .wa-btn { color: #53bdeb; border-top-color: rgba(255,255,255,.1); }
}
.rule-list li.off { opacity: .55; }
.rule-list .wa-btns { max-width: 260px; }
.rule-list .wa-btn { font-size: 13px; padding: 4px; }
.rule-actions { display: flex; gap: 6px; flex-shrink: 0; }
.kw-pills { display: flex; flex-wrap: wrap; gap: 4px; margin: 5px 0; }
.rule-test { margin-top: 16px; padding: 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.rule-test .label { display: block; margin-bottom: 6px; }
.rule-test input { width: 100%; }
#rule-test-out:not(:empty) { margin-top: 10px; }
#rule-test-out p { margin: 0 0 6px; }
.more-info { margin-top: 12px; }
.more-info summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.more-info ul { margin: 6px 0 0; padding-left: 18px; }
@media (max-width: 900px) {
  .btn-row { grid-template-columns: minmax(0, 1fr) auto; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; }
  .btn-row > span { display: none; }
  .btn-row select { grid-column: 1 / -1; grid-row: 2; }
  .rule-list li { flex-wrap: wrap; }
  .rule-list .grow { flex-basis: calc(100% - 60px); }
  .rule-actions { width: 100%; justify-content: flex-end; }
}

/* ===== v7: íconos de línea (sin emojis) ===== */
.ic { width: 1.15em; height: 1.15em; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.22em; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn.icon .ic { width: 20px; height: 20px; }
.nav-btn { gap: 10px; }
.nav-btn .ic { width: 19px; height: 19px; opacity: .8; }
.nav-btn.active .ic { opacity: 1; color: var(--accent); }
.subtabs button { display: inline-flex; align-items: center; gap: 6px; }
.subtabs button .ic { width: 16px; height: 16px; opacity: .75; }
.subtabs button.on .ic { opacity: 1; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.theme-seg button { display: flex; align-items: center; justify-content: center; padding: 7px 0; }
.theme-seg button .ic { width: 17px; height: 17px; }
#theme-mini .ic { width: 18px; height: 18px; }
.ic-row { display: inline-flex; align-items: center; gap: 7px; }
.guide-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 4px 0 10px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); font-size: 0; }
.guide-icon .ic { width: 32px; height: 32px; stroke-width: 1.7; }
.msg .kind { display: flex; align-items: center; gap: 5px; }
.msg .kind .ic { width: 14px; height: 14px; }
.msg .auto { display: inline-flex; align-items: center; gap: 3px; }
.msg .auto .ic { width: 13px; height: 13px; }
.tick .ic { width: 13px; height: 13px; vertical-align: -2px; }
.wa-btn { display: flex; align-items: center; justify-content: center; gap: 6px; }
.wa-btn .ic { width: 15px; height: 15px; }
.doc .ic, .att-doc .ic { width: 20px; height: 20px; }
#chat-note { display: flex; align-items: center; gap: 6px; }
#chat-note .ic { width: 15px; height: 15px; }
.menu-sheet .btn { justify-content: flex-start; }
.menu-sheet .theme-row .btn { justify-content: center; }
.aviso-estado b.ic-row .ic { width: 18px; height: 18px; }

/* ===== v8: pestañas en celular = una sola barra deslizable con línea (sin filas apiladas) ===== */
@media (max-width: 900px) {
  .subtabs {
    position: sticky; top: -16px; z-index: 3; background: var(--bg);
    flex-wrap: nowrap; overflow-x: auto; gap: 2px; margin: -4px -16px 14px; padding: 0 10px;
    border-bottom: 1px solid var(--line); scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  }
  .subtabs.at-end { -webkit-mask-image: none; mask-image: none; }
  .subtabs button {
    flex: none; scroll-snap-align: start; border: 0; border-radius: 0; background: none; color: var(--muted);
    padding: 13px 10px 11px; min-height: 46px; font-size: 14px; border-bottom: 2.5px solid transparent; margin-bottom: -1px;
  }
  .subtabs button.on { background: none; color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
  .subtabs button .ic { width: 17px; height: 17px; }
}
/* Selector de tema: ícono + nombre (Sistema / Claro / Oscuro) */
.theme-seg button { flex-direction: column; gap: 3px; padding: 7px 0 6px; font-size: 11.5px; color: var(--muted); }
.theme-seg button.on { color: var(--fg); font-weight: 600; }
.theme-seg button.on .ic { color: var(--accent); }

/* ===== Fotos en respuestas rápidas y automáticas (hasta 5) ===== */
.ph-editor { display: flex; flex-wrap: wrap; gap: 8px; }
.ph-item { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); flex: none; }
.ph-item.loading { display: grid; place-items: center; }
.ph-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-num { position: absolute; left: 4px; top: 4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.ph-btn { position: absolute; bottom: 4px; width: 30px; height: 30px; border: 0; border-radius: 99px; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; }
.ph-btn .ic { width: 16px; height: 16px; }
.ph-btn:hover { background: rgba(0,0,0,.8); }
.ph-del { right: 4px; }
.ph-left { left: 4px; }
.ph-add { width: 84px; height: 84px; border: 1.5px dashed var(--line); border-radius: 10px; background: none; color: var(--muted); display: grid; place-items: center; align-content: center; gap: 4px; font-size: 12px; cursor: pointer; flex: none; padding: 4px; text-align: center; }
.ph-add:hover { border-color: var(--accent); color: var(--accent); }
.ph-add .ic { width: 22px; height: 22px; }
.ph-strip { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.ph-mini { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); display: block; flex: none; }
img.broken { visibility: hidden; }
/* Vista previa estilo WhatsApp */
.wa-preview { display: grid; gap: 6px; justify-items: start; }
.wa-bubble.ph { padding: 4px; width: min(260px, 100%); }
.wa-bubble.ph .caption, .wa-bubble.ph .wa-btns { padding: 4px 6px 0; }
.wa-img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 7px; display: block; background: rgba(127,127,127,.15); min-height: 80px; }
/* Fotos listas para enviar, arriba del cuadro de texto */
.qr-att:not([hidden]) { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel-2); }
.qr-att .ph-strip { margin: 0; flex-wrap: nowrap; overflow-x: auto; flex: 0 1 auto; min-width: 0; }
.qr-att .att-note { flex: 1; min-width: 0; }
.qr-att .btn { flex: none; }
/* Menú "/" con miniatura */
.qr-item.has-ph { display: flex; align-items: center; gap: 10px; }
.qr-item .qr-txt { display: block; min-width: 0; flex: 1; color: inherit; font-size: inherit; white-space: normal; }
.qr-item .qr-txt span { display: block; }
.qr-ph { position: relative; flex: none; display: block; }
.qr-ph small { position: absolute; right: -4px; bottom: -4px; background: var(--accent); color: var(--accent-fg); border-radius: 99px; font-size: 11px; font-weight: 600; padding: 0 5px; line-height: 17px; }
@media (max-width: 900px) {
  .ph-item, .ph-add { width: 76px; height: 76px; }
  .ph-btn { width: 32px; height: 32px; }
}
.qr-att .att-note b { font-weight: 600; color: var(--fg); }
@media (max-width: 480px) {
  .qr-att .att-hint { display: none; }
  .wa-img { max-height: 170px; }
}

/* ===== Tope de fotos, consejos y espacio ===== */
.tip { display: flex; gap: 10px; align-items: flex-start; background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin: 10px 0 14px; }
.tip > .ic, .tip > [data-icon] { flex: none; color: var(--accent); margin-top: 1px; }
.tip > [data-icon] .ic, .tip > .ic { width: 20px; height: 20px; }
.tip p { margin: 0; font-size: 13.5px; line-height: 1.45; }
.warn-text { color: var(--warn-fg) !important; }
.ph-editor-wrap { display: grid; gap: 6px; }
.ph-usage { margin: 0; }
.ph-add.is-full { opacity: .6; border-style: solid; }
.num-input { width: 84px; padding: 5px 8px; }

/* ===== Liberar espacio ===== */
.btn.danger-solid { background: var(--danger); color: #fff; border-color: transparent; font-weight: 600; }
.btn.danger-solid:disabled, .btn:disabled { opacity: .55; cursor: not-allowed; }
.modal label.label select { margin-top: 6px; }

/* ===== Google Drive ===== */
#drive-body p .ic { width: 16px; height: 16px; vertical-align: -3px; color: var(--accent); }
.drive-return { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.drive-return .card { max-width: 420px; width: 100%; text-align: center; display: grid; gap: 10px; justify-items: center; }
.drive-return h1 { font-size: 20px; margin: 4px 0 0; }
.drive-return img { border-radius: 14px; }
.drive-folder { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.drive-folder b { overflow-wrap: anywhere; }
