/* ============================================================
   TIUNA CRM — Design System v1.7.0
   Basado en: Corporate Modern — Core Enterprise Design System
   Tipografía: Inter (UI) + JetBrains Mono (datos técnicos)
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Variables CSS (Design Tokens) --- */
:root {
    /* Colores principales */
    --color-sidebar:        #0F172A;
    --color-sidebar-hover:  #1E293B;
    --color-sidebar-active: #0D9488;
    --color-sidebar-texto:  #94A3B8;
    --color-sidebar-texto-activo: #FFFFFF;

    --color-accion:         #0D9488;
    --color-accion-hover:   #0f766e;
    --color-accion-light:   rgba(13,148,136,.1);

    --color-fondo:          #F8F9FF;
    --color-surface:        #FFFFFF;
    --color-surface-alt:    #F1F5F9;
    --color-borde:          #E2E8F0;
    --color-borde-focus:    #0D9488;

    --color-texto:          #0B1C30;
    --color-texto-muted:    #64748B;
    --color-texto-light:    #94A3B8;

    --color-secundario:     #3B82F6;
    --color-peligro:        #EF4444;
    --color-advertencia:    #F59E0B;
    --color-exito:          #10B981;

    /* Status */
    --status-activo-bg:     #DCFCE7;
    --status-activo-text:   #15803D;
    --status-suspendido-bg: #FEF3C7;
    --status-suspendido-text: #B45309;
    --status-cortado-bg:    #FEE2E2;
    --status-cortado-text:  #B91C1C;
    --status-inactivo-bg:   #F1F5F9;
    --status-inactivo-text: #64748B;

    /* Canales */
    --canal-whatsapp:   #25D366;
    --canal-sms:        #3B82F6;
    --canal-telegram:   #0088CC;
    --canal-email:      #6B7280;
    --canal-facebook:   #1877F2;
    --canal-instagram:  #E1306C;

    /* Layout */
    --sidebar-width:    220px;
    --navbar-height:    60px;
    --content-padding:  24px;

    /* Tipografía */
    --font-ui:          'Inter', system-ui, sans-serif;
    --font-mono:        'JetBrains Mono', monospace;

    /* Espaciado */
    --sp-xs:  8px;
    --sp-sm:  12px;
    --sp-md:  16px;
    --sp-lg:  24px;
    --sp-xl:  32px;

    /* Radios */
    --radius-sm:  4px;
    --radius-md:  6px;
    --radius-lg:  8px;
    --radius-xl:  12px;
    --radius-pill: 9999px;

    /* Sombras */
    --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,.08);
    --shadow-lg:  0 10px 30px rgba(0,0,0,.12);

    /* Transiciones */
    --transition: all .2s ease;
}

/* --- Reset Mínimo --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: var(--font-ui);
    background: var(--color-fondo);
    color: var(--color-texto);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-accion); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-logo {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-logo-img {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    object-fit: contain;
    background: rgba(255,255,255,.1);
}
.sidebar-logo-text { line-height: 1.2; }
.sidebar-logo-text strong {
    display: block;
    color: #FFFFFF;
    font-size: 0.9375rem;
    font-weight: 700;
}
.sidebar-logo-text span {
    font-size: 0.6875rem;
    color: var(--color-sidebar-texto);
    font-weight: 400;
}

.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-section-label {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: rgba(148,163,184,.5);
    padding: 16px 16px 6px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--color-sidebar-texto);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
    text-decoration: none;
}
.sidebar-item:hover {
    background: var(--color-sidebar-hover);
    color: #FFFFFF;
    text-decoration: none;
}
.sidebar-item.activo {
    background: rgba(13,148,136,.15);
    color: #FFFFFF;
    border-left-color: var(--color-accion);
}
.sidebar-item i { width: 18px; text-align: center; font-size: 0.875rem; }
.sidebar-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: #EF4444;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--color-accion);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user-info { line-height: 1.25; min-width: 0; }
.sidebar-user-info strong {
    display: block;
    color: #FFFFFF;
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-info span {
    font-size: 0.6875rem;
    color: var(--color-sidebar-texto);
    text-transform: capitalize;
}

/* --- ÁREA DE CONTENIDO --- */
.content-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- NAVBAR SUPERIOR --- */
.navbar-top {
    height: var(--navbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-borde);
    display: flex;
    align-items: center;
    padding: 0 var(--content-padding);
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 12px;
}
.navbar-search {
    flex: 1;
    max-width: 420px;
    position: relative;
}
.navbar-search input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1.5px solid var(--color-borde);
    border-radius: var(--radius-pill);
    font-size: 0.875rem;
    font-family: var(--font-ui);
    color: var(--color-texto);
    background: var(--color-fondo);
    transition: var(--transition);
}
.navbar-search input:focus {
    outline: none;
    border-color: var(--color-borde-focus);
    box-shadow: 0 0 0 3px var(--color-accion-light);
    background: #fff;
}
.navbar-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-texto-light);
    font-size: 0.875rem;
}
.navbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.navbar-btn-icon {
    width: 36px; height: 36px;
    border: none; background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-texto-muted);
    font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
    position: relative;
}
.navbar-btn-icon:hover { background: var(--color-fondo); color: var(--color-texto); }
.badge-notif {
    position: absolute;
    top: 4px; right: 4px;
    width: 8px; height: 8px;
    background: var(--color-peligro);
    border-radius: 50%;
    border: 2px solid white;
}
.navbar-divider { width: 1px; height: 24px; background: var(--color-borde); }

