/* ═══════════════════════════════════════════════════════════════
   CRM Sistemas — Estilos principales
   ═══════════════════════════════════════════════════════════════ */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 68px;
    --topbar-height: 60px;

    --primary:   #4361ee;
    --primary-dark: #3347c5;
    --secondary: #7209b7;
    --success:   #06d6a0;
    --warning:   #ffd166;
    --danger:    #ef233c;
    --info:      #4cc9f0;

    --sidebar-bg:      #0f172a;
    --sidebar-text:    #94a3b8;
    --sidebar-active:  #4361ee;
    --sidebar-hover:   rgba(67,97,238,.12);
    --sidebar-border:  rgba(255,255,255,.06);

    --body-bg:   #f1f5f9;
    --card-bg:   #ffffff;
    --text-main: #1e293b;
    --text-muted:#64748b;
    --border:    #e2e8f0;

    --radius:    10px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 10px 30px rgba(0,0,0,.08);

    --transition: .22s cubic-bezier(.4,0,.2,1);
}

/* ── Reset base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    color: var(--text-main);
    font-size: .9rem;
    overflow-x: hidden;
}

/* ══════════════════════════════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════════════════════════════ */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%234361ee' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: rgba(255,255,255,.97);
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0,0,0,.35);
    padding: 2.5rem;
    position: relative;
    z-index: 1;
}

.login-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #fff;
    margin: 0 auto 1.2rem;
    box-shadow: 0 8px 24px rgba(67,97,238,.4);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
    margin-bottom: .25rem;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
    margin-bottom: 1.8rem;
}

.form-floating label { color: var(--text-muted); }

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem rgba(67,97,238,.2);
}

.btn-login {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    color: #fff;
    font-weight: 600;
    padding: .75rem;
    border-radius: var(--radius);
    width: 100%;
    font-size: .95rem;
    letter-spacing: .02em;
    transition: var(--transition);
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(67,97,238,.4);
    color: #fff;
}

.btn-login:active { transform: translateY(0); }

.btn-login:disabled {
    opacity: .7;
    transform: none;
    cursor: not-allowed;
}

.ldap-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .72rem;
    background: rgba(67,97,238,.1);
    color: var(--primary);
    padding: .25rem .6rem;
    border-radius: 20px;
    font-weight: 600;
    border: 1px solid rgba(67,97,238,.2);
}

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

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    transition: width var(--transition);
    overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-header {
    padding: 1.1rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: var(--topbar-height);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    letter-spacing: -.01em;
}

.sidebar-brand i {
    font-size: 1.4rem;
    color: var(--primary);
    flex-shrink: 0;
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.1rem;
    padding: .3rem;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover { color: #fff; background: var(--sidebar-hover); }

/* Usuario en sidebar */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--sidebar-border);
    overflow: hidden;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: .9rem;
    flex-shrink: 0;
}

.user-info { overflow: hidden; }

.user-name {
    color: #e2e8f0;
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge-role {
    background: rgba(67,97,238,.25);
    color: #93c5fd;
    font-size: .65rem;
    font-weight: 500;
    padding: .15rem .45rem;
    border-radius: 4px;
}

/* Navegación */
.sidebar-nav {
    list-style: none;
    padding: .5rem 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.nav-item { position: relative; }

.nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1.2rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .85rem;
    font-weight: 500;
    border-radius: 0;
    transition: var(--transition);
    white-space: nowrap;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
}

.nav-link:hover {
    color: #e2e8f0;
    background: var(--sidebar-hover);
}

.nav-link.active {
    color: #fff;
    background: var(--primary);
}

.nav-link.active .nav-icon { color: #fff; }

.nav-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.nav-label { flex: 1; transition: opacity var(--transition); }

.nav-arrow {
    font-size: .65rem;
    transition: transform var(--transition);
}

.nav-link[aria-expanded="true"] .nav-arrow {
    transform: rotate(180deg);
}

/* Submenú */
.submenu {
    list-style: none;
    padding: .25rem 0;
    margin: 0;
    background: rgba(0,0,0,.15);
}

.submenu-link {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1.2rem .5rem 3rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .82rem;
    transition: var(--transition);
}

.submenu-link:hover { color: #e2e8f0; background: var(--sidebar-hover); }
.submenu-link.active { color: #93c5fd; }

/* Footer sidebar */
.sidebar-footer {
    padding: .5rem 0;
    border-top: 1px solid var(--sidebar-border);
}

/* Colapso de labels */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-arrow,
.sidebar.collapsed .user-info,
.sidebar.collapsed .sidebar-brand-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-user { justify-content: center; }
.sidebar.collapsed .user-avatar  { margin: 0; }

/* ── Contenido principal ─────────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
}

.main-wrapper.sidebar-collapsed { margin-left: var(--sidebar-collapsed-width); }

/* Topbar */
.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.topbar-title h6 { color: var(--text-main); }

.topbar-icon-btn {
    color: var(--text-muted);
    padding: .4rem;
    border-radius: 8px;
    transition: var(--transition);
    text-decoration: none;
}

.topbar-icon-btn:hover { background: var(--body-bg); color: var(--text-main); }

.topbar-avatar {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
}

/* Contenido */
.main-content {
    flex: 1;
    padding: 1.5rem;
}

/* ══════════════════════════════════════════════════════════════════
   COMPONENTES
══════════════════════════════════════════════════════════════════ */

/* Cards */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--card-bg);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Stat cards */
.stat-card {
    border-radius: var(--radius);
    padding: 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 4px;
    height: 100%;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.stat-card.primary::after { background: var(--primary); }
.stat-card.success::after { background: var(--success); }
.stat-card.warning::after { background: var(--warning); }
.stat-card.info::after    { background: var(--info); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.stat-icon.primary { background: rgba(67,97,238,.1);  color: var(--primary); }
.stat-icon.success { background: rgba(6,214,160,.1);  color: var(--success); }
.stat-icon.warning { background: rgba(255,209,102,.15);color: #e6a817; }
.stat-icon.info    { background: rgba(76,201,240,.1);  color: #1a9fc7; }

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text-main);
}

.stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-change {
    font-size: .75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .2rem;
}

.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* Botones */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* Tablas */
.table th {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.table td { font-size: .875rem; vertical-align: middle; }

/* Alerts */
.alert { border-radius: var(--radius); border: none; }
.alert-danger  { background: rgba(239,35,60,.08);  color: #b91c38; }
.alert-success { background: rgba(6,214,160,.08);  color: #047857; }
.alert-warning { background: rgba(255,209,102,.15);color: #92400e; }
.alert-info    { background: rgba(76,201,240,.1);  color: #0369a1; }

/* Loading spinner overlay */
.page-loader {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

/* Botón extra small */
.btn-xs {
    padding: .15rem .5rem;
    font-size: .75rem;
    border-radius: 5px;
    line-height: 1.4;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1050;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .main-wrapper { margin-left: 0 !important; }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 1040;
    }
    .sidebar-overlay.show { display: block; }
}
