/* =====================================================================
   NetwilOne CRM · sistema de diseno

   Hoja propia y autocontenida. El CRM es una herramienta de trabajo de una
   sola pantalla: densa, rapida de leer, y igual de comoda en el telefono del
   agente que en el escritorio.

   Estructura:
     escritorio   menu lateral (248px; 76px solo iconos entre 761 y 1280)
     telefono     barra arriba + pestanas abajo, como una app

   Colores: todo sale de los tokens de :root. Oscuro si el sistema lo pide.
   ===================================================================== */

:root {
    --bg: #F2F5F3;
    --surface: #FFFFFF;
    --surface-2: #F7F9F8;
    --surface-3: #EEF2F0;
    --line: #E2E8E4;
    --line-strong: #D0D9D4;
    --text: #0E1A13;
    --text-2: #354239;
    --muted: #66756C;
    --accent: #15A35A;
    --accent-strong: #0E8A4A;
    --accent-ink: #FFFFFF;
    --accent-soft: #E2F6EA;
    --accent-ring: rgba(21, 163, 90, .28);
    --chat-bg: #EFF3F1;
    --chat-dot: rgba(14, 26, 19, .045);
    --bubble-in: #FFFFFF;
    --bubble-out: #DAF6E4;
    --warn-bg: #FFF5D9;
    --warn-ink: #6B4E00;
    --error-bg: #FDE6E3;
    --error-ink: #8A1C12;
    --info-bg: #E6F0FF;
    --info-ink: #173E7A;
    --danger: #D23B30;
    --danger-ink: #FFFFFF;
    --ok: #15A35A;
    --read: #2F8FE0;
    --sh-1: 0 1px 2px rgba(14, 26, 19, .05), 0 1px 1px rgba(14, 26, 19, .03);
    --sh-2: 0 10px 30px -12px rgba(14, 26, 19, .18), 0 2px 6px rgba(14, 26, 19, .06);
    --sh-3: 0 24px 60px -20px rgba(14, 26, 19, .35);
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --side: 248px;
    --mbar: 58px;
    --tabbar: 64px;
    --ease: cubic-bezier(.2, .8, .3, 1);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #090E0B;
        --surface: #101713;
        --surface-2: #141D18;
        --surface-3: #1A251F;
        --line: #212D26;
        --line-strong: #2C3A32;
        --text: #E7EFEA;
        --text-2: #C3CFC8;
        --muted: #8C9B92;
        --accent: #25D366;
        --accent-strong: #3BE07A;
        --accent-ink: #04190D;
        --accent-soft: #11301F;
        --accent-ring: rgba(37, 211, 102, .3);
        --chat-bg: #0C1310;
        --chat-dot: rgba(255, 255, 255, .03);
        --bubble-in: #18221D;
        --bubble-out: #0F3D27;
        --warn-bg: #362B0C;
        --warn-ink: #F5D77A;
        --error-bg: #3A1512;
        --error-ink: #FFB4AC;
        --info-bg: #102540;
        --info-ink: #A9CBFF;
        --danger: #FF6B5E;
        --danger-ink: #2A0703;
        --ok: #25D366;
        --read: #53B8FF;
        --sh-1: 0 1px 2px rgba(0, 0, 0, .35);
        --sh-2: 0 12px 32px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
        --sh-3: 0 24px 60px -20px rgba(0, 0, 0, .8);
        color-scheme: dark;
    }
}

/* =====================================================================
   Base
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14.5px/1.5 Geist, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
a { color: var(--accent-strong); text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .78rem; font-weight: 650; margin-top: 22px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
p { margin: 0; }
ul, ol { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .86rem; }
.block { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
.ico { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-ring); }

/* Barras de desplazamiento finas y discretas. */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* =====================================================================
   Botones
   ===================================================================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 40px; padding: 0 16px;
    border: 1px solid var(--line-strong); border-radius: var(--r-sm);
    background: var(--surface); color: var(--text);
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
    box-shadow: var(--sh-1);
    transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 14px -6px var(--accent-ring); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn-danger-ghost { background: transparent; color: var(--danger); box-shadow: none; }