/* --- ÁREA MAIN --- */
.content-main {
    flex: 1;
    padding: var(--content-padding);
    overflow-y: auto;
}

/* --- HEADER DE MÓDULO --- */
.modulo-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--sp-lg);
    gap: var(--sp-md);
    flex-wrap: wrap;
}
.modulo-header-info h1 {
    font-size: 1.625rem;
    font-weight: 700;
    color: var(--color-texto);
    letter-spacing: -0.01em;
    line-height: 1.2;
}
.modulo-header-info p {
    font-size: 0.875rem;
    color: var(--color-texto-muted);
    margin-top: 4px;
}
.modulo-header-acciones { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   COMPONENTES: CARDS
   ============================================================ */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-borde);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: var(--sp-md) var(--sp-lg);
    border-bottom: 1px solid var(--color-borde);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-texto);
}
.card-body { padding: var(--sp-lg); }
.card-footer {
    padding: var(--sp-sm) var(--sp-lg);
    border-top: 1px solid var(--color-borde);
    background: var(--color-surface-alt);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--sp-md);
    margin-bottom: var(--sp-lg);
}
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-borde);
    border-radius: var(--radius-lg);
    padding: var(--sp-lg);
    box-shadow: var(--shadow-sm);
}
.kpi-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--color-texto-muted);
    margin-bottom: 8px;
}
.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-texto);
    line-height: 1;
    font-family: var(--font-mono);
}
.kpi-value.peligro { color: var(--color-peligro); }
.kpi-value.exito   { color: var(--color-exito); }
.kpi-delta {
    font-size: 0.75rem;
    color: var(--color-texto-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ============================================================
   COMPONENTES: BOTONES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-ui);
    border-radius: var(--radius-md);
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary  { background: var(--color-accion);     color: #fff; border-color: var(--color-accion); }
.btn-primary:hover { background: var(--color-accion-hover); }

.btn-secondary { background: transparent; color: var(--color-accion); border-color: var(--color-accion); }
.btn-secondary:hover { background: var(--color-accion-light); }

.btn-ghost { background: transparent; color: var(--color-texto-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--color-fondo); color: var(--color-texto); }

.btn-danger { background: transparent; color: var(--color-peligro); border-color: var(--color-peligro); }
.btn-danger:hover { background: #FEF2F2; }

.btn-sm { padding: 5px 11px; font-size: 0.8125rem; }
.btn-lg { padding: 11px 22px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================================================
   COMPONENTES: STATUS CHIPS
   ============================================================ */
@keyframes chip-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(185,28,28,.45); }
    70%  { box-shadow: 0 0 0 7px rgba(185,28,28,0); }
    100% { box-shadow: 0 0 0 0 rgba(185,28,28,0); }
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .5; transform: scale(1.4); }
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chip-activo      { background: var(--status-activo-bg);      color: var(--status-activo-text); }
.chip-suspendido  { background: var(--status-suspendido-bg);   color: var(--status-suspendido-text); }
.chip-cortado     { background: var(--status-cortado-bg);      color: var(--status-cortado-text);
                    animation: chip-pulse 1.8s ease-out infinite; }
.chip-inactivo    { background: var(--status-inactivo-bg);     color: var(--status-inactivo-text); }

/* ---- Status Badge (tabla de clientes) — versión icónica grande ---- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    border: 1.5px solid transparent;
    transition: transform .15s, box-shadow .15s;
}
.status-badge:hover { transform: translateY(-1px); }

.status-badge .sb-icon {
    font-size: 0.9rem;
    line-height: 1;
}
.status-badge .sb-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* Variantes */
.status-badge.sb-activo {
    background: var(--status-activo-bg);
    color: var(--status-activo-text);
    border-color: #86efac;
}
.status-badge.sb-activo .sb-dot {
    background: #16a34a;
}
.status-badge.sb-suspendido {
    background: var(--status-suspendido-bg);
    color: var(--status-suspendido-text);
    border-color: #fcd34d;
}
.status-badge.sb-cortado {
    background: #FEE2E2;
    color: #991B1B;
    border-color: #fca5a5;
    animation: chip-pulse 1.6s ease-out infinite;
}
.status-badge.sb-cortado .sb-dot {
    background: #dc2626;
    animation: pulse-dot 1.2s ease-in-out infinite;
}
.status-badge.sb-inactivo {
    background: var(--status-inactivo-bg);
    color: var(--status-inactivo-text);
    border-color: #e2e8f0;
}

/* Channel chips */
.chip-canal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    border-radius: 50%;
    font-size: 0.75rem;
    color: #fff;
    title: attr(title);
}
.chip-canal.whatsapp  { background: var(--canal-whatsapp); }
.chip-canal.sms       { background: var(--canal-sms); }
.chip-canal.telegram  { background: var(--canal-telegram); }
.chip-canal.email     { background: var(--canal-email); }
.chip-canal.facebook  { background: var(--canal-facebook); }
.chip-canal.instagram { background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888); }

