:root {
    --uni-red: #b71c1c;
    --uni-red-deep: #7a0019;
    --uni-red-light: #e53935;
    --ink: #1a1a2e;
    --ink-soft: #2c3e50;
    --paper: #fafafa;
    --paper-soft: #f3f4f6;
    --line: #e5e7eb;
    --muted: #6b7280;
    --green: #16a34a;
    --yellow: #eab308;
    --red: #dc2626;
    --blue: #2563eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
}

/* ========== Topbar ========== */
.topbar {
    background: linear-gradient(135deg, var(--uni-red-deep), var(--uni-red));
    color: white;
    padding: 0.7em 1.4em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 12px rgba(122,0,25,0.2);
}
.brand { display: flex; align-items: center; gap: 0.9em; }
.brand-mark {
    background: white;
    color: var(--uni-red-deep);
    font-weight: 900;
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.95em;
    letter-spacing: 0.05em;
}
.brand-title { font-weight: 700; font-size: 1.05em; }
.brand-sub { font-size: 0.75em; opacity: 0.85; }
.topbar-right { display: flex; align-items: center; gap: 0.7em; }
.rules-pill {
    background: rgba(255,255,255,0.15);
    padding: 0.35em 0.9em;
    border-radius: 999px;
    font-size: 0.72em;
    border: 1px solid rgba(255,255,255,0.3);
}
.status-dot { color: var(--green); font-size: 1.4em; line-height: 1; }
.status-dot.error { color: #fca5a5; }

/* ========== Layout ========== */
.layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - 65px);
    overflow: hidden;
}

/* ========== Sidebar ========== */
.sidebar {
    background: white;
    border-right: 1px solid var(--line);
    overflow-y: auto;
}
.sidebar-h {
    padding: 1em 1.2em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
    background: var(--paper-soft);
    position: sticky;
    top: 0;
    z-index: 1;
}
.sidebar-h h2 {
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
}
.counter {
    background: var(--uni-red);
    color: white;
    font-size: 0.7em;
    font-weight: 700;
    padding: 0.15em 0.6em;
    border-radius: 999px;
}
.student-list { padding: 0.5em 0; }