.btn-danger-ghost:hover { background: var(--error-bg); border-color: transparent; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: .86rem; }
.btn-small .ico { width: 16px; height: 16px; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
    border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn-sm { width: 28px; height: 28px; font-size: 1.1rem; border-radius: 8px; }

/* =====================================================================
   Formularios
   ===================================================================== */

.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: .86rem; font-weight: 600; color: var(--text-2); }
.field p, .field .muted { font-weight: 400; }
.field p b { font-weight: 650; }
:is(.field input, .field select, textarea, select, input[type="search"], input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"]) {
    width: 100%; min-height: 42px; padding: 9px 12px;
    border: 1px solid var(--line-strong); border-radius: var(--r-sm);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 400;
    transition: border-color .15s, box-shadow .15s;
}
:is(.field input, .field select, textarea, select, input):focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
textarea { resize: vertical; line-height: 1.5; }
input[type="file"] { font: inherit; font-size: .86rem; color: var(--muted); max-width: 100%; }
input[type="file"]::file-selector-button { font: inherit; font-weight: 600; margin-right: 10px; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface-2); color: var(--text); cursor: pointer; }
.form-error { color: var(--error-ink); background: var(--error-bg); padding: 9px 12px; border-radius: var(--r-sm); font-size: .88rem; }
.row-end { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; cursor: pointer; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.switch { position: relative; width: 46px; height: 26px; flex: none; border-radius: 99px; border: 0; background: var(--line-strong); cursor: pointer; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; cursor: pointer; }
.toggle-row p { margin-top: 4px; }

/* =====================================================================
   Avisos
   ===================================================================== */

.flashes { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; width: min(560px, calc(100% - 32px)); }
.crm-auth .flashes { position: static; transform: none; width: auto; }
.flash { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 11px 14px; border-radius: var(--r); box-shadow: var(--sh-2); background: var(--surface); border: 1px solid var(--line); animation: drop .25s var(--ease); }
.flash-success { border-left: 4px solid var(--accent); }
.flash-error { background: var(--error-bg); color: var(--error-ink); border-color: transparent; }
.flash-warning { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.flash-close { border: 0; background: none; color: inherit; font-size: 1.3rem; cursor: pointer; line-height: 1; opacity: .7; }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 11px 16px; font-size: .9rem; border-radius: var(--r); }
.banner-warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner-error { background: var(--error-bg); color: var(--error-ink); }
.banner-info { background: var(--info-bg); color: var(--info-ink); }
.banner a { color: inherit; font-weight: 600; }
.note-line { padding: 9px 12px; border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn-ink); }
.warn-list { display: grid; gap: 6px; justify-content: start; }
.warn-list ul { padding-left: 18px; display: grid; gap: 4px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: .76rem; font-weight: 650; white-space: nowrap; vertical-align: middle; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--accent-soft); color: var(--ok); }
.pill-wait { background: var(--warn-bg); color: var(--warn-ink); }
.pill-off { background: var(--surface-3); color: var(--muted); }
.pill-err { background: var(--error-bg); color: var(--error-ink); }

.chip {
    display: inline-flex; align-items: center; gap: 4px; max-width: 16ch;
    padding: 1px 8px; border-radius: 99px; font-size: .72rem; font-weight: 650;
    color: var(--tag, var(--accent));
    background: color-mix(in srgb, var(--tag, var(--accent)) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--tag, var(--accent)) 30%, transparent);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-toggle, .chip-check { cursor: pointer; font: inherit; font-size: .8rem; font-weight: 600; padding: 5px 11px; max-width: none; opacity: .6; transition: opacity .15s; }
.chip-toggle[aria-pressed="true"], .chip-check:has(input:checked) { opacity: 1; box-shadow: inset 0 0 0 1px var(--tag); }
.chip-toggle[aria-pressed="true"]::before { content: "\2713"; }
.chip-check input { accent-color: var(--tag); margin: 0 2px 0 0; }
.tag-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot-crm { background: var(--accent); }

/* =====================================================================
   Marco: menu lateral, barra movil, pestanas
   ===================================================================== */

.crm-app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.main { min-width: 0; display: flex; flex-direction: column; }

