/* ================================================================
   GestiónCom — Estilos principales
   ================================================================ */

:root {
    --sidebar-width:     240px;
    --sidebar-collapsed: 64px;
    --navbar-height:     56px;
    --sidebar-bg:        #12151e;
    --sidebar-text:      #a8b2c8;
    --sidebar-active-bg: rgba(67, 97, 238, 0.18);
    --sidebar-active:    #7da3ff;
    --sidebar-hover-bg:  rgba(255,255,255,0.06);
    --section-title:     #4a5568;
    --primary:           #4361ee;
    --primary-light:     #7da3ff;
    --body-bg:           #f0f2f8;
    --card-bg:           #ffffff;
    --text-muted-custom: #6b7280;
    --border-color:      #e2e8f0;
    --transition:        0.22s ease;
}

/* ── Reset / Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    color: #1e293b;
    overflow-x: hidden;
}

/* ── Navbar ────────────────────────────────────────────── */
.app-navbar {
    background: var(--sidebar-bg);
    height: var(--navbar-height);
    z-index: 1040;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.app-navbar .navbar-brand {
    font-size: 1.1rem;
    letter-spacing: .5px;
}
.app-navbar .btn-link { text-decoration: none; padding: .3rem .5rem; }
.app-navbar .dropdown-toggle::after { display: none; }

/* Avatar inicial */
.avatar-sm {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 700;
    flex-shrink: 0;
}

/* ── Layout wrapper ────────────────────────────────────── */
.app-wrapper {
    display: flex;
    margin-top: var(--navbar-height);
    min-height: calc(100vh - var(--navbar-height));
}

/* ── Sidebar ───────────────────────────────────────────── */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    flex-shrink: 0;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--transition);
    z-index: 1030;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.sidebar-inner { padding: 0 0 1.5rem; }

/* Sección title */
.nav-section-title {
    padding: .9rem 1.2rem .35rem;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--section-title);
    white-space: nowrap;
    overflow: hidden;
}

.nav-section { margin-bottom: .25rem; }

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem 1.2rem;
    color: var(--sidebar-text);
    border-radius: 0;
    font-size: .875rem;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}
.app-sidebar .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #e2e8f0;
}
.app-sidebar .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    font-weight: 600;
}
.app-sidebar .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--primary);
    border-radius: 0 2px 2px 0;
}

.nav-icon { font-size: 1.05rem; flex-shrink: 0; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* ── Ítem "Desarrollo a Medida" destacado ─────────────── */
.app-sidebar a[href*="/modules/amedida/"] {
    background: linear-gradient(90deg, rgba(250,204,21,.12), transparent);
    color: #fde68a !important;
}
.app-sidebar a[href*="/modules/amedida/"]:hover {
    background: linear-gradient(90deg, rgba(250,204,21,.22), transparent);
    color: #fef08a !important;
}
.app-sidebar a[href*="/modules/amedida/"] .bi-stars {
    color: #facc15 !important;
    filter: drop-shadow(0 0 4px rgba(250,204,21,.6));
}

/* ── Sidebar search ────────────────────────────────────── */
.sidebar-search {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--sidebar-bg);
    padding: .75rem .5rem .5rem;
}
.sidebar-search .form-control::placeholder { color: rgba(255,255,255,.35); }
.sidebar-search .form-control:focus { background: rgba(255,255,255,.08) !important; color: #fff; border-color: rgba(255,255,255,.25) !important; }
.sidebar-search .input-group-text { border-color: rgba(255,255,255,.15); }
.sidebar-search .form-control { border-color: rgba(255,255,255,.15); }
/* Ocultar buscador cuando el sidebar está colapsado */
body.sidebar-collapsed .sidebar-search { display: none; }

/* ── Sidebar colapsado ─────────────────────────────────── */
body.sidebar-collapsed .app-sidebar { width: var(--sidebar-collapsed); }
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-section-title,
body.sidebar-collapsed .badge { opacity: 0; pointer-events: none; }
body.sidebar-collapsed .app-sidebar .nav-link { justify-content: center; padding: .65rem; }
body.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed); }

/* ── Main ──────────────────────────────────────────────── */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    transition: margin-left var(--transition);
}

/* ── Page header ───────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    color: #0f172a;
}
.page-header .breadcrumb { margin: 0; font-size: .82rem; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: .9rem;
}

/* KPI Cards */
.kpi-card {
    border-radius: 14px;
    padding: 1.3rem 1.5rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.12);
}
.kpi-card .kpi-icon {
    position: absolute;
    right: 1rem; top: 50%;
    transform: translateY(-50%);
    font-size: 3.2rem;
    opacity: .18;
}
.kpi-card .kpi-label { font-size: .8rem; opacity: .9; text-transform: uppercase; letter-spacing: .5px; }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: 800; line-height: 1.2; margin: .25rem 0 .1rem; }
.kpi-card .kpi-sub   { font-size: .78rem; opacity: .8; }