/* ============================================================
   COMPONENTES: TABLA
   ============================================================ */
.tabla-wrapper { overflow-x: auto; border-radius: var(--radius-lg); }
.tabla-crm {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.tabla-crm thead th {
    background: var(--color-fondo);
    padding: 10px 14px;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--color-texto-muted);
    border-bottom: 2px solid var(--color-borde);
    white-space: nowrap;
}
.tabla-crm tbody tr {
    border-bottom: 1px solid var(--color-borde);
    transition: background .15s;
}
.tabla-crm tbody tr:hover { background: #F8FAFC; }
.tabla-crm tbody td { padding: 12px 14px; vertical-align: middle; }
.tabla-crm tbody tr:last-child { border-bottom: none; }

/* Avatar con iniciales */
.cliente-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.cliente-nombre { font-weight: 600; color: var(--color-texto); }
.cliente-id     { font-size: 0.75rem; color: var(--color-texto-muted); font-family: var(--font-mono); }

/* ============================================================
   COMPONENTES: FORMULARIOS
   ============================================================ */
.form-group { margin-bottom: var(--sp-md); }
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-texto);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.form-label.requerido::after { content: ' *'; color: var(--color-peligro); }
.form-control {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--color-borde);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-family: var(--font-ui);
    color: var(--color-texto);
    background: var(--color-surface);
    transition: var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--color-borde-focus);
    box-shadow: 0 0 0 3px var(--color-accion-light);
}
.form-control.error { border-color: var(--color-peligro); }
.form-error { font-size: 0.8125rem; color: var(--color-peligro); margin-top: 4px; }
.form-hint  { font-size: 0.8125rem; color: var(--color-texto-muted); margin-top: 4px; }
select.form-control { appearance: none; cursor: pointer; }
textarea.form-control { min-height: 100px; resize: vertical; }

/* ============================================================
   COMPONENTES: ALERTAS FLASH
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: var(--sp-md);
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: #F0FDF4; border: 1px solid #BBF7D0; color: #15803D; }
.alert-error   { background: #FEF2F2; border: 1px solid #FECACA; color: #B91C1C; }
.alert-warning { background: #FFFBEB; border: 1px solid #FDE68A; color: #B45309; }
.alert-info    { background: #EFF6FF; border: 1px solid #BFDBFE; color: #1D4ED8; }

/* ============================================================
   UTILIDADES
   ============================================================ */
.text-mono  { font-family: var(--font-mono); }
.text-muted { color: var(--color-texto-muted); }
.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.fw-bold    { font-weight: 700; }
.fw-semi    { font-weight: 600; }
.d-flex     { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm     { gap: var(--sp-sm); }
.gap-md     { gap: var(--sp-md); }
.mb-md      { margin-bottom: var(--sp-md); }
.mb-lg      { margin-bottom: var(--sp-lg); }
.mt-md      { margin-top: var(--sp-md); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-md); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-md); }