.sidenav {
    position: sticky; top: 0; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; gap: 6px; padding: 16px 12px;
    background: var(--surface); border-right: 1px solid var(--line);
}
.sidenav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--text); text-decoration: none; min-width: 0; }
.brand-logo { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 11px; background: linear-gradient(140deg, var(--accent), var(--accent-strong)); color: var(--accent-ink); box-shadow: 0 6px 16px -8px var(--accent-ring); }
.brand-logo .ico { width: 20px; height: 20px; }
.brand-text { display: grid; min-width: 0; line-height: 1.25; }
.brand-text b { font-size: .95rem; }
.brand-text em { font-style: normal; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidenav-links { display: grid; gap: 2px; }
.sidenav-links a, .sidenav-item {
    position: relative; display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px; border: 0; background: none; width: 100%;
    color: var(--text-2); font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; text-align: left;
    transition: background .15s, color .15s;
}
.sidenav-links a:hover, .sidenav-item:hover { background: var(--surface-3); color: var(--text); }
.sidenav-links a.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.sidenav-links a.is-active::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-badge { margin-left: auto; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-style: normal; font-size: .72rem; font-weight: 700; display: grid; place-items: center; font-variant-numeric: tabular-nums; }

.sidenav-foot { margin-top: auto; display: grid; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.live-dot { display: flex; align-items: center; gap: 10px; padding: 6px 12px; font-size: .8rem; color: var(--muted); }
.live-dot i { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.live-dot.is-on i { background: var(--ok); box-shadow: 0 0 0 4px var(--accent-soft); animation: pulse 2.4s infinite; }
.live-dot.is-off i { background: var(--danger); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px transparent; } }

.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.sidenav-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.sidenav-user:hover { background: var(--surface-3); }
.user-text { display: grid; min-width: 0; line-height: 1.25; }
.user-text b { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-text em { font-style: normal; font-size: .76rem; color: var(--muted); }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; font-size: .9rem; }
.usermenu-pop { position: absolute; left: 0; bottom: calc(100% + 6px); width: 240px; padding: 12px; display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-2); font-size: .9rem; z-index: 40; animation: drop .18s var(--ease); }
.usermenu-pop .muted { overflow-wrap: anywhere; }
.usermenu-pop a { padding: 6px 0; }

.mobilebar, .tabbar { display: none; }

/* Pantallas medianas: solo iconos en el menu, para darle espacio a la bandeja. */
@media (max-width: 1280px) and (min-width: 761px) {
    :root { --side: 76px; }
    .sidenav { padding: 16px 10px; align-items: center; }
    .sidenav-brand { padding: 4px 0 14px; }
    .brand-text, .sidenav-links a span, .sidenav-item span, .live-dot span, .user-text { display: none; }
    .sidenav-links, .sidenav-foot { width: 100%; }
    .sidenav-links a, .sidenav-item { justify-content: center; padding: 11px; }
    .sidenav-links a.is-active::before { left: -10px; }
    .nav-badge { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 17px; padding: 0 5px; font-size: .66rem; }
    .live-dot { justify-content: center; padding: 8px; }
    .sidenav-user { justify-content: center; }
}

/* =====================================================================
   Paginas y tarjetas
   ===================================================================== */

.page { width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 32px 64px; display: grid; gap: 20px; align-content: start; }
.page-wide { max-width: 1320px; }
.page-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-title p { margin-top: 6px; max-width: 72ch; }
.page-title h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.link-quiet { color: var(--muted); font-size: .88rem; text-decoration: none; font-weight: 550; }
.link-quiet:hover { color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px 22px; display: grid; gap: 14px; box-shadow: var(--sh-1); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-head p { margin-top: 4px; max-width: 64ch; }
.card-foot { display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); padding: 14px 22px 0; margin: 0 -22px; }
.empty-card { justify-items: start; padding: 32px; }
.list-empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: .92rem; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button, .tab-link { flex: none; border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 99px; font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, color .15s; }
.tabs button:hover, .tab-link:hover { color: var(--text); background: var(--surface-3); }
.tabs button[aria-selected="true"], .tab-link[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-strong); }
.tabs em { font-style: normal; font-variant-numeric: tabular-nums; opacity: .8; margin-left: 3px; }
.section-tabs { padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; justify-self: start; box-shadow: var(--sh-1); }

.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-3); border-radius: 99px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 99px; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