.kpi-blue    { background: linear-gradient(135deg, #4361ee, #3a0ca3); }
.kpi-green   { background: linear-gradient(135deg, #2cb67d, #0d9488); }
.kpi-orange  { background: linear-gradient(135deg, #f77f00, #e63946); }
.kpi-purple  { background: linear-gradient(135deg, #7b2fbe, #4361ee); }
.kpi-gray    { background: linear-gradient(135deg, #6c757d, #495057); }

/* ── Tablas ────────────────────────────────────────────── */
.table { font-size: .87rem; }
.table thead th {
    background: #f8fafc;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted-custom);
    border-bottom: 2px solid var(--border-color);
    font-weight: 700;
}
.table tbody tr:hover { background-color: #f7f9ff; }

/* ── Badges de estado ──────────────────────────────────── */
.badge-activo    { background: #dcfce7; color: #166534; }
.badge-inactivo  { background: #fee2e2; color: #991b1b; }
.badge-pendiente { background: #fef9c3; color: #854d0e; }
.badge-admin     { background: #ede9fe; color: #5b21b6; }

/* ── Formularios ───────────────────────────────────────── */
.form-label { font-size: .85rem; font-weight: 600; color: #374151; }
.form-control, .form-select {
    border-radius: 8px;
    border-color: #d1d5db;
    font-size: .88rem;
    transition: border-color .15s, box-shadow .15s;
}
.form-control::placeholder { color: #c0c4cc; opacity: 1; }
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, .15);
}

/* ── Botones ───────────────────────────────────────────── */
.btn { border-radius: 8px; font-size: .87rem; font-weight: 500; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: #3652d4; border-color: #3652d4; }

/* ── DataTable custom ──────────────────────────────────── */
div.dataTables_wrapper div.dataTables_filter input { border-radius: 8px; }
div.dataTables_wrapper div.dataTables_length select { border-radius: 8px; }

/* ── Acciones de tabla ─────────────────────────────────── */
.table-actions .btn { padding: .25rem .5rem; font-size: .8rem; }

/* ── Switch toggle ─────────────────────────────────────── */
.form-switch .form-check-input { cursor: pointer; width: 2.2em; }

/* ── Responsive sidebar ────────────────────────────────── */
@media (max-width: 991.98px) {
    .app-sidebar {
        left: calc(-1 * var(--sidebar-width));
        transition: left var(--transition);
    }
    .app-sidebar.sidebar-open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
    .app-main { margin-left: 0 !important; }

    /* Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1029;
    }
    .sidebar-overlay.show { display: block; }
}

/* ── Utilidades ────────────────────────────────────────── */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cursor-pointer { cursor: pointer; }

/* ── Login page ────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #12151e 0%, #1e2a5e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 18px;
    padding: 2.5rem 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-brand {
    text-align: center;
    margin-bottom: 1.75rem;
}
.login-brand .brand-icon {
    width: 60px; height: 60px;
    background: linear-gradient(135deg, var(--primary), #3a0ca3);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: white;
    margin-bottom: .75rem;
}
.login-brand h1 { font-size: 1.5rem; font-weight: 800; color: #0f172a; margin: 0; }
.login-brand p  { color: var(--text-muted-custom); font-size: .88rem; margin: .25rem 0 0; }

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}
.empty-state i { font-size: 3.5rem; margin-bottom: 1rem; }

/* ── Kanban CRM ────────────────────────────────────────── */
.kanban-scroll {
    overflow-x: auto;
    padding-bottom: .5rem;
}
.kanban-board {
    display: flex;
    gap: 1rem;
    min-width: max-content;
    align-items: flex-start;
}
.kanban-col {
    width: 230px;
    flex-shrink: 0;
    background: #f8fafc;
    border-radius: .75rem;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}
.kanban-col-header {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .6rem .75rem;
    font-size: .82rem;
    border-bottom: 1px solid #e2e8f0;
}
.kanban-cards {
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    min-height: 60px;
}
.kanban-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: .5rem;
    padding: .65rem .75rem;
    cursor: pointer;
    transition: box-shadow .15s, transform .1s;
    font-size: .82rem;
}
.kanban-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    transform: translateY(-1px);
}
.kanban-card-actions {
    border-top: 1px solid #f1f5f9;
    padding-top: .4rem;
}
.btn-xs {
    padding: .15rem .4rem;
    font-size: .72rem;
    border-radius: .3rem;
}

/* ── Timeline actividades ──────────────────────────────── */
.timeline-item + .timeline-item {
    border-top: 1px solid #f1f5f9;
    padding-top: .75rem;
}

/* ── Campanita de notificaciones ──────────────────────── */
.notif-badge {
    position: absolute;
    top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    background: #dc3545;
    color: #fff;
    border-radius: 8px;
    font-size: .65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    border: 2px solid var(--primary);
    pointer-events: none;
}
.notif-menu {
    width: 340px;
    max-height: 480px;
    overflow-y: auto;
    padding: 0;
    border-radius: .6rem;
}
@media (max-width: 575px) {
    .notif-menu {
        position: fixed !important;
        top: 56px !important;
        right: 8px !important;
        left: 8px !important;
        width: auto !important;
        max-height: 70vh;
    }
}
.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: .6rem .6rem 0 0;
    font-size: .9rem;
}
.notif-item {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .6rem 1rem !important;
    border-bottom: 1px solid #f1f5f9;
    transition: background .12s;
    white-space: normal;
}
.notif-item:hover { background: #f8fafc; }
.notif-item:last-child { border-bottom: none; }
.notif-icon {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: .9rem;
}
.notif-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .4rem;
    padding: 1.8rem 1rem;
    color: #9ca3af;
    font-size: .85rem;
}
.notif-empty i { font-size: 1.8rem; }

/* ── Print helpers ─────────────────────────────────────── */
@media print {
    .print-only { display: block !important; }
    .no-print   { display: none  !important; }
    .app-sidebar, .app-navbar, .page-header .btn, .btn-group { display: none !important; }
    .app-main { margin-left: 0 !important; }
}
@media screen {
    .print-only { display: none !important; }
}
