:root {
    --primary: #194266;
    --primary-hover: #112d47;
    --danger: #b91c1c;
    --danger-hover: #991b1b;
    --bg-body: #f4f6f8;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; display: flex; flex-direction: column; }
#login-screen { align-items: center; justify-content: center; background-color: var(--primary); padding: 1rem; }

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}
.form-card { width: 100%; max-width: 400px; text-align: left; }

.btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.7rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    font-size: 1rem;
    transition: background 0.2s;
}
.btn:hover { background-color: var(--primary-hover); }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }

input, select, textarea {
    width: 100%;
    padding: 0.7rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    background: #fff;
}

.error-msg { color: var(--danger); font-size: 0.9rem; margin-top: 1rem; }

header {
    background: var(--card-bg);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

@media (min-width: 768px) {
    header { padding: 1rem 2rem; }
}

.tab-menu {
    display: flex;
    background: var(--card-bg);
    padding: 0 1rem;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.tab-menu::-webkit-scrollbar { display: none; }

.tab-btn {
    background: none;
    border: none;
    padding: 0.8rem 0.8rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    font-size: 0.95rem;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--danger);
}

.main-content { padding: 1rem; }
.grid-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

@media (min-width: 1024px) {
    .main-content { padding: 2rem; }
    .grid-layout {
        grid-template-columns: 1fr 350px;
        gap: 2.5rem;
        width: 96%;
    }
}

.table-responsive { overflow-x: auto; width: 100%; -webkit-overflow-scrolling: touch; }
.horario-table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.9rem; }
.horario-table th, .horario-table td {
    border: 1px solid var(--border);
    padding: 0.5rem;
    text-align: center;
    white-space: nowrap;
}
@media (min-width: 768px) {
    .horario-table th, .horario-table td { padding: 0.75rem; font-size: 1rem; }
}
.horario-table th { background-color: var(--primary); color: white; }
.recreo { background-color: #f1f5f9; font-weight: bold; color: var(--text-muted); }

.calendario-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    text-align: center;
}
@media (min-width: 768px) { .calendario-grid { gap: 5px; } }

.dia-semana { font-weight: bold; color: var(--text-muted); font-size: 0.8rem; padding-bottom: 0.3rem; }
@media (min-width: 768px) { .dia-semana { font-size: 0.9rem; } }

.dia-calendario {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}
@media (min-width: 768px) { .dia-calendario { border-radius: 8px; font-size: 1rem; } }
.dia-calendario:hover { background: #e2e8f0; }
.dia-hoy { background: #e0f2fe; border-color: var(--primary); font-weight: bold; }
.punto-evento { width: 5px; height: 5px; border-radius: 50%; }

.evento-badge { font-size: 0.7rem; padding: 2px 4px; border-radius: 4px; color: white; font-weight: bold; }
.badge-EXAMEN { background: var(--danger); }
.badge-ENTREGA { background: #d97706; }
.badge-TAREA { background: var(--primary); }
.badge-DESTACADO { background: #7c3aed; }
.evento-item { background: #f8fafc; padding: 10px; border-radius: 8px; border-left: 4px solid var(--border); margin-bottom: 10px; }
.evento-EXAMEN { border-left-color: var(--danger); }
.evento-ENTREGA { border-left-color: #d97706; }
.evento-TAREA { border-left-color: var(--primary); }
.evento-DESTACADO { border-left-color: #7c3aed; }
.creador-evento { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; font-style: italic; }

.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
    padding: 1rem;
}
.modal-content {
    background: white; padding: 1.5rem; border-radius: 12px;
    width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; position: relative;
}
@media (min-width: 768px) { .modal-content { padding: 2rem; } }
.close-modal { position: absolute; top: 15px; right: 20px; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }

.acciones-asistencia { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.btn-falta { background: var(--danger); color: white; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.btn-retraso { background: #ea580c; color: white; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.btn-restar { background: #64748b; color: white; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }

.chat-mensajes-container {
    height: 50vh;
    min-height: 350px;
    max-height: 600px;
    overflow-y: auto;
    border: 1px solid var(--border); border-radius: 8px;
    padding: 1rem; margin-bottom: 1rem; background: #f8fafc;
    display: flex; flex-direction: column; gap: 10px;
}
@media (min-width: 768px) {
    .chat-mensajes-container { height: 60vh; padding: 1.5rem; }
}
.chat-form { display: flex; gap: 8px; }

.mensaje-wrapper { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.mensaje-wrapper.propio { justify-content: flex-end; }

.chat-avatar-img {
    width: 30px; height: 30px;
    border-radius: 50%; object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
    background-color: white;
}
@media (min-width: 768px) {
    .chat-avatar-img { width: 36px; height: 36px; }
}

.mensaje-burbuja {
    max-width: 82%; padding: 8px 12px;
    border-radius: 12px; background: white;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
@media (min-width: 768px) {
    .mensaje-burbuja { max-width: 75%; padding: 10px 14px; border-radius: 14px; }
}

.mensaje-burbuja.mensaje-propio {
    background: var(--primary);
    color: white; border: none;
    border-bottom-right-radius: 2px;
}
.mensaje-wrapper:not(.propio) .mensaje-burbuja { border-bottom-left-radius: 2px; }

.mensaje-autor { font-size: 0.75rem; margin-bottom: 2px; display: block; }
.mensaje-texto { word-break: break-word; font-size: 0.95rem; line-height: 1.4; }
.mensaje-tiempo { font-size: 0.65rem; text-align: right; margin-top: 3px; }
.mensaje-wrapper:not(.propio) .mensaje-tiempo { color: var(--text-muted); }
.mensaje-wrapper.propio .mensaje-tiempo { color: rgba(255,255,255,0.7); }

.snippet-box {
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.8rem;
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    margin-top: 0.5rem;
    white-space: pre-wrap;
}

.punto-estado { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.punto-online { background-color: #16a34a; box-shadow: 0 0 4px #16a34a; }
.punto-offline { background-color: #94a3b8; }
.usuario-estado-item { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.usuario-estado-item:last-child { border-bottom: none; }