/* Tablas: tarjetas en el telefono (ver abajo). */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-1); }
.card .table-wrap { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table td .chip { margin: 0 4px 4px 0; }
.cell-end { text-align: right; white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; }

.modal { border: 0; border-radius: var(--r-xl); padding: 24px; width: min(440px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--sh-3); }
.modal::backdrop { background: rgba(5, 10, 7, .5); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .2s var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } }

.pop { position: relative; }
.pop summary { list-style: none; }
.pop summary::-webkit-details-marker { display: none; }
.pop-body { position: absolute; right: 0; top: 44px; z-index: 30; width: min(340px, calc(100vw - 32px)); padding: 16px; display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-2); animation: drop .18s var(--ease); }
.pop-body hr { border: 0; border-top: 1px solid var(--line); margin: 0; width: 100%; }

/* =====================================================================
   Bandeja
   ===================================================================== */

.inbox {
    height: 100vh; height: 100dvh;
    display: grid;
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "banner banner" "list chat";
}
.inbox.has-info { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr) 330px; grid-template-areas: "banner banner banner" "list chat info"; }
#numberBanner { grid-area: banner; border-radius: 0; }
.pane { min-height: 0; background: var(--surface); }
.pane-list { grid-area: list; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.pane-chat { grid-area: chat; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; }
.pane-info { grid-area: info; border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; display: grid; gap: 10px; align-content: start; }

.list-head { padding: 18px 16px 12px; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.list-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-title h1 { font-size: 1.3rem; }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--muted); transition: border-color .15s, box-shadow .15s; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); background: var(--surface); }
.search input, .search input:focus { border: 0; background: transparent; padding-left: 0; min-height: 40px; box-shadow: none; }
.list-filters { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tag-filter select { min-height: 30px; padding: 3px 10px; font-size: .8rem; border-radius: 99px; width: auto; max-width: 170px; }

.conv-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; display: grid; gap: 2px; align-content: start; }
.conv {
    position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 1px 12px; align-items: center;
    width: 100%; padding: 10px; border: 0; border-radius: 12px; background: none; color: inherit; text-align: left; font: inherit; cursor: pointer;
    transition: background .12s;
}
.conv:hover { background: var(--surface-3); }
.conv[aria-current="true"] { background: var(--accent-soft); }
.conv-avatar { grid-row: span 2; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--av, var(--muted)); color: #fff; font-weight: 700; font-size: .88rem; letter-spacing: .02em; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; justify-self: end; }
.conv-preview { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; gap: 6px; align-items: center; justify-self: end; }
.conv-tags { grid-column: 2 / -1; display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.conv.is-unread .conv-name { font-weight: 750; }
.conv.is-unread .conv-preview { color: var(--text-2); }
.conv.is-unread .conv-time { color: var(--accent-strong); font-weight: 650; }
.conv.is-new { animation: flashrow 1.6s var(--ease); }
@keyframes flashrow { 0% { background: var(--accent-soft); } }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 700; display: grid; place-items: center; }
.tag-agent { font-size: .68rem; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--muted); max-width: 10ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.chat-empty { margin: auto; text-align: center; display: grid; gap: 10px; justify-items: center; padding: 24px; color: var(--muted); max-width: 340px; }
.chat-empty .ico { width: 56px; height: 56px; padding: 14px; border-radius: 18px; background: var(--surface); color: var(--accent); box-shadow: var(--sh-1); }
.chat-empty h2 { color: var(--text); }

