/* ============================================================
   Campañas At Home — estilos base
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:      #22404e;
    --primary-dark: #183039;
    --primary-light:#345c6e;
    --accent:       #eab543;
    --sidebar-bg:   #1a1a2e;
    --sidebar-text: #c8ccd4;
    --sidebar-active: #22404e;
    --bg:           #f4f5f7;
    --white:        #ffffff;
    --border:       #e2e5ea;
    --text:         #1a1a2e;
    --text-muted:   #6b7280;
    --success:      #16a34a;
    --warning:      #d97706;
    --danger:       #dc2626;
    --info:         #2563eb;
    --radius:       8px;
    --shadow:       0 1px 4px rgba(0,0,0,.08);
    --shadow-md:    0 4px 12px rgba(0,0,0,.12);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Layout */
.app-layout   { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar          { width: 220px; background: var(--sidebar-bg); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; }
.sidebar-logo     { display: flex; align-items: center; gap: 10px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo-icon        { font-size: 22px; }
.logo-text        { color: #fff; font-weight: 700; font-size: 15px; }
.sidebar-nav      { flex: 1; padding: 14px 0; }
.nav-item         { display: flex; align-items: center; gap: 10px; padding: 10px 18px; color: var(--sidebar-text); text-decoration: none; font-size: 13.5px; transition: background .15s, color .15s; }
.nav-item:hover   { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active  { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-icon         { font-size: 15px; width: 18px; text-align: center; }
.sidebar-footer   { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user     { display: block; color: var(--sidebar-text); font-size: 12px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-link      { font-size: 12px; color: #e87474; text-decoration: none; }
.logout-link:hover{ text-decoration: underline; }

/* Main */
.main-content { margin-left: 220px; flex: 1; display: flex; flex-direction: column; }
.topbar       { background: var(--white); border-bottom: 1px solid var(--border); padding: 16px 28px; display: flex; align-items: center; gap: 12px; }
.page-title   { font-size: 18px; font-weight: 600; color: var(--text); }
.content-body { padding: 24px 28px; }

/* Cards */
.card         { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-title   { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 6px; }
.card-value   { font-size: 28px; font-weight: 700; color: var(--text); }

.stats-grid        { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px; }
.card-hoy          { border-top: 3px solid var(--primary); }
.dashboard-label   { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin: 20px 0 8px; }

/* Formularios */
.form-section  { margin-bottom: 28px; }
.form-label    { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-label .req { color: var(--primary); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 13.5px; color: var(--text);
    background: var(--white); transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--primary);
}
.form-textarea { resize: vertical; min-height: 110px; }
.form-hint     { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Campo bloqueado */
.locked-field  { background: #f8f9fa; border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; font-size: 13.5px; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; }
.lock-icon     { font-size: 12px; color: #9ca3af; }

/* Botones */
.btn           { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: var(--radius); font-size: 13.5px; font-weight: 500; cursor: pointer; border: none; text-decoration: none; transition: background .15s; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: 5px 12px; font-size: 12.5px; }

/* Badges de estado */
.badge         { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-pendiente  { background: #fef3c7; color: #92400e; }
.badge-activa     { background: #d1fae5; color: #065f46; }
.badge-pausada    { background: #e5e7eb; color: #374151; }
.badge-completada { background: #dbeafe; color: #1e40af; }
.badge-error      { background: #fee2e2; color: #991b1b; }
.badge-enviado    { background: #e0f2fe; color: #0369a1; }
.badge-entregado  { background: #d1fae5; color: #065f46; }
.badge-leido      { background: #ede9fe; color: #5b21b6; }
.badge-fallido    { background: #fee2e2; color: #991b1b; }
.badge-test       { background: #fef3c7; color: #78350f; border: 1px solid #fde68a; }
.badge-excel      { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-bbdd       { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* Tablas */
.table-wrap    { overflow-x: auto; }
table          { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th             { text-align: left; padding: 10px 14px; background: #f8f9fa; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
th.sortable    { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); background: #f0f1f3; }
th.sortable::after { content: ' ⇅'; opacity: .35; font-size: 11px; }
th.sortable[data-sort="asc"]::after  { content: ' ↑'; opacity: 1; color: var(--primary); }
th.sortable[data-sort="desc"]::after { content: ' ↓'; opacity: 1; color: var(--primary); }
td             { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
tr:last-child td { border-bottom: none; }
tr:hover td    { background: #fafafa; }

/* Upload */
.upload-area   { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary); background: #eef2f4; }
.upload-icon   { font-size: 28px; margin-bottom: 8px; }
.upload-text   { font-size: 13px; color: var(--text-muted); }
.upload-preview img { max-width: 100%; max-height: 200px; border-radius: var(--radius); margin-top: 10px; }

/* Alerta de destinatarios */
.destinatarios-box { background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.destinatarios-num { font-size: 22px; font-weight: 700; color: var(--primary); }
.destinatarios-label { font-size: 13px; color: var(--text-muted); }

/* Grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* Layout creación campaña: form + preview */
.campaign-layout { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.preview-sticky  { position: sticky; top: 24px; }

/* Preview WhatsApp */
.wa-preview       { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-md); overflow: hidden; }
.wa-preview-header{ background: #1a1a2e; color: #fff; padding: 10px 14px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.wa-phone-frame   { background: #e5ddd5; padding: 14px 12px; min-height: 280px; }
.wa-contact-bar   { background: #075e54; color: #fff; padding: 8px 12px; display: flex; align-items: center; gap: 10px; border-radius: 6px 6px 0 0; margin-bottom: 12px; }
.wa-avatar        { width: 32px; height: 32px; background: #128c7e; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.wa-contact-name  { font-size: 13px; font-weight: 600; }
.wa-contact-status{ font-size: 11px; color: #9de1db; }
.wa-bubble        { background: #fff; border-radius: 0 8px 8px 8px; padding: 0; max-width: 92%; box-shadow: 0 1px 2px rgba(0,0,0,.12); overflow: hidden; }
.wa-bubble-img-wrap { display: block; }
.wa-bubble-img      { width: 100%; height: auto; display: block; }
.wa-bubble-body   { padding: 8px 10px 4px; }
.wa-greeting      { font-size: 13px; color: #111; font-weight: 500; margin-bottom: 10px; }
.wa-message       { font-size: 13px; color: #333; white-space: pre-wrap; word-break: break-word; margin-bottom: 10px; }
.wa-fixed-text    { font-size: 12.5px; color: #555; }
.wa-separator     { border: none; border-top: 1px solid #e5e5e5; margin: 6px 0; }
.wa-footer        { font-size: 11.5px; color: #9ca3af; font-style: italic; padding: 4px 10px 8px; }
.wa-time          { text-align: right; font-size: 11px; color: #9ca3af; padding: 0 10px 6px; }
.wa-placeholder   { color: #aaa; font-style: italic; font-size: 13px; }
.wa-caption       { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* Sección de envío de prueba */
.test-send-row { display: flex; gap: 8px; align-items: flex-end; }
.prefix-select { width: 110px; }

/* Login */
.login-wrap   { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card   { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 40px 36px; width: 100%; max-width: 380px; }
.login-logo   { text-align: center; margin-bottom: 28px; }
.login-logo-icon { font-size: 40px; }
.login-logo-text { display: block; font-size: 20px; font-weight: 700; color: var(--text); margin-top: 6px; }
.login-logo-sub  { font-size: 13px; color: var(--text-muted); }
.login-form-title{ font-size: 15px; font-weight: 600; margin-bottom: 18px; }
.btn-block    { width: 100%; justify-content: center; }
.alert        { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-error  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success{ background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }

/* Selección de audiencia con radio buttons */
.audiencia-radios { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.audiencia-radio-label {
    display: flex; align-items: center; gap: 7px;
    padding: 8px 18px; cursor: pointer;
    font-size: 13px; font-weight: 500; color: var(--text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.audiencia-radio-label:hover { color: var(--text); }
.audiencia-radio-label:has(input:checked) {
    color: var(--primary); border-bottom-color: var(--primary); font-weight: 600;
}
.audiencia-radio-label input[type="radio"] {
    accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; flex-shrink: 0;
}

/* Zona de subida de Excel */
.excel-upload-area      { border: 2px dashed var(--border); border-radius: var(--radius);
                          padding: 28px; text-align: center; cursor: pointer;
                          transition: border-color .15s, background .15s; }
.excel-upload-area:hover,
.excel-upload-area.drag-over { border-color: var(--primary); background: #eef2f4; }
.excel-upload-area.excel-ok  { border-color: var(--success); background: #f0fdf4; }

/* Modal overlay */
.modal-overlay  { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
                  display: flex; align-items: center; justify-content: center;
                  padding: 16px; }
.modal-box      { background: var(--white); border-radius: var(--radius);
                  box-shadow: var(--shadow-md); width: 100%; max-width: 600px;
                  max-height: 80vh; display: flex; flex-direction: column; }
.modal-header   { padding: 14px 20px; border-bottom: 1px solid var(--border);
                  display: flex; justify-content: space-between; align-items: center; }
.modal-title    { font-size: 15px; font-weight: 600; color: var(--text); }
.modal-close    { background: none; border: none; font-size: 22px; line-height: 1;
                  cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-search   { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.modal-body     { flex: 1; overflow-y: auto; }
.modal-loading  { padding: 32px; text-align: center; color: var(--text-muted); font-size: 13px; }
.modal-footer   { padding: 8px 16px; border-top: 1px solid var(--border);
                  font-size: 12px; color: var(--text-muted); text-align: right; }

/* Barra de herramientas WhatsApp */
.wa-toolbar {
    display: flex; align-items: center; gap: 2px;
    padding: 5px 8px;
    background: #f8f9fa; border: 1px solid var(--border);
    border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
}
.wa-textarea { border-radius: 0 0 var(--radius) var(--radius) !important; }
.wa-tool {
    width: 30px; height: 28px; border: none; background: transparent;
    border-radius: 4px; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text); transition: background .12s; flex-shrink: 0;
}
.wa-tool:hover   { background: var(--border); }
.wa-tool.active  { background: #dbe4e8; color: var(--primary); }
.wa-toolbar-sep  { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.wa-toolbar-hint { font-size: 11px; color: var(--text-muted); margin-left: 6px; white-space: nowrap; }

/* Emoji picker */
.wa-emoji-wrap   { position: relative; }
.wa-emoji-picker {
    position: absolute; top: 34px; left: 0; z-index: 200;
    background: var(--white); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    padding: 8px; width: 264px;
    display: none; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.wa-emoji-picker.open { display: grid; }
.wa-emoji-btn {
    background: none; border: none; cursor: pointer;
    font-size: 19px; padding: 4px; border-radius: 4px;
    line-height: 1; transition: background .1s;
}
.wa-emoji-btn:hover { background: var(--bg); }

/* Hamburger (oculto en escritorio) */
.hamburger {
    display: none; flex-direction: column; justify-content: center; align-items: center;
    gap: 5px; width: 36px; height: 36px; padding: 0; border: none; background: none;
    cursor: pointer; border-radius: var(--radius); flex-shrink: 0;
}
.hamburger span { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; }
.hamburger:hover { background: var(--bg); }

/* Overlay lateral en móvil */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 150; }
.sidebar-overlay.open { display: block; }

/* Grids de dashboard */
.dash-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.dash-grid-5 { display: grid; grid-template-columns: repeat(5,1fr); gap: 16px; }

/* Cabecera detalle campaña */
.detail-header         { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.detail-header-meta    { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Utilidades de layout */
.list-actions       { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.form-actions       { display: flex; gap: 12px; justify-content: flex-end; }
.excel-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }

/* Aviso Meta */
.meta-warning {
    background: #fffbeb; border: 1px solid #fcd34d;
    border-left: 4px solid #f59e0b; border-radius: 8px;
    padding: 16px 20px; margin-bottom: 24px;
    display: flex; gap: 14px; align-items: flex-start;
}

/* ── Multiselect personalizado ─────────────────────────────── */
.ms-wrap    { position: relative; }
.ms-trigger {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--white); cursor: pointer; font-size: 13.5px; color: var(--text);
    user-select: none; transition: border-color .15s; min-height: 38px;
}
.ms-trigger:focus                    { outline: none; border-color: var(--primary); }
.ms-wrap.ms-open .ms-trigger        { border-color: var(--primary); }
.ms-value                            { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.ms-value.ms-placeholder             { color: var(--text-muted); }
.ms-arrow                            { font-size: 10px; color: var(--text-muted); transition: transform .15s; flex-shrink: 0; }
.ms-wrap.ms-open .ms-arrow          { transform: rotate(180deg); }
.ms-panel {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 110;
    background: var(--white); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    display: none; flex-direction: column; max-height: 260px;
}
.ms-wrap.ms-open .ms-panel          { display: flex; }
.ms-search-wrap                      { padding: 6px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.ms-search                           { width: 100%; padding: 6px 10px !important; font-size: 13px !important; border-radius: calc(var(--radius) - 2px) !important; }
.ms-list                             { overflow-y: auto; flex: 1; padding: 4px 0; }
.ms-option {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 12px; cursor: pointer; font-size: 13px; color: var(--text);
    transition: background .1s;
}
.ms-option:hover                     { background: var(--bg); }
.ms-option input[type="checkbox"]    { width: 14px; height: 14px; flex-shrink: 0; accent-color: var(--primary); cursor: pointer; margin: 0; }
.ms-option span                      { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-no-results                       { padding: 12px; text-align: center; color: var(--text-muted); font-size: 13px; display: none; }

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 900px) {
    .campaign-layout { grid-template-columns: 1fr; }
    .preview-sticky  { position: static; }
    .stats-grid      { grid-template-columns: 1fr 1fr 1fr; }
    .dash-grid-5     { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    /* Sidebar off-canvas */
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; z-index: 200; }
    .sidebar.open { transform: translateX(0); }

    /* Contenido principal */
    .main-content { margin-left: 0; }

    /* Topbar */
    .hamburger  { display: flex; }
    .topbar     { padding: 12px 16px; }
    .page-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

    /* Padding de contenido */
    .content-body { padding: 16px; }

    /* Stats grids */
    .stats-grid  { grid-template-columns: 1fr 1fr; }
    .dash-grid-3 { grid-template-columns: 1fr 1fr; }
    .dash-grid-5 { grid-template-columns: 1fr 1fr; }

    /* Grids de formularios */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

    /* Layout campaña */
    .campaign-layout { grid-template-columns: 1fr; }
    .preview-sticky  { position: static; }

    /* Fila de envío de prueba */
    .test-send-row        { flex-direction: column; }
    .test-send-row > *    { width: 100%; }
    .prefix-select        { width: 100%; }

    /* Acciones formulario */
    .form-actions .btn { flex: 1; justify-content: center; min-width: 120px; }

    /* Aviso Meta */
    .meta-warning { flex-direction: column; }

    /* Modal */
    .modal-box { max-width: 95vw; }

    /* ── Tablas: tarjetas (sin scroll horizontal) ── */
    .table-wrap    { overflow-x: visible; }
    table          { display: block; width: 100%; }
    table thead    { display: none; }
    table tbody    { display: block; }
    table tbody tr {
        display: block; border: 1px solid var(--border); border-radius: var(--radius);
        box-shadow: var(--shadow); margin-bottom: 8px; background: var(--white);
    }
    table tbody tr:last-child { margin-bottom: 0; }
    table tbody td {
        display: flex; justify-content: space-between; align-items: center;
        padding: 9px 14px; border-bottom: 1px solid #f0f0f0; text-align: right;
        font-size: 13px; gap: 10px;
    }
    table tbody td:last-child               { border-bottom: none; }
    table tbody tr:last-child td            { border-bottom: 1px solid #f0f0f0; }
    table tbody tr:last-child td:last-child { border-bottom: none; }
    table tbody tr:hover td                 { background: transparent !important; }
    table tbody td::before {
        content: attr(data-label); font-weight: 600; font-size: 11px;
        color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
        text-align: left; flex-shrink: 0; white-space: nowrap;
    }
    /* Celda de acciones: mostrar botones en columna */
    td[data-label="Acciones"] { flex-direction: column; align-items: flex-start; gap: 6px; }
}

@media (max-width: 480px) {
    .stats-grid, .dash-grid-3, .dash-grid-5 { grid-template-columns: 1fr; }
    .card-value   { font-size: 22px; }
    .topbar       { padding: 10px 12px; }
    .content-body { padding: 12px; }
    .page-title   { font-size: 14px; }
    .form-actions { flex-wrap: wrap; }
    .form-actions .btn { width: 100%; flex: none; }
}
