/* ============================================
   SISTEMA ACADÉMICO - ESTILOS PRINCIPALES
   ============================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;
    --light: #f8fafc;
    --dark: #1e293b;
    --sidebar: #1e293b;
    --sidebar-width: 260px;
    --header-height: 60px;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f1f5f9;
    color: var(--dark);
    line-height: 1.6;
}

img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

/* ============================================
   LOGIN
   ============================================ */
.login-body {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

.login-box {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.login-box .logo {
    text-align: center;
    margin-bottom: 30px;
}

.login-box .logo h1 {
    color: var(--primary);
    font-size: 1.8rem;
    font-weight: 700;
}

.login-box .logo p {
    color: var(--secondary);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.2s;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #475569; }

.btn-sm { padding: 8px 16px; font-size: 0.85rem; }

.btn-block { width: 100%; }

.alert {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

.alert-icon { font-size: 1.2rem; font-weight: bold; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.sidebar-header h2 {
    font-size: 1.1rem;
    color: white;
}

.sidebar-header p {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
}

.sidebar-menu {
    list-style: none;
    padding: 15px 0;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-menu li {
    margin: 2px 0;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: rgba(255,255,255,0.08);
    color: white;
    border-left-color: var(--primary);
}

.sidebar-menu .icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
}

.sidebar-footer {
    padding: 10px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: var(--sidebar);
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.8rem;
}

.user-details { flex: 1; min-width: 0; }
.user-details .name { font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-details .role { font-size: 0.65rem; color: rgba(255,255,255,0.5); text-transform: capitalize; }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.content {
    flex: 1;
    min-width: 0;
}

/* Header */
.top-header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    margin-right: 12px;
}

.menu-toggle:hover { background: var(--light); }

.menu-toggle span {
    display: block;
    width: 100%;
    height: 3px;
    background: var(--dark);
    border-radius: 2px;
    transition: all 0.3s;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

.sidebar-overlay.active { display: block; }

.header-left h1 {
    font-size: 1.3rem;
    color: var(--dark);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.badge {
    position: relative;
    padding: 8px;
    border-radius: 10px;
    background: var(--light);
    cursor: pointer;
    font-size: 1.1rem;
}

.badge-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Content Area */
.content {
    padding: 30px;
}

.page-title {
    font-size: 1.5rem;
    margin-bottom: 24px;
    color: var(--dark);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s;
}

.stat-card:hover { transform: translateY(-2px); }

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

.stat-icon.blue { background: #dbeafe; }
.stat-icon.green { background: #d1fae5; }
.stat-icon.orange { background: #ffedd5; }
.stat-icon.purple { background: #f3e8ff; }
.stat-icon.red { background: #fee2e2; }

.stat-info h3 {
    font-size: 1.6rem;
    color: var(--dark);
}

.stat-info p {
    font-size: 0.85rem;
    color: var(--secondary);
}

/* Cards */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: visible;
    max-width: 100%;
}
.card-header {
    border-radius: 12px 12px 0 0;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.card-header h2 {
    font-size: 1.1rem;
    color: var(--dark);
    min-width: 0;
    overflow-wrap: break-word;
}

.card-body {
    padding: 24px;
}

/* Tables */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; display: block; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: unset;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--secondary);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table td {
    font-size: 0.9rem;
}

/* Status Badges */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
}

.status-active { background: #d1fae5; color: #065f46; }
.status-inactive { background: #fee2e2; color: #991b1b; }
.status-pending { background: #fef3c7; color: #92400e; }

/* Asistencia Indicadores */
.asistencia-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 0.9rem;
}

.tag-asistio { background: #d1fae5; color: #065f46; }
.tag-falta { background: #fee2e2; color: #991b1b; }
.tag-justificado { background: #dbeafe; color: #1e40af; }
.tag-retardo { background: #fef3c7; color: #92400e; }

/* Search & Filters */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-bar .form-control { flex: 1; min-width: 200px; }

/* Grid layouts */
.grid-1 { display: grid; grid-template-columns: 1fr; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-2 > div { min-width: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-3 > div { min-width: 0; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.grid-4 > div { min-width: 0; }

/* Chat */
.chat-container {
    display: flex;
    height: 600px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.chat-sidebar {
    width: 280px;
    background: #f8fafc;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: white;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
}

.message {
    max-width: 70%;
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
}

.message-sent {
    background: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message-received {
    background: white;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-input {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border);
}

.chat-input .form-control { flex: 1; }

/* Calificaciones Grid */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
}

.cal-item {
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid var(--border);
}

.cal-item .label { font-size: 0.7rem; color: var(--secondary); text-transform: uppercase; }
.cal-item .value { font-size: 1.2rem; font-weight: 700; color: var(--dark); }

/* Rendimiento */
.rendimiento-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 6px;
}

.rendimiento-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-weight: 500;
    color: var(--secondary);
    white-space: nowrap;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary);
}

/* ============================================
   RESPONSIVE - MÓVIL
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open + .sidebar-overlay.active { display: block; }
    .main-content { margin-left: 0; }
    .menu-toggle { display: flex; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 12px; }
    .grid-4 { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
    .chat-container { flex-direction: column; height: auto; }
    .chat-sidebar { width: 100%; max-height: 200px; }
    .content { padding: 12px; }
    .top-header { padding: 0 12px; height: 52px; }
    .header-left { display: flex; align-items: center; min-width: 0; }
    .header-left h1 { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
    .card-header { padding: 12px 14px; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
    .card-header h2 { font-size: 1rem; min-width: 0; overflow-wrap: break-word; max-width: 100%; }
    .card-header .btn { width: 100%; text-align: center; }
    .card-body { padding: 14px; }
    .btn-sm { padding: 8px 14px; font-size: 0.85rem; min-height: 38px; }
    .login-box { padding: 24px; }
    .modal { width: 95% !important; max-width: 95% !important; max-height: 90vh; display: flex; flex-direction: column; border-radius: 14px !important; }
    .modal-body { max-height: 60vh; overflow-y: auto; }
    .search-bar .form-control { min-width: 100% !important; width: 100% !important; }
    .form-group { margin-bottom: 14px; }
    .form-control { padding: 10px 14px; font-size: 1rem; }
    .btn { padding: 10px 20px; font-size: 0.95rem; min-height: 42px; }

    /* Form row en móvil */
    .form-row { flex-direction: column; gap: 12px; }
    .form-row .form-group { min-width: 100%; width: 100%; }
    .max-w-400 { max-width: 100%; }
    .min-w-200 { min-width: 100% !important; }
    .min-w-150 { min-width: 100% !important; }
    .flex-row { flex-wrap: wrap; }
    .flex-col-mobile { flex-direction: column !important; align-items: stretch !important; }

    /* Tablas en móvil: scroll horizontal sin romper palabras */
    .table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative; }
    .data-table { font-size: 0.85rem; border-collapse: collapse; table-layout: auto; word-break: normal; min-width: 700px; }
    .data-table th, .data-table td { padding: 10px 12px; font-size: 0.85rem; }
    .data-table th { white-space: nowrap; word-break: normal; }
    .data-table td { white-space: normal; word-break: normal; overflow-wrap: break-word; }
    .data-table tr { border-bottom: 1px solid var(--border); }
    .data-table tbody tr:nth-child(even) { background: rgba(0,0,0,0.02); }
    /* Botones de acción en tablas: flex row compacto */
    .data-table td .btn,
    .data-table td .inline-form,
    .data-table td form,
    .data-table td a.btn {
        display: inline-flex;
        width: auto;
        margin: 2px;
        text-align: center;
        font-size: 0.8rem;
        padding: 6px 10px;
        min-height: 32px;
    }
    .data-table td .btn + .btn,
    .data-table td .btn + .inline-form,
    .data-table td .inline-form + .btn,
    .data-table td .btn + a.btn,
    .data-table td a.btn + .btn {
        margin-left: 2px;
    }
    
    /* Categorías de biblioteca en móvil */
    .flex-row.gap-15 { flex-wrap: wrap; gap: 8px; }
    .flex-row.gap-15 .btn { font-size: 0.8rem; padding: 6px 12px; min-height: 36px; }

    /* Footer */
    .app-footer { padding: 12px 14px; }
    .footer-content { flex-direction: column; text-align: center; gap: 8px; font-size: 0.75rem; }
    .footer-section { font-size: 0.75rem; }
    .footer-brand h4 { font-size: 0.9rem; }
    .footer-copy { font-size: 0.75rem; }

    /* Header derecho */
    .header-right { gap: 8px; }
    .header-right span { display: none; }
    .badge { padding: 6px; font-size: 1rem; }
    .badge-count { width: 16px; height: 16px; font-size: 0.6rem; }

    /* Stat cards */
    .stat-card { padding: 16px; gap: 12px; }
    .stat-icon { width: 42px; height: 42px; font-size: 1.2rem; }
    .stat-info h3 { font-size: 1.3rem; }
    .stat-info p { font-size: 0.75rem; }

    /* User info en sidebar */
    .sidebar-footer { padding: 8px 12px; }
    .user-avatar { width: 28px; height: 28px; font-size: 0.7rem; }
    .user-details .name { font-size: 0.75rem; }
    .user-details .role { font-size: 0.6rem; }

    /* Calificaciones */
    .cal-grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
    .cal-item { padding: 8px; }
    .cal-item .value { font-size: 1rem; }

    /* Asistencia tags */
    .asistencia-tag { width: 28px; height: 28px; font-size: 0.8rem; }

    /* Tabs */
    .tab { padding: 10px 14px; font-size: 0.85rem; }

    /* Modal */
    .modal-header { padding: 14px 16px; }
    .modal-header h2 { font-size: 1rem; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
    .modal-footer .btn { flex: 1; justify-content: center; min-width: 100px; }

    /* Grid inline styles */
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

    /* Flex layouts que se romben - capturar TODAS las variaciones */
    form[style*="display:flex"] { flex-direction: column !important; }
    form[style*="display: flex"] { flex-direction: column !important; }
    
    div[style*="display:flex"], div[style*="display: flex"] { flex-direction: column !important; align-items: stretch !important; }
    div[style*="display:flex"] > *, div[style*="display: flex"] > * { width: 100% !important; max-width: 100% !important; }
    
    /* Pero permitir ciertos elementos que DEBEN mantener flex-row */
    div[class*="asistencia"] div[style*="display:flex"],
    div[class*="asistencia"] div[style*="display: flex"] { flex-direction: row !important; }
    
    /* Badges y contadores deben mantenerse en línea */
    a[style*="display:flex"], a[style*="display: flex"] { flex-direction: row !important; align-items: center !important; }
    span[style*="display:flex"], span[style*="display: flex"] { flex-direction: row !important; }
    
    /* Cards de biblioteca: mejora visual */
    div[style*="border:1px solid"] { padding: 14px !important; margin-bottom: 10px !important; }
    div[style*="border: 1px solid"] { padding: 14px !important; margin-bottom: 10px !important; }
    div[style*="border:1px solid"]:last-child, div[style*="border: 1px solid"]:last-child { margin-bottom: 0 !important; }
    
    /* Forms inline en tabla */
    td form[style*="display:inline"] { display: block !important; width: 100% !important; }
    td form[style*="display: inline"] { display: block !important; width: 100% !important; }
    td form { margin-bottom: 4px; }
    td form:last-child { margin-bottom: 0; }
    td .btn { width: 100% !important; justify-content: center; }
    
    /* Anchos fijos que romben el layout */
    [style*="width:160px"] { width: 100% !important; }
    [style*="width: 160px"] { width: 100% !important; }
    [style*="width:150px"] { width: 100% !important; }
    [style*="width: 150px"] { width: 100% !important; }
    [style*="width:180px"] { width: 100% !important; }
    [style*="width: 180px"] { width: 100% !important; }
    [style*="width:200px"] { width: 100% !important; }
    [style*="width: 200px"] { width: 100% !important; }
    [style*="width:220px"] { width: 100% !important; }
    [style*="width: 220px"] { width: 100% !important; }
    [style*="width:250px"] { width: 100% !important; }
    [style*="width: 250px"] { width: 100% !important; }
    [style*="width:300px"] { width: 100% !important; }
    [style*="width: 300px"] { width: 100% !important; }
    [style*="max-width:500px"] { max-width: 95% !important; }
    [style*="max-width: 500px"] { max-width: 95% !important; }
    [style*="max-width:600px"] { max-width: 95% !important; }
    [style*="max-width: 600px"] { max-width: 95% !important; }
    [style*="max-width:700px"] { max-width: 95% !important; }
    [style*="max-width: 700px"] { max-width: 95% !important; }
    [style*="min-width:200px"] { min-width: 100% !important; }
    [style*="min-width: 200px"] { min-width: 100% !important; }
    [style*="min-width:150px"] { min-width: 100% !important; }
    [style*="min-width: 150px"] { min-width: 100% !important; }
    [style*="min-width:250px"] { min-width: 100% !important; }
    [style*="min-width: 250px"] { min-width: 100% !important; }
    
    /* Padding/margin excesivos */
    [style*="padding:20px"] { padding: 14px !important; }
    [style*="padding: 20px"] { padding: 14px !important; }
    [style*="padding:25px"] { padding: 14px !important; }
    [style*="padding: 25px"] { padding: 14px !important; }
    [style*="margin-bottom:25px"] { margin-bottom: 14px !important; }
    [style*="margin-bottom: 25px"] { margin-bottom: 14px !important; }
    [style*="margin-bottom:20px"] { margin-bottom: 14px !important; }
    [style*="margin-bottom: 20px"] { margin-bottom: 14px !important; }
    [style*="margin-top:20px"] { margin-top: 14px !important; }
    [style*="margin-top: 20px"] { margin-top: 14px !important; }
    [style*="gap:20px"] { gap: 12px !important; }
    [style*="gap: 20px"] { gap: 12px !important; }
    [style*="gap:15px"] { gap: 10px !important; }
    [style*="gap: 15px"] { gap: 10px !important; }
    [style*="gap:25px"] { gap: 12px !important; }
    [style*="gap: 25px"] { gap: 12px !important; }
    
    /* Botones en tablas */
    .data-table td .btn { min-height: 36px; padding: 6px 10px; }
    .data-table td .btn-sm { font-size: 0.8rem; padding: 6px 10px; }

    /* Alertas */
    .alert { padding: 10px 14px; font-size: 0.85rem; }
    
    /* Mejoras visuales para biblioteca */
    [style*="border-radius:12px"] { border-radius: 10px !important; }
    [style*="border-radius: 12px"] { border-radius: 10px !important; }
    [style*="border-radius:10px"] { border-radius: 8px !important; }
    [style*="border-radius: 10px"] { border-radius: 8px !important; }
    
    /* Hacer que textos largos se ajusten */
    h3[style*="font-size"] { font-size: 1rem !important; word-break: break-word; }
    p[style*="color:var(--secondary)"] { font-size: 0.85rem !important; }
    p[style*="color: var(--secondary)"] { font-size: 0.85rem !important; }
    
    .hide-mobile { display: none; }
    .hide-desktop { display: block; }
    .nowrap { white-space: normal; }

    /* Grids responsive */
    .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
    .grid-3 { grid-template-columns: 1fr !important; }
    .grid-2 { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; gap: 10px; }
    .form-row { gap: 10px; }
    .form-row .form-group { min-width: 100%; }
    .header-left h1 { max-width: 140px; font-size: 0.85rem; }
    .card-header { padding: 10px 12px; gap: 6px; }
    .card-header h2 { font-size: 0.95rem; }
    .card-body { padding: 12px; }
    .btn { padding: 8px 16px; font-size: 0.9rem; min-height: 40px; }
    .btn-sm { padding: 6px 10px; font-size: 0.8rem; }
    .content { padding: 10px; }
    .data-table { font-size: 0.8rem; min-width: 600px !important; }
    .data-table th, .data-table td { padding: 8px 10px; font-size: 0.8rem; }
    .form-control { padding: 10px 12px; font-size: 0.95rem; }
    .stat-card { padding: 14px; }
    .stat-icon { width: 36px; height: 36px; font-size: 1rem; }
    .stat-info h3 { font-size: 1.2rem; }
    .stat-info p { font-size: 0.7rem; }
    
    /* Modal en 480px: centrado y elegante, NO bottom-sheet */
    .modal { 
        width: 95% !important; 
        border-radius: 12px !important; 
        max-height: 90vh; 
        position: relative; 
        bottom: auto; 
    }
    .modal-overlay { padding: 10px; align-items: center; justify-content: center; }
    .modal-header { padding: 12px 14px; }
    .modal-body { padding: 12px 14px; max-height: 65vh; }
    .modal-footer { padding: 10px 14px; }
    
    .search-bar { gap: 8px; }
    .table-responsive { margin: 0; width: 100%; }
    .top-header { height: 48px; padding: 0 10px; }
    .menu-toggle { width: 36px; height: 36px; margin-right: 8px; }
    .badge { padding: 5px; font-size: 0.9rem; }
    .badge-count { width: 14px; height: 14px; font-size: 0.55rem; }
    .alert { padding: 8px 12px; font-size: 0.8rem; }
    .footer-content { gap: 6px; }
    .footer-section { font-size: 0.7rem; }
    .footer-brand h4 { font-size: 0.85rem; }
    .footer-copy { font-size: 0.7rem; }
    .cal-grid { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 4px; }
    
    /* Padding reducido */
    [style*="padding:20px"] { padding: 12px !important; }
    [style*="padding: 20px"] { padding: 12px !important; }
    [style*="padding:15px"] { padding: 10px !important; }
    [style*="padding: 15px"] { padding: 10px !important; }
    [style*="margin-bottom:20px"] { margin-bottom: 10px !important; }
    [style*="margin-bottom: 20px"] { margin-bottom: 10px !important; }
    [style*="margin-bottom:25px"] { margin-bottom: 12px !important; }
    [style*="margin-bottom: 25px"] { margin-bottom: 12px !important; }
    [style*="margin-bottom:15px"] { margin-bottom: 10px !important; }
    [style*="margin-bottom: 15px"] { margin-bottom: 10px !important; }
    [style*="gap:20px"] { gap: 10px !important; }
    [style*="gap: 20px"] { gap: 10px !important; }
    [style*="gap:15px"] { gap: 8px !important; }
    [style*="gap: 15px"] { gap: 8px !important; }
    [style*="gap:12px"] { gap: 6px !important; }
    [style*="gap: 12px"] { gap: 6px !important; }
    [style*="gap:10px"] { gap: 6px !important; }
    [style*="gap: 10px"] { gap: 6px !important; }
    [style*="gap:8px"] { gap: 5px !important; }
    [style*="gap: 8px"] { gap: 5px !important; }
    
    /* Font sizes más pequeños */
    [style*="font-size:1.5rem"] { font-size: 1.2rem !important; }
    [style*="font-size: 1.5rem"] { font-size: 1.2rem !important; }
    [style*="font-size:1.3rem"] { font-size: 1.1rem !important; }
    [style*="font-size: 1.3rem"] { font-size: 1.1rem !important; }
    [style*="font-size:1.05rem"] { font-size: 0.95rem !important; }
    [style*="font-size: 1.05rem"] { font-size: 0.95rem !important; }
    [style*="font-size:0.9rem"] { font-size: 0.82rem !important; }
    [style*="font-size: 0.9rem"] { font-size: 0.82rem !important; }
    [style*="font-size:0.85rem"] { font-size: 0.78rem !important; }
    [style*="font-size: 0.85rem"] { font-size: 0.78rem !important; }
    
    /* Tablas aún más compactas */
    .data-table { min-width: 100% !important; }
    .data-table td .btn { min-height: 32px; padding: 5px 8px; font-size: 0.75rem; }
    .data-table td .btn-sm { font-size: 0.75rem; padding: 5px 8px; }
    
    /* Cards */
    .card { border-radius: 10px; }
    .card-header { border-radius: 10px 10px 0 0; }
    
    /* Asistencia */
    .asistencia-tag { width: 24px; height: 24px; font-size: 0.7rem; }
    
    /* Modales */
    .modal-header h2 { font-size: 0.95rem; }
    .modal-footer .btn { min-width: 80px; }
}

/* ============================================
   UTILIDADES
   ============================================ */
.flex-row { display: flex; flex-wrap: wrap; }
.flex-col { display: flex; flex-direction: column; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-5 { gap: 5px; }

/* Form row: filas de formulario responsive */
.form-row { display: flex; flex-wrap: wrap; gap: 20px; }
.form-row .form-group { flex: 1; min-width: 200px; }

/* Max width utilities */
.max-w-400 { max-width: 400px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-15 { gap: 15px; }
.gap-20 { gap: 20px; }
.gap-25 { gap: 25px; }
.mb-8 { margin-bottom: 8px; }
.mb-10 { margin-bottom: 10px; }
.mb-12 { margin-bottom: 12px; }
.mb-15 { margin-bottom: 15px; }
.mb-20 { margin-bottom: 20px; }
.mb-25 { margin-bottom: 25px; }
.mt-6 { margin-top: 6px; }
.mt-15 { margin-top: 15px; }
.p-10 { padding: 10px; }
.p-12 { padding: 12px; }
.p-15 { padding: 15px; }
.p-20 { padding: 20px; }
.pt-10 { padding-top: 10px; }
.pb-10 { padding-bottom: 10px; }
.border-default { border: 1px solid var(--border); }
.rounded-lg { border-radius: 12px; }
.rounded-md { border-radius: 10px; }
.rounded-sm { border-radius: 8px; }
.bg-white { background: #fff; }
.bg-light { background: #f8f9fa; }
.shadow-hover { transition: box-shadow 0.2s; }
.shadow-hover:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.text-inherit { color: inherit; }
.no-underline { text-decoration: none; }
.flex-1 { flex: 1; }
.min-w-200 { min-width: 200px; }
.min-w-150 { min-width: 150px; }
.w-full { width: 100%; }
.max-w-95 { max-width: 95%; }

/* ============================================
   FOOTER
   ============================================ */
.app-footer {
    background: white;
    border-top: 1px solid var(--border);
    padding: 24px 30px;
    margin-top: auto;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

.footer-section {
    font-size: 0.85rem;
    color: var(--secondary);
    line-height: 1.6;
}

.footer-brand h4 {
    color: var(--primary);
    font-size: 1rem;
    margin-bottom: 2px;
}

.footer-brand p {
    font-size: 0.8rem;
    color: var(--secondary);
}

.footer-label {
    font-weight: 600;
    color: var(--dark);
}

.footer-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.footer-copy {
    margin-top: 4px;
    font-size: 0.8rem;
}

/* Login Footer */
.login-footer {
    text-align: center;
    padding: 20px;
    color: rgba(255,255,255,0.8);
    font-size: 0.8rem;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

.login-footer a {
    color: white;
    text-decoration: underline;
}

/* Print */
@media print {
    .sidebar, .top-header, .btn, .app-footer { display: none !important; }
    .main-content { margin-left: 0; }
}

/* ============================================
   UTILIDADES RESPONSIVE
   ============================================ */
.hide-mobile { display: block; }
.hide-desktop { display: none; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--secondary) !important; }
.text-info { color: var(--info) !important; }
.text-light { color: var(--text-light) !important; }
.text-dark { color: var(--dark) !important; }
.font-bold { font-weight: 700 !important; }
.font-weight-600 { font-weight: 600 !important; }
.font-large { font-size: 1.2rem !important; }
.text-small { font-size: 0.8rem !important; }
.text-medium { font-size: 0.9rem !important; }
.text-base { font-size: 1.05rem !important; }
.text-lg { font-size: 1.1rem !important; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.gap-30 { gap: 30px; }
.gap-4 { gap: 4px; }
.bg-dark { background: var(--dark); color: white; }
.line-height-lg { line-height: 1.6; }
.line-height-xl { line-height: 1.7; }
.inline-form { display: inline; }
.badge-count { margin-left: 6px; background: rgba(0,0,0,0.15); padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; }
.badge-nivel { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; padding: 3px 10px; border-radius: 20px; }
.badge-tag { font-size: 0.8rem; padding: 3px 10px; background: #f0f0f0; border-radius: 12px; color: var(--secondary); display: inline-block; }
.badge-nivel-sm { font-size: 0.7rem; text-transform: uppercase; padding: 2px 8px; border-radius: 20px; background: #f0f0f0; color: var(--secondary); display: inline-block; }
.badge-nivel-md { font-size: 0.85rem; padding: 5px 14px; border-radius: 20px; font-weight: 500; display: inline-block; }
.max-w-400 { max-width: 400px; }
.mt-5 { margin-top: 5px; }
.m-0 { margin: 0 !important; }
.border-bottom { border-bottom: 1px solid var(--border); }
.border-top { border-top: 1px solid var(--border); }
.px-20 { padding-left: 20px; padding-right: 20px; }
.pl-18 { padding-left: 18px; }
.max-w-180 { max-width: 180px; }
.max-w-150 { max-width: 150px; }
.scroll-y-200 { max-height: 200px; overflow-y: auto; }
.py-4 { padding-top: 4px; padding-bottom: 4px; }
.cursor-pointer { cursor: pointer; }
.p-6 { padding: 6px; }
.font-size-lg { font-size: 1.4rem; }
.font-size-2xl { font-size: 2rem; }
.text-center-p-20 { text-align: center; padding: 20px; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #e64a19; }
.bg-surface { background: var(--surface); }
.bg-primary { background: var(--primary); }
.bg-success { background: var(--success); }
.bg-warning { background: var(--warning); }
.bg-danger { background: var(--danger); }
.bg-info { background: var(--info); }

/* ============================================
   NUEVOS ESTILOS — TEMAS, AVATAR, DROPDOWN
   ============================================ */

/* Tema oscuro: texto claro en cards y sidebar */
body[style*="background-color"]:has(:root[style]) .card,
body .card { color: var(--text, var(--dark)); }

/* Header user menu hover */
.header-user-menu:hover { opacity: 0.85; }

/* Dropdown arrow fix */
.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 18px;
    width: 12px;
    height: 12px;
    background: var(--card);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    transform: rotate(45deg);
}

/* Responsive name in header */
@media (min-width: 768px) {
    .header-name-desktop { display: inline !important; }
}

/* Tema oscuro: ajustes generales */
[data-theme="dark"] .card,
[data-theme="dark"] .sidebar,
[data-theme="dark"] .dropdown-menu { background: var(--card); }
[data-theme="dark"] body { color: #e2e8f0; }
[data-theme="dark"] .text-secondary { color: #94a3b8 !important; }
[data-theme="dark"] .stat-card { background: var(--card); }
[data-theme="dark"] .card { border-color: #334155; }
[data-theme="dark"] .data-table th { background: #1e293b; }
[data-theme="dark"] .data-table td { border-color: #334155; }
[data-theme="dark"] .table-responsive { background: var(--card); }
[data-theme="dark"] .form-control { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .form-control:focus { border-color: var(--primary); background: #0f172a; }
[data-theme="dark"] .search-form { background: #1e293b; }
[data-theme="dark"] .search-form .form-control { background: #0f172a; }
[data-theme="dark"] .form-control::placeholder { color: #64748b; }
[data-theme="dark"] .form-label { color: #94a3b8; }
[data-theme="dark"] .page-title h1 { color: #e2e8f0; }
[data-theme="dark"] .page-title p { color: #94a3b8; }
[data-theme="dark"] .modal-content { background: #1e293b; color: #e2e8f0; }
[data-theme="dark"] .modal-header { border-color: #334155; }
[data-theme="dark"] .modal-footer { border-color: #334155; }
[data-theme="dark"] .btn-outline { background: transparent; border-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .btn-outline:hover { background: #334155; }
[data-theme="dark"] .card-header { border-color: #334155; }
[data-theme="dark"] .list-group { background: var(--card); }
[data-theme="dark"] .list-group-item { border-color: #334155; }
[data-theme="dark"] .list-group-item:hover { background: #0f172a; }
[data-theme="dark"] .nav-tabs { border-color: #334155; }
[data-theme="dark"] .nav-tabs .nav-link { color: #94a3b8; }
[data-theme="dark"] .nav-tabs .nav-link:hover { background: #0f172a; color: #e2e8f0; }
[data-theme="dark"] .nav-tabs .nav-link.active { background: #1e293b; color: #e2e8f0; border-color: #334155; border-bottom-color: #1e293b; }
[data-theme="dark"] .alert-info { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .alert-warning { background: #1e293b; border-color: #334155; color: #e2e8f0; }