.chat { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 66px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-head .conv-avatar { grid-row: auto; width: 40px; height: 40px; }
.chat-who { display: grid; min-width: 0; flex: 1; line-height: 1.3; }
.chat-who b, .chat-who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-who span { font-size: .82rem; }
.assign select { min-height: 34px; padding: 4px 10px; font-size: .84rem; max-width: 190px; border-radius: 99px; }

.messages {
    flex: 1; overflow-y: auto; padding: 18px clamp(12px, 4vw, 56px);
    background-color: var(--chat-bg);
    background-image: radial-gradient(var(--chat-dot) 1px, transparent 1px);
    background-size: 18px 18px;
}
.messages ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.older { display: block; margin: 0 auto 12px; }
.day { align-self: center; position: sticky; top: 4px; z-index: 1; margin: 14px 0 8px; padding: 4px 12px; border-radius: 99px; background: var(--surface); color: var(--muted); font-size: .74rem; font-weight: 650; box-shadow: var(--sh-1); }
.msg { position: relative; max-width: min(72%, 600px); padding: 7px 11px 5px; border-radius: 14px; background: var(--bubble-in); box-shadow: var(--sh-1); align-self: flex-start; overflow-wrap: anywhere; animation: msgin .18s var(--ease); }
.msg.in { border-top-left-radius: 4px; }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 4px; }
@keyframes msgin { from { opacity: 0; transform: translateY(4px); } }
.msg-author { display: block; font-size: .72rem; font-weight: 700; color: var(--accent-strong); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; line-height: 1.45; }
.msg-foot { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 2px; font-size: .68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg-status { font-weight: 700; letter-spacing: -.1em; }
.msg-status.is-read { color: var(--read); }
.msg.is-failed { box-shadow: 0 0 0 1px var(--danger); }
.msg-error { font-size: .78rem; color: var(--danger); display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.msg-error button { border: 0; background: none; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; padding: 0; font-weight: 600; }
.media { display: grid; gap: 6px; margin: 2px 0 4px; }
.media img, .media video { max-width: 100%; max-height: 340px; border-radius: 10px; display: block; background: var(--surface-3); }
.media audio { width: min(290px, 100%); }
.media-load { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--surface-3) 70%, transparent); border: 0; color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; text-align: left; width: 100%; text-decoration: none; }
.media-load .ico { color: var(--accent); }
.media-gone { padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--surface-3) 70%, transparent); color: var(--muted); font-size: .84rem; font-style: italic; }
.media-actions { display: flex; gap: 12px; font-size: .74rem; }
.media-actions button, .media-actions a { border: 0; background: none; padding: 0; color: var(--accent-strong); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.media-saved { color: var(--muted); }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { min-height: 46px; max-height: 170px; resize: none; border-radius: 23px; padding: 12px 18px; background: var(--surface-2); }
.composer .btn { width: 46px; height: 46px; min-height: 46px; padding: 0; border-radius: 50%; flex: none; }

.info-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 6px 0 0; font-size: .86rem; padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; font-weight: 550; }
.marketing { display: grid; gap: 8px; justify-items: start; padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-new { display: flex; gap: 6px; }
.tag-new input { flex: 1; min-width: 0; min-height: 34px; padding: 6px 10px; font-size: .86rem; }
.notes { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 8px; }
.note { padding: 10px 12px; border-radius: var(--r); background: var(--warn-bg); color: var(--warn-ink); font-size: .87rem; }
.note-head { display: flex; justify-content: space-between; gap: 8px; font-size: .72rem; margin-bottom: 4px; opacity: .85; }
.note-head button { border: 0; background: none; color: inherit; cursor: pointer; text-decoration: underline; font: inherit; padding: 0; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.show-sm { display: none; }

/* =====================================================================
   Contactos
   ===================================================================== */

.contacts { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; align-items: start; }
.contacts > * { min-width: 0; }
.filters { display: grid; gap: 10px; position: sticky; top: 20px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-1); }
.filters h3 { margin-top: 10px; }
.filters .search input { min-width: 0; }
.filter-group { display: grid; gap: 2px; }
.filter-group a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 9px; color: var(--text-2); text-decoration: none; font-size: .9rem; flex: 1; min-width: 0; transition: background .12s; }
.filter-group a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-group a:hover { background: var(--surface-3); }
.filter-group a.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.filter-group em { font-style: normal; color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.tag-row { display: flex; align-items: center; gap: 2px; }
.contact-list { display: grid; gap: 10px; min-width: 0; }

.group-list { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 440px; overflow-y: auto; }
.group-item { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; transition: border-color .15s, background .15s; }
.group-item:hover { border-color: var(--line-strong); }
.group-item:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.group-item input { accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.group-item span { display: grid; }
.group-item em { font-style: normal; }

/* =====================================================================
   Campanas y publicaciones
   ===================================================================== */

.campaign-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.campaign-card { display: grid; gap: 12px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); color: var(--text); text-decoration: none; box-shadow: var(--sh-1); transition: border-color .15s, box-shadow .2s, transform .15s; align-content: start; }
.campaign-card:hover { border-color: var(--accent); box-shadow: var(--sh-2); transform: translateY(-1px); }
.campaign-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.campaign-nums { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.campaign-nums b { color: var(--text); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-strong)); border-radius: 99px; transition: width .5s var(--ease); }
.progress-lg { height: 10px; }