.student-card {
    padding: 0.9em 1.2em;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
    transition: background 0.15s;
    border-left: 4px solid transparent;
}
.student-card:hover { background: var(--paper-soft); }
.student-card.active {
    background: #fff5f5;
    border-left-color: var(--uni-red);
}
.sc-name {
    font-weight: 600;
    font-size: 0.95em;
    margin-bottom: 0.2em;
}
.sc-code { font-family: 'JetBrains Mono', monospace; font-size: 0.75em; color: var(--muted); }
.sc-meta {
    display: flex;
    gap: 0.4em;
    margin-top: 0.45em;
    flex-wrap: wrap;
    align-items: center;
}
.tag {
    font-size: 0.65em;
    padding: 0.18em 0.55em;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tag-trica { background: #fee2e2; color: var(--red); }
.tag-2da { background: #fef3c7; color: #92400e; }
.tag-1ra { background: #dcfce7; color: #166534; }
.tag-risk-alto { background: var(--red); color: white; }
.tag-risk-medio { background: var(--yellow); color: #44340e; }
.tag-risk-bajo { background: var(--green); color: white; }

/* ========== Main ========== */
.main {
    overflow-y: auto;
    background: var(--paper);
    padding: 0;
}

.empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-align: center;
    padding: 2em;
}
.empty-icon { font-size: 3em; margin-bottom: 0.4em; }
.empty-title { font-size: 1.2em; font-weight: 600; color: var(--ink-soft); }
.empty-sub { margin-top: 0.3em; }

.detail { padding: 1.4em 1.8em 2em; }

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1em;
    padding-bottom: 1.2em;
    border-bottom: 1px solid var(--line);
    margin-bottom: 1.4em;
}
.detail-meta { font-size: 0.78em; color: var(--muted); margin-bottom: 0.2em; }
#detail-name { font-size: 1.7em; font-weight: 700; color: var(--ink); }
.detail-purpose {
    margin-top: 0.5em;
    font-size: 0.92em;
    color: var(--ink-soft);
    font-style: italic;
    max-width: 700px;
}
.badge-stack { display: flex; flex-direction: column; gap: 0.4em; align-items: flex-end; }
.badge {
    padding: 0.4em 0.9em;
    border-radius: 6px;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========== Sections ========== */
.section-h {
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0.7em;
}
.grades-section, .predict-section, .chat-section { margin-bottom: 1.4em; }

/* ========== Grades grid ========== */
.grades-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.6em;
    margin-bottom: 0.8em;
}
.grade-card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.7em 0.5em;
    text-align: center;
    box-shadow: var(--shadow);
}
.grade-card.dropped {
    opacity: 0.45;
    background: var(--paper-soft);
    text-decoration: line-through;
}
.grade-card.pending {
    background: repeating-linear-gradient(45deg, #fafafa, #fafafa 6px, #f3f4f6 6px, #f3f4f6 12px);
    border-style: dashed;
}
.gc-label {
    font-size: 0.65em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.gc-value {
    font-size: 1.6em;
    font-weight: 800;
    margin-top: 0.2em;
    line-height: 1;
}
.gc-value.pass { color: var(--green); }
.gc-value.fail { color: var(--red); }
.gc-value.na { color: #cbd5e1; font-size: 1.2em; }
.gc-due { font-size: 0.6em; color: var(--muted); margin-top: 0.3em; }

.grade-summary {
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.9em 1.1em;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1em;
    box-shadow: var(--shadow);
}
.summary-item { text-align: center; }
.summary-label { font-size: 0.7em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.summary-value { font-size: 1.4em; font-weight: 800; margin-top: 0.2em; }
.summary-value.fail { color: var(--red); }
.summary-value.pass { color: var(--green); }

/* ========== Predict ========== */
.predict-block {
    background: linear-gradient(135deg, #fff8e1, #fef3c7);
    border-left: 5px solid #f59e0b;
    border-radius: 8px;
    padding: 1em 1.2em;
    box-shadow: var(--shadow);
}
.predict-block.success {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    border-left-color: var(--green);
}
.predict-block.danger {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    border-left-color: var(--red);
}
.predict-h { font-weight: 700; font-size: 1em; margin-bottom: 0.3em; color: var(--ink); }
.predict-num {
    font-size: 2.4em;
    font-weight: 900;
    color: var(--ink);
    line-height: 1;
    margin: 0.2em 0;
}
.predict-explain { font-size: 0.85em; color: var(--ink-soft); }

/* ========== Chat ========== */
.chat-section {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--line);
    padding: 1em 1.2em;
    box-shadow: var(--shadow);
}
.chat-h {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.7em;
}
.chat-log {
    background: #ece5dd; /* WhatsApp vibe */
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40"><circle cx="20" cy="20" r="1" fill="rgba(0,0,0,0.04)"/></svg>');
    border-radius: 8px;
    padding: 1em;
    height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}
.bubble {
    max-width: 75%;
    padding: 0.6em 0.85em;
    border-radius: 10px;
    font-size: 0.92em;
    line-height: 1.4;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
    white-space: pre-wrap;
    word-break: break-word;
    position: relative;
}
.bubble.user {
    background: #dcf8c6;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.bubble.assistant {
    background: white;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}
.bubble-time {
    font-size: 0.65em;
    color: var(--muted);
    margin-top: 0.3em;
    text-align: right;
}
.bubble-empty {
    align-self: center;
    color: var(--muted);
    font-size: 0.85em;
    padding: 1em;
    text-align: center;
}

.chat-input {
    margin-top: 0.7em;
    display: flex;
    gap: 0.5em;
}
.chat-input input {
    flex: 1;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.7em 1em;
    font-family: inherit;
    font-size: 0.9em;
    outline: none;
    transition: border 0.15s;
}
.chat-input input:focus { border-color: var(--uni-red); }

.btn-primary {
    background: var(--uni-red);
    color: white;
    border: none;
    border-radius: 999px;
    padding: 0 1.2em;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-primary:hover { background: var(--uni-red-deep); }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 999px;
    padding: 0.3em 0.8em;
    font-size: 0.75em;
    cursor: pointer;
    font-family: inherit;
}
.btn-ghost:hover { background: var(--paper-soft); }

.chat-hint { font-size: 0.7em; color: var(--muted); margin-top: 0.4em; padding: 0 0.4em; }

.typing {
    align-self: flex-start;
    background: white;
    padding: 0.6em 0.85em;
    border-radius: 10px;
    color: var(--muted);
    font-style: italic;
    font-size: 0.85em;
}

/* ============== User chip & top bar additions ============== */
.user-chip {
    display: flex;
    align-items: center;
    gap: 0.6em;
    background: rgba(255,255,255,0.15);
    padding: 0.4em 0.7em 0.4em 0.9em;
    border-radius: 999px;
    color: white;
    font-size: 0.78em;
    border: 1px solid rgba(255,255,255,0.25);
}
.user-chip span:first-child {
    background: rgba(0,0,0,0.18);
    padding: 0.15em 0.5em;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 700;
}

/* ============== Alerts banner ============== */
.alerts-banner {
    background: linear-gradient(135deg, #fff8e1, #fef3c7);
    border-bottom: 2px solid #f59e0b;
    padding: 0.7em 1.4em;
}
.alerts-banner-h {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    color: #78350f;
}
.alerts-list {
    margin-top: 0.6em;
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}
.alert-item {
    background: white;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    padding: 0.7em 0.9em;
    font-size: 0.82em;
}
.alert-item.alert-sev-medium { border-left-color: #f97316; }
.alert-item.alert-sev-high   { border-left-color: var(--red); background: #fff5f5; }
.alert-item.alert-sev-critical {
    border-left-color: var(--red);
    background: #fee2e2;
    box-shadow: 0 0 0 2px rgba(239,68,68,0.2);
    animation: pulse-alert 2s infinite;
}
@keyframes pulse-alert {
    0%, 100% { box-shadow: 0 0 0 2px rgba(239,68,68,0.2); }
    50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0.05); }
}
.alert-row {
    display: flex;
    align-items: center;
    gap: 0.7em;
    flex-wrap: wrap;
}
.alert-sev { font-size: 0.7em; padding: 0.2em 0.6em; }
.tag-sev-low      { background: #dbeafe; color: #1e40af; }
.tag-sev-medium   { background: #fed7aa; color: #9a3412; }
.tag-sev-high     { background: #fee2e2; color: #991b1b; }
.tag-sev-critical { background: var(--red); color: white; }
.alert-topic { font-weight: 600; color: var(--ink); }
.alert-student { color: var(--ink-soft); font-size: 0.9em; }
.alert-time { color: var(--muted); font-size: 0.85em; margin-left: auto; }
.alert-summary {
    margin-top: 0.4em;
    color: var(--ink-soft);
    font-size: 0.95em;
    line-height: 1.4;
}

.alert-badge {
    display: inline-block;
    background: var(--red);
    color: white;
    font-size: 0.65em;
    font-weight: 700;
    padding: 0.1em 0.5em;
    border-radius: 999px;
    margin-left: 0.3em;
}

/* ============== Course tabs ============== */
.courses-section { margin-bottom: 1.4em; }
.course-tabs {
    display: flex;
    gap: 0.4em;
    overflow-x: auto;
    padding-bottom: 0.5em;
    margin-bottom: 1em;
    border-bottom: 1px solid var(--line);
}
.course-tab {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink-soft);
    padding: 0.5em 0.9em;
    border-radius: 8px 8px 0 0;
    font-family: inherit;
    font-size: 0.78em;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.course-tab:hover { background: var(--paper-soft); }
.course-tab.active {
    background: var(--uni-red);
    color: white;
    border-color: var(--uni-red);
}

/* ============== Course code tag in messages ============== */
.msg-course {
    display: inline-block;
    background: rgba(0,0,0,0.08);
    color: var(--ink-soft);
    font-size: 0.82em;
    padding: 0.05em 0.35em;
    border-radius: 3px;
    margin-right: 0.5em;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

/* ============== Daily summary ============== */
.daily-summary-section {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--line);
    padding: 1em 1.2em;
    box-shadow: var(--shadow);
    margin-bottom: 1.4em;
}
.daily-summary { display: flex; flex-direction: column; gap: 0.8em; }
.summary-empty {
    color: var(--muted);
    font-style: italic;
    font-size: 0.85em;
    padding: 0.5em 0;
}
.summary-loading {
    color: var(--uni-red-deep);
    font-style: italic;
    padding: 0.6em 0;
}
.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7em 1em;
    border-radius: 8px;
    border-left: 5px solid var(--muted);
}
.summary-header.sent-optimista     { background: #dcfce7; border-left-color: var(--green); }
.summary-header.sent-neutro        { background: #f3f4f6; border-left-color: var(--muted); }
.summary-header.sent-ambivalente   { background: #fff8e1; border-left-color: #f59e0b; }
.summary-header.sent-preocupante   { background: #fed7aa; border-left-color: #f97316; }
.summary-header.sent-negativo      { background: #fee2e2; border-left-color: var(--red); }
.summary-header.sent-sin-datos     { background: #f3f4f6; border-left-color: var(--muted); }

.summary-sent { display: flex; align-items: center; gap: 0.7em; }
.summary-emoji { font-size: 1.5em; }
.summary-label {
    font-weight: 800;
    font-size: 0.85em;
    letter-spacing: 0.08em;
    color: var(--ink);
}
.summary-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7em;
    color: var(--muted);
    background: rgba(255,255,255,0.7);
    padding: 0.15em 0.5em;
    border-radius: 4px;
}
.summary-msgcount {
    font-size: 0.75em;
    color: var(--muted);
}
.summary-text {
    font-size: 0.95em;
    line-height: 1.5;
    color: var(--ink);
}
.summary-academic {
    font-size: 0.85em;
    color: var(--ink-soft);
    background: var(--paper-soft);
    padding: 0.5em 0.8em;
    border-radius: 6px;
}
.summary-block {
    background: var(--paper-soft);
    border-radius: 8px;
    padding: 0.7em 1em;
    font-size: 0.85em;
}
.summary-block strong { color: var(--uni-red-deep); display: block; margin-bottom: 0.3em; }
.summary-block ul { margin: 0; padding-left: 1.2em; line-height: 1.5; }

/* ============== Filter pills ============== */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3em;
    padding: 0.6em 0.9em;
    border-bottom: 1px solid var(--line);
    background: var(--paper-soft);
}
.filter-pill {
    background: white;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.25em 0.7em;
    font-size: 0.7em;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.filter-pill:hover { background: var(--paper-soft); }
.filter-pill.active {
    background: var(--uni-red);
    color: white;
    border-color: var(--uni-red);
}

/* ============== Stats dashboard ============== */
.stats-dashboard {
    padding: 1.4em 1.8em 2em;
    overflow-y: auto;
    max-height: 100%;
}
.stats-title {
    font-size: 1.4em;
    color: var(--uni-red-deep);
    margin-bottom: 0.2em;
}
.stats-sub {
    color: var(--muted);
    font-size: 0.85em;
    margin-bottom: 1.2em;
}

.stats-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.8em;
    margin-bottom: 1.4em;
}
.kpi-card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1em 1.1em;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--uni-red);
}
.kpi-card.kpi-alerts { border-left-color: var(--accent, #f59e0b); }
.kpi-card.kpi-trica  { border-left-color: var(--red); }
.kpi-card.kpi-evals  { border-left-color: var(--blue); }

.kpi-value {
    font-size: 2em;
    font-weight: 800;
    color: var(--ink);
    line-height: 1;
}
.kpi-label {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    font-weight: 600;
    margin-top: 0.3em;
}
.kpi-sub {
    font-size: 0.75em;
    color: var(--ink-soft);
    margin-top: 0.4em;
}

.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1em;
    margin-bottom: 1.4em;
}
.stats-card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1em 1.2em;
    box-shadow: var(--shadow);
    margin-bottom: 1em;
}
.stats-h {
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0.7em;
}

/* Bars */
.bars-vertical { display: flex; flex-direction: column; gap: 0.5em; }
.bar-row {
    display: grid;
    grid-template-columns: 90px 1fr 32px;
    align-items: center;
    gap: 0.5em;
    font-size: 0.78em;
}
.bar-label { color: var(--ink-soft); font-weight: 600; }
.bar-track {
    background: var(--paper-soft);
    border-radius: 999px;
    height: 14px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s;
}
.bar-risk-alto  { background: linear-gradient(90deg, var(--red), #fca5a5); }
.bar-risk-medio { background: linear-gradient(90deg, var(--yellow), #fde68a); }
.bar-risk-bajo  { background: linear-gradient(90deg, var(--green), #86efac); }
.enr-1ra   { background: linear-gradient(90deg, var(--blue), #93c5fd); }
.enr-2da   { background: linear-gradient(90deg, #f97316, #fdba74); }
.enr-trica { background: linear-gradient(90deg, var(--red), #fca5a5); }
.bar-value {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

/* Course stats table */
.course-stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82em;
}
.course-stats-table thead {
    background: var(--paper-soft);
}
.course-stats-table th {
    text-align: left;
    padding: 0.5em 0.7em;
    font-size: 0.85em;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--line);
}
.course-stats-table td {
    padding: 0.6em 0.7em;
    border-bottom: 1px solid var(--line);
}
.course-stats-table tbody tr:hover { background: #fff5f5; }
.muted-inline { color: var(--muted); font-size: 0.92em; }
.trica-cell { color: var(--red); font-weight: 700; }
.pass-cell { color: var(--green); font-weight: 700; }
.fail-cell { color: var(--red); font-weight: 700; }

/* Top at risk */
.top-risk-list { display: flex; flex-direction: column; gap: 0.5em; }
.risk-row {
    display: flex;
    align-items: center;
    gap: 0.7em;
    padding: 0.7em 0.9em;
    background: var(--paper-soft);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.85em;
}
.risk-row:hover { background: #fff5f5; }
.risk-name { font-weight: 600; }
.risk-failing { margin-left: auto; color: var(--red); font-weight: 700; font-size: 0.9em; }

@media (max-width: 1100px) {
    .stats-row { grid-template-columns: 1fr; }
}

/* ============== User chip rediseñado ============== */
.user-chip {
    display: flex;
    align-items: center;
    gap: 0.6em;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.22);
    padding: 0.35em 0.4em 0.35em 0.4em;
    border-radius: 999px;
    backdrop-filter: blur(8px);
}
.user-avatar {
    background: linear-gradient(135deg, #ffd54f, #ffeb3b);
    color: var(--uni-red-deep);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.78em;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    padding-right: 0.3em;
    color: white;
}
.user-name-line {
    display: flex;
    align-items: center;
    gap: 0.4em;
    font-size: 0.78em;
    font-weight: 600;
}
.role-badge {
    font-size: 0.6em;
    font-weight: 800;
    padding: 0.1em 0.45em;
    border-radius: 4px;
    letter-spacing: 0.05em;
}
.role-badge.role-admin   { background: rgba(255,213,79,0.95); color: var(--uni-red-deep); }
.role-badge.role-teacher { background: rgba(255,255,255,0.85); color: var(--uni-red-deep); }
.user-username {
    font-size: 0.65em;
    opacity: 0.7;
    margin-top: 0.1em;
    font-family: 'JetBrains Mono', monospace;
}
.logout-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25);
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.logout-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: rotate(180deg);
}

/* ============== View tabs (Panorama / Mis chats / Admin) ============== */
.view-tabs {
    display: flex;
    gap: 0.4em;
    padding: 0.6em 1.4em 0;
    border-bottom: 1px solid var(--line);
    background: white;
}
.view-tab {
    background: transparent;
    border: 1px solid var(--line);
    border-bottom: none;
    color: var(--ink-soft);
    padding: 0.5em 1em;
    border-radius: 8px 8px 0 0;
    font-family: inherit;
    font-size: 0.82em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: -1px;
}
.view-tab:hover { background: var(--paper-soft); }
.view-tab.active {
    background: var(--uni-red);
    color: white;
    border-color: var(--uni-red);
}

.teacher-block {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.9em 1em;
    margin-bottom: 0.9em;
    box-shadow: var(--shadow);
}
.all-teachers-list { display: flex; flex-direction: column; gap: 0.7em; }

/* ============== Brand link ============== */
a.brand,
a.brand:link,
a.brand:visited,
a.brand:hover,
a.brand:active {
    color: white !important;
    text-decoration: none !important;
    cursor: pointer;
    transition: opacity 0.15s;
}
a.brand:hover { opacity: 0.85; }
a.brand .brand-title,
a.brand .brand-sub { color: white !important; }

/* ============== RESPONSIVE ============== */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }
    .sidebar {
        max-height: 60vh;
        position: sticky;
        top: 0;
        z-index: 5;
    }
    .stats-row { grid-template-columns: 1fr; }
    .grades-grid { grid-template-columns: repeat(3, 1fr); }
    .mvp-grid, .stats-kpi-grid { grid-template-columns: 1fr 1fr; }
    .topbar { flex-wrap: wrap; gap: 0.5em; padding: 0.5em 0.8em; }
    .brand-title { font-size: 0.95em; }
    .brand-sub { font-size: 0.7em; }
    .rules-pill {
        order: 3;
        flex-basis: 100%;
        text-align: center;
        font-size: 0.65em;
    }
    .user-chip { order: 2; padding: 0.3em; }
    .user-info { display: none; }
    .detail { padding: 0.9em 1em 1.5em; }
    .detail-header { flex-direction: column; }
    .badge-stack { flex-direction: row; align-items: flex-start; flex-wrap: wrap; }
    #detail-name { font-size: 1.4em; }
    .detail-meta { font-size: 0.72em; }
    .grade-summary { grid-template-columns: 1fr 1fr; gap: 0.5em; }
    .course-tabs { padding-bottom: 0.4em; }
    .course-tab { font-size: 0.72em; padding: 0.4em 0.7em; }
    .filter-bar { padding: 0.5em 0.7em; }
    .view-tabs { padding: 0.4em 0.6em 0; overflow-x: auto; }
    .view-tab { white-space: nowrap; font-size: 0.72em; padding: 0.4em 0.7em; }
    .agenda-grid, .var-grid, .tech-grid, .protocol-grid, .phase-grid, .obj-grid, .bot-grid {
        grid-template-columns: 1fr 1fr;
    }
    .chat-log { height: 240px; }
    .alerts-banner { padding: 0.5em 0.8em; }
    .alert-row { font-size: 0.85em; }
    .stats-kpi-grid { grid-template-columns: 1fr 1fr; gap: 0.5em; }
    .kpi-value { font-size: 1.5em; }
    .kpi-label { font-size: 0.65em; }
    .course-stats-table { font-size: 0.7em; }
    .course-stats-table th, .course-stats-table td { padding: 0.3em 0.4em; }
}
@media (max-width: 540px) {
    .grades-grid { grid-template-columns: repeat(2, 1fr); }
    .mvp-grid, .stats-kpi-grid { grid-template-columns: 1fr; }
    .agenda-grid, .var-grid, .tech-grid, .protocol-grid, .phase-grid, .obj-grid, .bot-grid {
        grid-template-columns: 1fr;
    }
    .stats-title { font-size: 1.1em; }
    .grade-summary { grid-template-columns: 1fr; }
    .topbar-right { flex-wrap: wrap; }
    .logout-btn { width: 26px; height: 26px; }
    .user-avatar { width: 26px; height: 26px; font-size: 0.65em; }
}

/* ============== Variables del modelo (TrayectorIA-UNI) ============== */
.model-section { margin-bottom: 1.4em; }
.model-block {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1em;
    background: linear-gradient(135deg, #faf5ff, #ede9fe);
    border-left: 5px solid #8b5cf6;
    border-radius: 12px;
    padding: 1em 1.2em;
    box-shadow: var(--shadow);
}
.model-prob {
    background: white;
    border-radius: 10px;
    padding: 0.8em;
    text-align: center;
    box-shadow: 0 1px 4px rgba(139,92,246,0.18);
}
.prob-label {
    font-size: 0.65em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 600;
    margin-bottom: 0.4em;
}
.prob-bar {
    background: var(--paper-soft);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
    margin-bottom: 0.4em;
}
.prob-fill {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #6366f1);
    border-radius: 999px;
    transition: width 0.4s;
}
.model-prob.prob-low  .prob-fill { background: linear-gradient(90deg, var(--green), #4ade80); }
.model-prob.prob-medium .prob-fill { background: linear-gradient(90deg, var(--yellow), #fcd34d); }
.model-prob.prob-high .prob-fill { background: linear-gradient(90deg, var(--red), #f87171); }
.prob-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.7em;
}
.prob-num {
    font-size: 2.2em;
    font-weight: 800;
    color: var(--ink);
    line-height: 1;
}
.prob-tag {
    font-size: 0.7em;
    font-weight: 700;
    padding: 0.2em 0.7em;
    border-radius: 4px;
    letter-spacing: 0.05em;
    background: var(--paper-soft);
}
.model-prob.prob-low  .prob-tag { background: #dcfce7; color: #166534; }
.model-prob.prob-medium .prob-tag { background: #fef3c7; color: #92400e; }
.model-prob.prob-high .prob-tag { background: var(--red); color: white; }
.prob-source {
    font-size: 0.6em;
    color: var(--muted);
    margin-top: 0.5em;
    font-style: italic;
}

.model-vars-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5em;
}
.model-var {
    background: white;
    border-radius: 8px;
    padding: 0.5em 0.7em;
}
.mv-label {
    font-size: 0.6em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 0.2em;
}
.mv-value {
    font-size: 1em;
    font-weight: 700;
    color: var(--ink);
}
.mv-value.mv-text { font-size: 0.78em; font-weight: 600; }
.mv-value.mv-mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62em;
    word-break: break-all;
    color: var(--muted);
}

@media (max-width: 900px) {
    .model-block { grid-template-columns: 1fr; }
    .model-vars-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============== Test data view ============== */
.var-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3em 0.7em;
}
.var-list li {
    font-size: 0.78em;
    color: var(--ink-soft);
    padding: 0.2em 0;
}
.var-list code {
    font-family: 'JetBrains Mono', monospace;
    background: var(--paper-soft);
    padding: 0.1em 0.4em;
    border-radius: 3px;
    font-size: 0.92em;
}
@media (max-width: 540px) {
    .var-list { grid-template-columns: 1fr; }
}

/* ============== Pipeline flow (arquitectura del modelo) ============== */
.pipeline-flow {
    display: flex;
    align-items: stretch;
    gap: 0.4em;
    overflow-x: auto;
    padding: 0.7em 0.3em 1em;
}
.pipe-box {
    flex: 1 1 160px;
    min-width: 160px;
    background: linear-gradient(135deg, #fff5f5, #ffe4e1);
    border: 1px solid var(--uni-red-light, #e53935);
    border-radius: 10px;
    padding: 0.7em 0.7em 0.6em;
    position: relative;
    box-shadow: var(--shadow);
}
.pipe-step-num {
    position: absolute;
    top: -10px;
    left: -10px;
    background: var(--uni-red);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.75em;
}
.pipe-icon { font-size: 1.4em; margin-bottom: 0.2em; }
.pipe-title {
    font-weight: 800;
    color: var(--uni-red-deep);
    margin-bottom: 0.3em;
    font-size: 0.9em;
}
.pipe-detail {
    font-size: 0.7em;
    color: var(--ink-soft);
    line-height: 1.4;
    margin-bottom: 0.5em;
}
.pipe-tech {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.62em;
    background: white;
    padding: 0.2em 0.5em;
    border-radius: 4px;
    color: #6b7280;
    display: inline-block;
    margin-bottom: 0.4em;
}
.pipe-output {
    font-size: 0.65em;
    color: var(--uni-red);
    font-weight: 600;
    margin-top: 0.3em;
}
.pipe-arrow-flow {
    align-self: center;
    color: var(--uni-red);
    font-size: 1.1em;
    font-weight: 700;
    flex-shrink: 0;
}

/* Métricas pill */
.metrics-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    margin-top: 0.5em;
}
.metric-pill {
    background: white;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.4em 0.9em;
    font-size: 0.78em;
    display: flex;
    align-items: baseline;
    gap: 0.4em;
    box-shadow: var(--shadow);
}
.mp-label {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.05em;
}
.mp-value {
    color: var(--uni-red);
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
}

/* Feature importance */
.feature-importance { display: flex; flex-direction: column; gap: 0.35em; }
.fi-row {
    display: grid;
    grid-template-columns: 220px 1fr 50px;
    align-items: center;
    gap: 0.6em;
    font-size: 0.82em;
}
.fi-name code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.92em;
    color: var(--ink-soft);
}
.fi-bar {
    background: var(--paper-soft);
    border-radius: 999px;
    height: 12px;
    overflow: hidden;
}
.fi-fill {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #6366f1);
    border-radius: 999px;
}
.fi-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--ink);
}

@media (max-width: 900px) {
    .pipeline-flow { padding: 0.5em 0; }
    .pipe-box { min-width: 140px; padding: 0.6em 0.5em 0.5em; }
    .pipe-arrow-flow { font-size: 0.9em; }
    .fi-row { grid-template-columns: 130px 1fr 40px; font-size: 0.72em; }
}

/* ============== WhatsApp chip ============== */
.whatsapp-chip {
    display: flex;
    align-items: center;
    gap: 0.5em;
    background: #25D366;
    color: white;
    padding: 0.4em 0.8em 0.4em 0.7em;
    border-radius: 999px;
    text-decoration: none;
    font-size: 0.78em;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(37,211,102,0.35);
    transition: transform 0.15s, box-shadow 0.15s;
    line-height: 1.2;
}
.whatsapp-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37,211,102,0.5);
    color: white;
    text-decoration: none;
}
.wc-text { display: flex; flex-direction: column; }
.wc-title { font-weight: 700; font-size: 0.95em; }
.wc-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72em;
    opacity: 0.95;
}
@media (max-width: 900px) {
    .wc-text { display: none; }
    .whatsapp-chip { padding: 0.45em; }
}

/* ============== Course tab credits ============== */
.course-tab-credits {
    display: inline-block;
    background: rgba(0,0,0,0.08);
    padding: 0.05em 0.4em;
    border-radius: 999px;
    font-size: 0.85em;
    margin-left: 0.3em;
    font-weight: 700;
    color: var(--ink-soft);
}
.course-tab.active .course-tab-credits {
    background: rgba(255,255,255,0.25);
    color: white;
}
.credits-total {
    margin-left: auto;
    align-self: center;
    font-size: 0.78em;
    color: var(--muted);
    background: var(--paper-soft);
    padding: 0.4em 0.9em;
    border-radius: 999px;
    white-space: nowrap;
}

/* ============== Pipeline mejorado (link a notebook) ============== */
.stats-h-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.7em;
    margin-bottom: 0.5em;
}
.stats-h-row .stats-h { margin-bottom: 0; }
.notebook-link {
    background: #2d2d2d;
    color: white !important;
    text-decoration: none !important;
    padding: 0.4em 0.9em;
    border-radius: 999px;
    font-size: 0.78em;
    font-weight: 600;
    transition: all 0.15s;
}
.notebook-link:hover {
    background: var(--ink);
    transform: translateY(-1px);
}

a.pipe-box {
    color: inherit;
    text-decoration: none;
    transition: all 0.15s;
    display: block;
}
a.pipe-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    border-color: var(--uni-red);
}
.pipe-notebook-ref {
    margin-top: 0.5em;
    font-size: 0.55em;
    color: var(--muted);
    border-top: 1px dashed var(--line);
    padding-top: 0.4em;
    font-style: italic;
}

/* Feature importance source tags */
.fi-tag {
    display: inline-block;
    margin-left: 0.4em;
    padding: 0.05em 0.45em;
    border-radius: 3px;
    font-size: 0.65em;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.fi-real { background: #e9d5ff; color: #6b21a8; }
.fi-sim  { background: #d1fae5; color: #065f46; }
.fi-fill-sim { background: linear-gradient(90deg, var(--green), #4ade80); }

/* ============== Admin: gestor + sub-tabs ============== */
.admin-subtabs {
    display: flex;
    gap: 0.4em;
    margin: 1em 0;
    border-bottom: 1px solid var(--line);
}
.admin-subtabs .subtab {
    background: transparent;
    border: 1px solid var(--line);
    border-bottom: none;
    color: var(--ink-soft);
    padding: 0.45em 1em;
    border-radius: 8px 8px 0 0;
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: -1px;
}
.admin-subtabs .subtab.active {
    background: var(--uni-red-deep);
    color: white;
    border-color: var(--uni-red-deep);
}
.admin-pane { padding-top: 0.5em; }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1em;
}
.modal {
    background: white;
    border-radius: 12px;
    padding: 1.4em 1.6em;
    max-width: 680px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h3 {
    color: var(--uni-red-deep);
    margin-bottom: 1em;
    border-bottom: 2px solid var(--uni-red);
    padding-bottom: 0.4em;
}
.form-row {
    margin-bottom: 0.7em;
    display: flex;
    flex-direction: column;
}
.form-row label {
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0.25em;
}
.form-row input,
.form-row select,
.form-row textarea {
    padding: 0.5em 0.7em;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.92em;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus { outline: none; border-color: var(--uni-red); }
.form-row input:disabled { background: var(--paper-soft); color: var(--muted); }

.checks-grid {
    max-height: 220px;
    overflow-y: auto;
    background: var(--paper-soft);
    border-radius: 6px;
    padding: 0.5em;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.2em 0.5em;
    font-size: 0.78em;
}
.checks-grid label {
    display: flex;
    align-items: center;
    gap: 0.3em;
    padding: 0.15em 0.3em;
    cursor: pointer;
    border-radius: 4px;
    color: var(--ink);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    font-size: 1em;
    margin: 0;
}
.checks-grid label:hover { background: white; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6em;
    margin-top: 1.2em;
    padding-top: 0.7em;
    border-top: 1px solid var(--line);
}

@media (max-width: 540px) {
    .checks-grid { grid-template-columns: 1fr; }
}

/* ============== Logs · header + live ============== */
.logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.7em;
    margin-bottom: 0.5em;
}
.live-toggle {
    display: flex;
    align-items: center;
    gap: 0.5em;
    font-size: 0.82em;
    color: var(--ink-soft);
    cursor: pointer;
    user-select: none;
}
.live-toggle input { cursor: pointer; }
.live-toggle .live-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px rgba(34,197,94,0.6);
    display: inline-block;
    animation: pulse-live 1.5s infinite;
}
.live-toggle input:not(:checked) ~ .live-dot {
    background: #cbd5e1;
    box-shadow: none;
    animation: none;
}
@keyframes pulse-live {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.3); opacity: 0.6; }
}

/* ============== Wellness · termómetro ============== */
.wellness-section { margin-bottom: 1.4em; }
.wellness-block {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    border: 1px solid #bbf7d0;
    border-left: 5px solid #16a34a;
    border-radius: 12px;
    padding: 0.9em 1.1em;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.6em;
}
.wellness-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--muted);
    font-style: italic;
    padding: 1.2em 0.5em;
    font-size: 0.85em;
}
.wellness-card {
    background: white;
    border-radius: 10px;
    padding: 0.7em 0.6em;
    text-align: center;
}
.wc-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
    margin-bottom: 0.3em;
}
.wc-icon { font-size: 1.1em; }
.wc-label {
    font-size: 0.65em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
}
.wc-value {
    font-size: 1.8em;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.3em;
}
.wc-of {
    font-size: 0.45em;
    color: var(--muted);
    font-weight: 600;
}
.wc-bar {
    background: #f3f4f6;
    height: 5px;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.3em;
}
.wc-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s;
}
.wc-spark {
    display: flex;
    justify-content: center;
    min-height: 24px;
}
.wellness-notes {
    grid-column: 1 / -1;
    background: white;
    border-radius: 8px;
    padding: 0.7em 0.9em;
    margin-top: 0.3em;
}
.wc-note {
    padding: 0.5em 0;
    border-bottom: 1px dashed var(--line);
    font-size: 0.78em;
}
.wc-note:last-child { border-bottom: none; }
.wc-note-date {
    font-size: 0.85em;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.wc-note-summary {
    color: var(--ink);
    margin-top: 0.15em;
    line-height: 1.4;
}
.wc-note-evidence {
    color: var(--ink-soft);
    font-style: italic;
    margin-top: 0.2em;
    padding-left: 0.7em;
    border-left: 2px solid var(--green);
    font-size: 0.92em;
}

@media (max-width: 900px) {
    .wellness-block { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 540px) {
    .wellness-block { grid-template-columns: 1fr 1fr; }
}
