:root{font:15px/1.5 system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;color:#0f172a;background:#f8fafc;--brand:#0284c7;--border:#e2e8f0}
*{box-sizing:border-box}
body{margin:0}
body.app-layout{display:flex;min-height:100vh;background:#f8fafc}

/* SIDEBAR LATERAL */
.sidebar{width:240px;min-width:240px;background:#0f172a;color:#f8fafc;display:flex;flex-direction:column;border-right:1px solid #1e293b;position:sticky;top:0;height:100vh;padding:20px 14px;box-sizing:border-box}
.sidebar-header{padding-bottom:16px;border-bottom:1px solid #1e293b;margin-bottom:14px}
.logo{font-size:1.25rem;font-weight:800;letter-spacing:-0.02em;color:#38bdf8;margin:0}
.sidebar-nav{display:flex;flex-direction:column;gap:4px;flex:1;padding:0;border:none}
.nav-item{display:flex;align-items:center;gap:10px;width:100%;padding:10px 12px;background:transparent;color:#94a3b8;border:none;border-radius:8px;font-size:.88rem;font-weight:600;text-align:left;cursor:pointer;transition:all .15s ease}
.nav-item:hover{background:#1e293b;color:#f1f5f9}
.nav-item[aria-current=page]{background:#0284c7;color:#fff}
.nav-icon{font-size:1.05rem}
.sidebar-footer{border-top:1px solid #1e293b;padding-top:14px;font-size:.78rem}
.sidebar-auth input{font-size:.78rem;padding:7px 9px;background:#1e293b;border:1px solid #334155;color:#fff;border-radius:6px;margin-bottom:8px;width:100%}
.auth-buttons{display:flex;gap:6px}
.auth-btn{flex:1;padding:6px;font-size:.75rem;font-weight:600;border-radius:6px;background:#0284c7;color:#fff;border:none;cursor:pointer}
.auth-btn.secondary{background:#334155;color:#cbd5e1}
.auth-status{font-size:.72rem;color:#64748b;margin:6px 0 0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* MAIN CONTENT */
.main-content{flex:1;min-width:0;height:100vh;overflow-y:auto;padding:24px 32px;box-sizing:border-box}
#main{max-width:1150px;margin:0}
h1{font-size:1.6rem;margin:0}
h2{margin:0 0 14px;font-size:1.35rem;color:#0f172a}
h3{margin:0 0 14px;font-size:1rem;color:#1e293b}
.eyebrow{font-size:.7rem;font-weight:750;letter-spacing:.1em;color:#64748b;margin:0 0 4px}
.badge{font-size:.7rem;font-weight:700;border:1px solid #e2e8f0;background:#f1f5f9;border-radius:20px;padding:3px 8px;white-space:nowrap}
.notice{background:#fffbeb;border:1px solid #fef3c7;padding:12px 16px;border-radius:8px;color:#92400e;font-size:.85rem;margin-bottom:16px}
.hint{font-size:.8rem;color:#64748b;margin:6px 0 0}
.heading{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:16px}
.heading h2{margin-bottom:0}
.columns{display:grid;grid-template-columns:minmax(280px,360px) 1fr;gap:20px;align-items:start}
.card{background:#fff;border:1px solid var(--border);border-radius:10px;padding:18px;box-shadow:0 1px 3px rgba(0,0,0,0.04)}
.list{display:grid;gap:10px}
.list .card{padding:14px}
.list h3{margin-bottom:4px}
.meta{font-size:.8rem;color:#64748b;white-space:pre-wrap;overflow-wrap:anywhere}
label{display:block;font-size:.82rem;font-weight:650;margin-bottom:4px;color:#334155}
input,select,textarea{font:inherit;font-size:.86rem;border:1px solid #cbd5e1;border-radius:6px;background:#fff;padding:8px 10px;width:100%;color:inherit}
form>input,form>select,form>textarea{margin-bottom:12px}
textarea{resize:vertical}
.check{display:flex;gap:8px;align-items:center;margin:8px 0;font-weight:450;font-size:.82rem}
.check input{width:auto}
button{font:inherit;font-size:.84rem;font-weight:650;cursor:pointer;border:1px solid transparent;border-radius:6px;padding:8px 14px;color:#fff;background:var(--brand)}
button:hover{filter:brightness(.92)}
button:disabled{opacity:.55;cursor:wait}
.secondary{background:#fff;color:#334155;border-color:#cbd5e1}
.danger{background:#fff;color:#dc2626;border-color:#fca5a5}
.actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
:focus-visible{outline:2px solid #0284c7;outline-offset:2px}
[hidden]{display:none!important}
#feedback{color:#dc2626;min-height:22px;margin-bottom:10px;font-size:.85rem;font-weight:600}
#feedback.success{color:#16a34a}
pre{white-space:pre-wrap;overflow-wrap:anywhere;background:#f1f5f9;border:1px solid #e2e8f0;padding:12px;border-radius:6px;font-size:.82rem}
.skip{position:absolute;top:-100px;left:10px;background:#fff;padding:8px;z-index:99}
.skip:focus{top:10px}

/* MODALES */
.modal-backdrop{position:fixed;inset:0;background:rgba(15,23,42,0.65);backdrop-filter:blur(3px);display:flex;align-items:center;justify-content:center;z-index:999;padding:16px;box-sizing:border-box}
.modal-card{background:#fff;border-radius:12px;width:100%;max-width:620px;max-height:88vh;display:flex;flex-direction:column;box-shadow:0 20px 25px -5px rgba(0,0,0,0.25);overflow:hidden}
.modal-card.large{max-width:850px}
.modal-header{display:flex;justify-content:space-between;align-items:center;padding:14px 18px;border-bottom:1px solid #e2e8f0;background:#f8fafc}
.modal-header h3{margin:0;font-size:1.1rem;color:#0f172a}
.modal-close{background:transparent;border:none;font-size:1.4rem;cursor:pointer;color:#64748b;line-height:1;padding:2px 6px;border-radius:4px}
.modal-close:hover{background:#e2e8f0;color:#0f172a}
.modal-body{padding:18px;overflow-y:auto;flex:1}
.modal-footer{display:flex;justify-content:flex-end;gap:8px;padding:12px 18px;border-top:1px solid #e2e8f0;background:#f8fafc}

/* TABLA INTERACTIVA (CONTACTOS) */
.data-table-container{background:#fff;border:1px solid var(--border);border-radius:8px;overflow:hidden;box-shadow:0 1px 3px rgba(0,0,0,0.04)}
.data-table{width:100%;border-collapse:collapse;text-align:left;font-size:.84rem}
.data-table th{background:#f8fafc;padding:10px 12px;font-weight:700;color:#475569;border-bottom:1px solid #cbd5e1;cursor:pointer;user-select:none;white-space:nowrap}
.data-table th:hover{background:#e2e8f0;color:#0f172a}
.data-table td{padding:10px 12px;border-bottom:1px solid #f1f5f9;color:#334155;vertical-align:middle}
.data-table tbody tr{cursor:pointer;transition:background .15s}
.data-table tbody tr:hover{background:#f0fdf9}
.toolbar{display:flex;gap:10px;align-items:center;justify-content:space-between;flex-wrap:wrap;margin-bottom:12px}
.toolbar-left{display:flex;gap:8px;align-items:center;flex-wrap:wrap;flex:1}
.toolbar-right{display:flex;gap:8px;align-items:center}
.pagination-bar{display:flex;justify-content:space-between;align-items:center;padding:10px 14px;background:#f8fafc;border-top:1px solid #e2e8f0;font-size:.8rem;color:#64748b}
.tag-chip{display:inline-block;padding:2px 7px;background:#e0f2fe;color:#0369a1;border-radius:12px;font-size:.72rem;font-weight:600;margin-right:4px}

/* BANDEJA ESTILO WHATSAPP */
.inbox-subtabs{display:flex;gap:8px;margin-bottom:12px}
.inbox-tab-btn{padding:8px 16px;border-radius:6px;font-weight:700;font-size:.84rem;background:#e2e8f0;color:#475569;border:none;cursor:pointer}
.inbox-tab-btn.active{background:#0284c7;color:#fff}
.whatsapp-layout{display:flex;height:550px;background:#fff;border:1px solid var(--border);border-radius:10px;overflow:hidden;box-shadow:0 2px 8px rgba(0,0,0,0.06)}
.wa-sidebar{width:290px;min-width:290px;border-right:1px solid #e2e8f0;display:flex;flex-direction:column;background:#f8fafc}
.wa-sidebar-header{padding:10px;border-bottom:1px solid #e2e8f0}
.wa-chat-list{flex:1;overflow-y:auto}
.wa-chat-item{padding:10px 12px;border-bottom:1px solid #f1f5f9;cursor:pointer;display:flex;align-items:center;gap:10px;transition:background .15s}
.wa-chat-item:hover,.wa-chat-item.active{background:#e0f2fe}
.wa-avatar{width:36px;height:36px;border-radius:50%;background:#0284c7;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:.85rem;flex-shrink:0}
.wa-chat-main{flex:1;display:flex;flex-direction:column;background:#f0f2f5}
.wa-header{padding:10px 16px;background:#fff;border-bottom:1px solid #e2e8f0;display:flex;justify-content:space-between;align-items:center}
.wa-messages{flex:1;overflow-y:auto;padding:14px;display:flex;flex-direction:column;gap:8px;background:#f0f2f5}
.wa-msg{max-width:72%;padding:8px 12px;border-radius:8px;font-size:.84rem;line-height:1.4;position:relative;box-shadow:0 1px 1px rgba(0,0,0,0.08)}
.wa-msg.inbound{align-self:flex-start;background:#fff;color:#111b21;border-top-left-radius:0}
.wa-msg.outbound{align-self:flex-end;background:#d9fdd3;color:#111b21;border-top-right-radius:0}
.wa-time{font-size:.65rem;color:#667781;margin-top:3px;text-align:right}
.wa-footer{padding:10px 14px;background:#fff;border-top:1px solid #e2e8f0;display:flex;gap:8px;align-items:center}

/* CALENDARIO ESTILO GOOGLE CALENDAR (MATRIZ DÍA POR HORA) */
.gcal-toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;gap:8px;flex-wrap:wrap}
.gcal-matrix-wrapper{background:#fff;border:1px solid #cbd5e1;border-radius:10px;overflow:hidden;box-shadow:0 1px 4px rgba(0,0,0,0.06);display:flex;flex-direction:column}
.gcal-matrix-header{display:grid;grid-template-columns:70px repeat(7,minmax(110px,1fr));background:#f8fafc;border-bottom:1px solid #cbd5e1;position:sticky;top:0;z-index:3}
.gcal-header-tz{padding:10px 4px;font-size:0.7rem;font-weight:700;color:#94a3b8;text-align:center;border-right:1px solid #e2e8f0;display:flex;align-items:center;justify-content:center;background:#f8fafc}
.gcal-header-day{padding:8px 6px;text-align:center;font-weight:700;font-size:.76rem;color:#475569;border-right:1px solid #e2e8f0;display:flex;flex-direction:column;align-items:center;gap:2px;background:#f8fafc}
.gcal-header-day:last-child{border-right:none}
.gcal-header-day.today{color:#15803d}
.gcal-day-num{font-weight:700;font-size:.85rem;display:inline-block;width:24px;height:24px;line-height:24px;text-align:center;border-radius:50%}
.gcal-header-day.today .gcal-day-num{background:#16a34a;color:#fff}

.gcal-matrix-body{max-height:560px;overflow-y:auto;overflow-x:auto}
.gcal-matrix-table{min-width:840px}
.gcal-time-row{display:grid;grid-template-columns:70px repeat(7,minmax(110px,1fr));border-bottom:1px solid #f1f5f9;min-height:54px}
.gcal-time-row:hover{background:rgba(248,250,252,0.6)}
.gcal-time-label{font-size:.72rem;font-weight:600;color:#64748b;text-align:right;padding:6px 10px 0 0;border-right:1px solid #e2e8f0;user-select:none;background:#fafafa}
.gcal-cell{border-right:1px solid #f1f5f9;padding:2px 4px;position:relative;cursor:pointer;transition:background .12s;min-height:54px;display:flex;flex-direction:column;gap:3px}
.gcal-cell:last-child{border-right:none}
.gcal-cell:hover{background:#f0f9ff}
.gcal-cell.today-col{background:rgba(240,253,244,0.35)}
.gcal-cell.today-col:hover{background:#dcfce7}

.gcal-event-pill{background:#0284c7;color:#fff;border-radius:4px;padding:3px 6px;font-size:.72rem;line-height:1.25;cursor:pointer;font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,0.12);display:flex;flex-direction:column;gap:1px;transition:filter .15s}
.gcal-event-pill:hover{filter:brightness(.9)}
.gcal-event-time{font-size:.64rem;opacity:.92;font-weight:500}
.gcal-event-title{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* ASISTENTES & CHAT MODAL */
.assistant-list-item{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;background:#fff;border:1px solid var(--border);border-radius:8px;margin-bottom:8px}
.assistant-list-item h4{margin:0 0 2px;font-size:.92rem;color:#0284c7;display:flex;align-items:center;gap:6px}
.assistant-list-item p{margin:0;font-size:.78rem;color:#64748b}
.chat-window{display:flex;flex-direction:column;height:380px;background:#f8fafc;border:1px solid var(--border);border-radius:8px;overflow:hidden}
.chat-messages{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:8px}
.chat-msg{max-width:82%;padding:8px 12px;border-radius:8px;font-size:.85rem;line-height:1.4}
.chat-msg.user{align-self:flex-end;background:#0284c7;color:#fff;border-bottom-right-radius:2px}
.chat-msg.bot{align-self:flex-start;background:#fff;border:1px solid #e2e8f0;color:#1e293b;border-bottom-left-radius:2px}
.code-editor{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:.82rem;background:#0f172a;color:#f8fafc;tab-size:4;border-radius:6px;line-height:1.4;max-height:400px;overflow-y:auto}

@media(max-width:768px){
  body.app-layout{flex-direction:column}
  .sidebar{width:100%;min-width:100%;height:auto;position:static}
  .sidebar-nav{flex-direction:row;overflow-x:auto}
  .main-content{height:auto;padding:16px}
  .columns{grid-template-columns:1fr}
  .whatsapp-layout{flex-direction:column;height:auto}
  .wa-sidebar{width:100%;min-width:100%;height:200px}
}

/* User administration: keep labels next to their checkbox, not full-width. */
:is(#users, #modal-user-create, #modal-user-detail) fieldset { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:0.65rem; padding:1rem; border:1px solid #cbd5e1; border-radius:8px; }
:is(#users, #modal-user-create, #modal-user-detail) fieldset legend { padding:0 0.35rem; font-weight:600; }
:is(#users, #modal-user-create, #modal-user-detail) label:has(input[type="checkbox"]) { display:flex; flex-direction:row; align-items:center; gap:0.55rem; margin:0.4rem 0; }
:is(#users, #modal-user-create, #modal-user-detail) input[type="checkbox"] { display:inline-block; width:1.25rem; height:1.25rem; flex:0 0 auto; margin:0; }
#users-list { display:grid; gap:1rem; margin-top:1rem; }
#user-create-form { display:grid; gap:0.7rem; margin-bottom:1rem; }

/* Native user-create dialog: dedicated top layer, keyboard focus and mobile fit. */
:is(#modal-user-create, #modal-user-detail, #modal-self-password) { width:min(720px,calc(100vw - 2rem)); max-width:none; max-height:calc(100dvh - 2rem); padding:0; border:1px solid #cbd5e1; border-radius:12px; color:#0f172a; background:#fff; box-shadow:0 18px 55px #0f172a44; overflow:auto; }
:is(#modal-user-create, #modal-user-detail, #modal-self-password)::backdrop { background:rgb(15 23 42 / 55%); }
:is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-header { display:flex; align-items:center; justify-content:space-between; gap:1rem; padding:1rem 1.25rem; border-bottom:1px solid #e2e8f0; position:sticky; top:0; background:#fff; z-index:1; }
:is(#modal-user-create, #modal-user-detail, #modal-self-password) h2 { margin:0; }
:is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-body { padding:1.25rem; }
:is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-actions { display:flex; justify-content:flex-end; gap:.7rem; flex-wrap:wrap; }
#modal-user-create #user-create-feedback { min-height:1.3em; margin:.2rem 0; color:#b91c1c; }
@media(max-width:480px) { :is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-body { padding:1rem; } :is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-actions button { flex:1; } }

#users-list { list-style:none; padding:0; gap:.5rem; }
.users-row { display:grid; grid-template-columns:minmax(120px,1fr) 110px minmax(150px,1fr) auto; align-items:center; gap:.8rem; width:100%; padding:1rem; text-align:left; background:#fff; color:#0f172a; border:1px solid #cbd5e1; border-radius:8px; }
.users-row:hover { background:#eff6ff; border-color:#0284c7; }
.users-row:focus-visible { outline:3px solid #0284c7; outline-offset:2px; }
.users-row .user-status, .users-row .user-role { font-weight:400; }
.users-row .user-detail-hint { color:#0369a1; }
#user-detail-form, #user-detail-password-form { display:grid; gap:.8rem; margin-bottom:1rem; }
#user-detail-password-form { padding-top:1rem; border-top:1px solid #e2e8f0; }
#user-detail-feedback { min-height:1.3em; margin:.3rem 0; }
@media(max-width:600px) { .users-row { grid-template-columns:1fr auto; } .users-row .user-role { grid-column:1; } }
.users-row strong, .users-row .user-role { min-width:0; overflow-wrap:anywhere; }
:is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-header h2 { min-width:0; overflow-wrap:anywhere; }
:is(#modal-user-create, #modal-user-detail, #modal-self-password) .user-create-header > button { flex-shrink:0; }

#media-upload-form {display:flex;align-items:center;gap:.7rem;flex-wrap:wrap;margin:1rem 0;}
#media-upload-form input {width:auto;max-width:100%;}
#media-list {list-style:none;padding:0;display:grid;gap:.7rem;}
.media-row {display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:1rem;border:1px solid #cbd5e1;border-radius:8px;background:white;}
.media-row>div {min-width:0;overflow-wrap:anywhere;}.media-row p {margin:.3rem 0;}.media-row .actions {flex-shrink:0;}
@media(max-width:600px){.media-row{align-items:stretch;flex-direction:column;}.media-row .actions{display:flex;flex-wrap:wrap;}}

#self-password-feedback { min-height:1.3em; color:#b91c1c; }

/* Campaigns own their layout; no generic form/checkbox overrides. */
#campaigns fieldset {min-width:0;border:1px solid #cbd5e1;border-radius:8px;padding:.8rem;margin:.8rem 0;}
#campaign-contacts label {display:flex!important;align-items:center;gap:.6rem;overflow-wrap:anywhere;margin:.5rem 0;}
#campaign-contacts input[type="checkbox"] {width:1.3rem;height:1.3rem;flex:0 0 auto;}
#campaigns .actions {flex-wrap:wrap;}
#campaigns .card {display:block;min-width:0;}
#campaign-preview {max-width:100%;}

/* Inbox campaign dialog: scoped selectors, independent of other sections. */
#modal-inbox-campaign {width:min(950px,94vw);max-height:90vh;overflow:auto;border:1px solid #cbd5e1;border-radius:14px;padding:1.4rem;color:#0f172a;}
#modal-inbox-campaign::backdrop {background:rgba(15,23,42,.55);}
#modal-inbox-campaign .ic-heading {display:flex;justify-content:space-between;align-items:center;gap:1rem;}
#modal-inbox-campaign fieldset {min-width:0;border:1px solid #cbd5e1;border-radius:8px;padding:.8rem;margin:.8rem 0;}
#modal-inbox-campaign .ic-filters {display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:.6rem;}
#modal-inbox-campaign .actions {flex-wrap:wrap;gap:.5rem;}
#modal-inbox-campaign .check,#modal-inbox-campaign .ic-contact {display:flex;align-items:center;gap:.7rem;}
#modal-inbox-campaign input[type=checkbox] {width:1.3rem;height:1.3rem;flex:0 0 auto;}
#ic-contact-list {max-height:260px;overflow:auto;}
#modal-inbox-campaign .ic-contact {padding:.55rem;border-bottom:1px solid #e2e8f0;overflow-wrap:anywhere;}
#modal-inbox-campaign small {display:block;font-weight:400;}
#modal-inbox-campaign input,#modal-inbox-campaign select,#modal-inbox-campaign textarea {max-width:100%;box-sizing:border-box;}

/* HTML templates remain inside Inbox; no global HTML/style injection. */
#modal-html-template {width:min(1000px,94vw);max-height:90vh;overflow:auto;border:1px solid #cbd5e1;border-radius:14px;padding:1.2rem;color:#0f172a;}
#modal-html-template::backdrop {background:rgba(15,23,42,.55);}
#modal-html-template .ht-heading {display:flex;justify-content:space-between;align-items:center;gap:1rem;}
#modal-html-template .actions {flex-wrap:wrap;gap:.5rem;}
#ht-code {font-family:monospace;}
#ht-preview,#wa-html-frame,#ic-html-frame {width:100%;min-height:240px;border:1px solid #cbd5e1;background:white;}
#wa-html-template-wrap {padding:.6rem;background:#f8fafc;max-height:380px;overflow:auto;}

/* Explicit contrast and non-ambiguous login fields on the dark gatekeeper. */
#auth-gatekeeper-form label { color:#cbd5e1; }
#auth-gatekeeper-form input { background:#1e293b; color:#f8fafc; border:1px solid #64748b; caret-color:#f8fafc; }
#auth-gatekeeper-form input::placeholder { color:#94a3b8; opacity:1; }
#auth-gatekeeper-form input:focus-visible { outline:2px solid #38bdf8; outline-offset:2px; }

#automation-parameters-dialog { width:min(600px,calc(100vw - 2rem)); max-height:85vh; overflow:auto; border:1px solid #cbd5e1; border-radius:12px; padding:24px; background:#fff; color:#0f172a; }
#automation-parameters-dialog::backdrop { background:#0f172a99; }
#automation-parameters-dialog input { width:100%; margin:8px 0 16px; background:#fff; color:#0f172a; }

.automation-parameter-definition { display:grid; grid-template-columns:1fr 2fr auto auto; gap:12px; align-items:center; padding:12px; border:1px solid #cbd5e1; border-radius:8px; margin-bottom:12px; }
@media(max-width:700px){.automation-parameter-definition {grid-template-columns:1fr;} }