.campaign-form, .campaign-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.editor-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.editor-tools .muted { margin-left: auto; font-variant-numeric: tabular-nums; }
.image-current { display: flex; align-items: center; gap: 12px; }
.image-current img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--r); }
.audience { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; display: grid; gap: 10px; margin: 0; background: var(--surface); }
.audience legend { font-weight: 650; padding: 0 6px; }
.audience-count { font-weight: 650; color: var(--accent-strong); }

.phone { position: sticky; top: 20px; display: grid; gap: 10px; }
.phone-screen { min-height: 280px; padding: 18px 14px; border-radius: 28px; border: 8px solid var(--surface-3); background-color: var(--chat-bg); background-image: radial-gradient(var(--chat-dot) 1px, transparent 1px); background-size: 18px 18px; display: flex; flex-direction: column; box-shadow: var(--sh-2); }
.phone-msg { max-width: 94%; }
.phone-msg img { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 10px; margin-bottom: 6px; }

.launch input[type="datetime-local"] { width: auto; margin-left: 8px; min-height: 36px; padding: 4px 8px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.kpi { display: grid; gap: 2px; padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.kpi b { font-size: 1.45rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi span { font-size: .78rem; color: var(--muted); }

/* =====================================================================
   Ajustes
   ===================================================================== */

.number-body { display: grid; gap: 12px; }
.qr { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr img { width: 260px; height: 260px; border-radius: var(--r-lg); background: #fff; padding: 10px; box-shadow: var(--sh-2); }
.steps { padding-left: 20px; display: grid; gap: 8px; max-width: 36ch; }
.meter { position: relative; height: 12px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.meter-all { background: var(--muted); opacity: .4; }
.meter-crm { background: var(--accent); }
.meter-legend { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: .88rem; }
.cleanup { display: grid; gap: 14px; }
.cleanup-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cleanup-preview { padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); font-size: .9rem; }
.cleanup .btn-danger { justify-self: start; }
.rhythm { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; align-items: end; }
.rhythm .btn { grid-column: 1 / -1; justify-self: start; }

/* =====================================================================
   Entrada
   ===================================================================== */

.crm-auth {
    min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
    background:
        radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, var(--accent-soft), transparent 60%),
        var(--bg);
}
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 32px 30px; box-shadow: var(--sh-3); display: grid; gap: 16px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.brand-tag { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-strong); letter-spacing: .05em; }
.auth-title { font-size: 1.5rem; }
.auth-foot { font-size: .88rem; text-align: center; }
.account-pick { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-align: left; transition: border-color .15s; }
.account-pick:hover { border-color: var(--accent); }

/* =====================================================================
   Avisos en vivo: notificaciones flotantes y panel
   ===================================================================== */

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid; gap: 10px; width: min(360px, calc(100% - 32px)); }
.toast {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
    padding: 12px 14px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line);
    box-shadow: var(--sh-3); cursor: pointer; text-align: left; font: inherit; color: var(--text); width: 100%;
    animation: toastin .3s var(--ease);
}
.toast .conv-avatar { grid-row: span 2; width: 40px; height: 40px; font-size: .8rem; }
.toast b { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast span { font-size: .84rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 2 / -1; }
.toast em { grid-row: 1; grid-column: 3; font-style: normal; font-size: .66rem; font-weight: 700; color: var(--accent-strong); text-transform: uppercase; letter-spacing: .05em; }
.toast.is-assign { border-left: 4px solid var(--read); }
.toast.is-assign em { color: var(--read); }
.toast.is-out { animation: toastout .25s var(--ease) forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toastout { to { opacity: 0; transform: translateX(16px); } }

.notif-dialog { width: min(460px, calc(100% - 32px)); }
.notif-list { list-style: none; padding: 0; display: grid; gap: 4px; max-height: 260px; overflow-y: auto; }
.notif-list a { display: grid; gap: 1px; padding: 8px 10px; border-radius: 10px; color: var(--text); text-decoration: none; font-size: .88rem; }
.notif-list a:hover { background: var(--surface-3); }
.notif-list a span { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =====================================================================
   Tablet y telefono
   ===================================================================== */

@media (max-width: 1100px) {
    .inbox.has-info { grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); grid-template-areas: "banner banner" "list chat"; }
    .pane-info { position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100%); z-index: 50; box-shadow: var(--sh-3); animation: slidein .22s var(--ease); }
    .campaign-form, .campaign-layout { grid-template-columns: 1fr; }
    .phone { position: static; }
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } }

@media (max-width: 760px) {
    body { font-size: 15px; }
    .crm-app { grid-template-columns: minmax(0, 1fr); }
    .sidenav { display: none; }

    .mobilebar {
        display: flex; align-items: center; gap: 6px; position: sticky; top: 0; z-index: 40;
        height: var(--mbar); padding: 0 8px 0 12px;
        background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.4) blur(12px);
        border-bottom: 1px solid var(--line);
    }
    .mobilebar .sidenav-brand { padding: 0; flex: 1; }
    .mobilebar .brand-logo { width: 32px; height: 32px; border-radius: 10px; }
    .mobilebar .usermenu-pop { left: auto; right: 0; top: calc(100% + 6px); bottom: auto; }

    .tabbar {
        display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
        background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(12px);
        border-top: 1px solid var(--line);
    }
    .tabbar a { position: relative; display: grid; justify-items: center; align-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; }
    .tabbar a .ico { width: 22px; height: 22px; }
    .tabbar a.is-active { color: var(--accent-strong); }
    .tabbar a.is-active .ico { background: var(--accent-soft); border-radius: 99px; padding: 3px 14px; width: 52px; height: 28px; }
    .tabbar .nav-badge { position: absolute; top: 6px; left: calc(50% + 8px); min-width: 18px; height: 17px; padding: 0 5px; font-size: .64rem; margin: 0; }
    .main { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }

    .page { padding: 18px 14px 28px; gap: 16px; }
    h1 { font-size: 1.3rem; }
    .card { padding: 16px; border-radius: var(--r); }
    .card-foot { margin: 0 -16px; padding: 14px 16px 0; }
    .flashes { top: calc(var(--mbar) + 8px); }
    .toasts { left: 50%; right: auto; transform: translateX(-50%); top: calc(var(--mbar) + 8px); bottom: auto; }

    /* La bandeja: lista o chat, uno a la vez, entre las dos barras. */
    .inbox, .inbox.has-info { height: calc(100dvh - var(--mbar) - var(--tabbar) - env(safe-area-inset-bottom)); grid-template-columns: minmax(0, 1fr); grid-template-areas: "banner" "list"; }
    .pane-chat { display: none; }
    .inbox.is-chat .pane-list { display: none; }
    .inbox.is-chat .pane-chat { display: flex; grid-area: list; }
    .hide-sm { display: none; }
    .show-sm { display: inline-grid; }
    .msg { max-width: 88%; }
    .chat-head { padding: 8px; gap: 6px; min-height: 58px; }
    .chat-head .conv-avatar { display: none; }
    .assign select { max-width: 112px; }
    .messages { padding: 14px 10px; }
    .composer { padding-bottom: 10px; }

    .contacts { grid-template-columns: 1fr; gap: 14px; }
    .filters { position: static; padding: 12px; }
    .filter-group { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
    .filter-group a, .tag-row { flex: none; }
    .filter-group a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; font-size: .84rem; }
    .filters h3 { margin-top: 4px; }
    .tag-row form, .filters .tag-new { display: none; }

    /* Tablas como tarjetas: cada fila es un bloque, cada celda con su titulo. */
    .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 10px; box-shadow: var(--sh-1); }
    .table td { border: 0; padding: 4px 0; }
    .table td[data-label]::before { content: attr(data-label); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
    .table td.cell-end { text-align: left; padding-top: 8px; }
    .table tbody tr:hover { background: var(--surface); }

    .kpis { grid-template-columns: repeat(2, 1fr); }
    .kpi b { font-size: 1.2rem; }
    .rhythm, .cleanup-dates { grid-template-columns: 1fr 1fr; }
    .qr img { width: 220px; height: 220px; }
    .campaign-list { grid-template-columns: 1fr; }
    .page-title > .row-end { width: 100%; justify-content: flex-start; }
    .modal { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
