/* Plan de estudio personalizado (página de Recomendaciones del estudiante). */
.study-plan {
    --sp-ink: var(--color-brand-navy, #171d46);
    --sp-muted: var(--color-muted, #66708a);
    --sp-accent: var(--color-brand-blue, #176b9f);
    --sp-accent-dark: var(--color-brand-blue-dark, #115582);
    --sp-accent-soft: #edf5fc;
    --sp-surface: #f5f8fc;
    --sp-border: #e6ebf2;
    display: grid;
    gap: 18px;
    min-width: 0;
    color: var(--sp-ink);
}
.study-plan svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Encabezado */
.study-plan .sp-header { margin-bottom: 4px; }
.sp-course { position: relative; }
.sp-course-button { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 340px; padding: 8px 12px; border: 1px solid var(--t-line); border-radius: 8px; background: var(--t-surface); color: var(--sp-ink); font: inherit; text-align: left; cursor: pointer; }
.sp-course-button:hover:not(:disabled) { border-color: #b8cee4; background: var(--t-subtle); }
.sp-course-button:focus-visible, .sp-chip:focus-visible, .sp-button:focus-visible, .sp-vote:focus-visible, .sp-detail-toggle:focus-visible, .sp-bars button:focus-visible { outline: 2px solid var(--sp-accent); outline-offset: 2px; }
.sp-course-button > svg:first-child { flex-shrink: 0; width: 18px; height: 18px; color: var(--sp-accent); }
.sp-course-text { display: grid; flex: 1; min-width: 0; }
.sp-course-text strong, .sp-course-menu strong { overflow: hidden; font-size: calc(13px * var(--ui-scale, 1)); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.sp-course-text small, .sp-course-menu small { color: var(--sp-muted); font-size: calc(11px * var(--ui-scale, 1)); }
.sp-chevron { flex-shrink: 0; width: 16px; height: 16px; transition: transform .15s; }
[aria-expanded="true"] > .sp-chevron { transform: rotate(180deg); }
.sp-backdrop { position: fixed; inset: 0; z-index: 20; }
.sp-course-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 21; width: min(340px, calc(100vw - 32px)); max-height: 360px; margin: 0; padding: 6px; overflow-y: auto; list-style: none; border: 1px solid var(--sp-border); border-radius: 10px; background: var(--t-surface); box-shadow: 0 18px 40px #17204624; }
.sp-course-menu button { display: grid; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--sp-ink); font: inherit; text-align: left; cursor: pointer; }
.sp-course-menu button:hover, .sp-course-menu button[aria-selected="true"] { background: var(--sp-accent-soft); }
.sp-course-menu button[aria-selected="true"] strong { color: var(--sp-accent-dark); }
.sp-course-error { padding: 9px 10px; color: var(--sp-muted); font-size: calc(12px * var(--ui-scale, 1)); }

/* ¿Por qué? + precisión */
.sp-why { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 20px; padding: 18px 22px; border: 1px solid var(--sp-border); border-radius: 14px; background: var(--t-surface); }
.sp-why-text { display: flex; align-items: center; gap: 14px; min-width: 0; }
.sp-why-icon { display: grid; flex-shrink: 0; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: var(--sp-accent-soft); color: var(--sp-accent); }
.sp-why-icon svg { width: 24px; height: 24px; stroke-width: 2.4; }
.sp-why-text strong { font-size: calc(16px * var(--ui-scale, 1)); }
.sp-why-text p { margin: 4px 0 0; color: var(--t-muted); font-size: calc(13px * var(--ui-scale, 1)); line-height: 1.5; }
.sp-why-text b { color: var(--sp-ink); font-weight: 650; }
.sp-precision { display: flex; align-items: center; gap: 12px; min-width: 250px; padding-left: 22px; border-left: 1px solid var(--sp-border); }
.sp-precision > div { display: grid; flex: 1; gap: 2px; }
.sp-precision span:not(.sp-precision-icon) { color: var(--sp-muted); font-size: calc(12px * var(--ui-scale, 1)); }
.sp-precision strong { font-size: calc(28px * var(--ui-scale, 1)); font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.sp-precision small { color: var(--sp-muted); font-size: calc(10px * var(--ui-scale, 1)); }
.sp-precision-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: var(--t-subtle); color: var(--color-brand-red, #c53736); }
.sp-precision-icon svg { width: 26px; height: 26px; }
.sp-precision-bar { height: 7px; margin: 4px 0 2px; overflow: hidden; border-radius: 99px; background: #e6ebf2; }
.sp-precision-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--sp-accent); transition: width .4s ease; }
.sp-precision-good .sp-precision-bar > span { background: #1f9a62; }
.sp-precision-fair .sp-precision-bar > span { background: #e0a21d; }
.sp-precision-low .sp-precision-bar > span { background: #d0383f; }

/* Pestañas de categoría */
.sp-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.sp-chip { --cat: #49506e; --cat-soft: #f1f2f6; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 6px 13px; border: 1px solid var(--t-line); border-radius: 999px; background: var(--t-surface); color: var(--sp-ink); font: inherit; font-size: calc(12px * var(--ui-scale, 1)); font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.sp-chip .category-glyph, .sp-chip > svg { width: 16px; height: 16px; color: var(--cat); }
.sp-chip:hover { border-color: var(--cat); background: var(--cat-soft); }
.sp-chip[aria-pressed="true"] { border-color: var(--cat); background: var(--cat); color: #fff; }
.sp-chip[aria-pressed="true"] .category-glyph { color: #fff; }
.sp-chip-all { --cat: var(--sp-accent); --cat-soft: var(--sp-accent-soft); }
.sp-chip-all > svg { fill: currentColor; }
.sp-chip-all[aria-pressed="true"] > svg { color: #fff; }
.sp-chip-count { min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--cat-soft); color: var(--cat); font-size: calc(11px * var(--ui-scale, 1)); font-weight: 700; text-align: center; }
.sp-chip[aria-pressed="true"] .sp-chip-count { background: #ffffff33; color: #fff; }

/* Detalle desplegable */
.sp-detail { border: 1px solid var(--sp-border); border-radius: 14px; background: var(--t-surface); }
.sp-detail-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 13px 18px; border: 0; border-radius: 14px; background: transparent; color: var(--sp-ink); font: inherit; text-align: left; cursor: pointer; }
.sp-detail-toggle > span { display: grid; gap: 2px; min-width: 0; }
.sp-detail-toggle strong { font-size: calc(14px * var(--ui-scale, 1)); }
.sp-detail-toggle small { color: var(--sp-muted); font-size: calc(12px * var(--ui-scale, 1)); }
.sp-detail-body { display: grid; gap: 16px; padding: 4px 18px 18px; border-top: 1px solid var(--t-line); }
.sp-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0 0; }
.sp-kpis div { padding: 11px 12px; border-radius: 10px; background: var(--sp-surface); }
.sp-kpis dt { color: var(--sp-muted); font-size: calc(11px * var(--ui-scale, 1)); }
.sp-kpis dd { margin: 4px 0 0; font-size: calc(20px * var(--ui-scale, 1)); font-weight: 750; }
.sp-kpis dd small { color: var(--sp-muted); font-size: calc(11px * var(--ui-scale, 1)); font-weight: 500; }
.sp-bars { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.sp-bars button { display: grid; grid-template-columns: minmax(110px, 190px) minmax(0, 1fr) minmax(110px, auto); align-items: center; gap: 12px; width: 100%; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--sp-ink); font: inherit; text-align: left; cursor: pointer; }
.sp-bars button:hover:not(:disabled), .sp-bars button[aria-pressed="true"] { border-color: var(--cat); background: var(--cat-soft); }
.sp-bars button:disabled { cursor: default; opacity: .7; }
.sp-bar-name { overflow: hidden; font-size: calc(12px * var(--ui-scale, 1)); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.sp-bar-track { height: 8px; overflow: hidden; border-radius: 99px; background: var(--t-subtle); }
.sp-bar-track > span { display: block; height: 100%; border-radius: inherit; background: var(--cat); }
.sp-bar-value { font-size: calc(13px * var(--ui-scale, 1)); font-weight: 700; white-space: nowrap; }
.sp-bar-value small { color: var(--sp-muted); font-size: calc(11px * var(--ui-scale, 1)); font-weight: 500; }
.sp-muted { margin: 12px 0 0; color: var(--sp-muted); font-size: calc(13px * var(--ui-scale, 1)); }

/* Estados */
.sp-notice { margin: 0; padding: 16px 18px; border: 1px solid var(--sp-border); border-radius: 12px; background: var(--sp-surface); font-size: calc(13px * var(--ui-scale, 1)); }
.sp-notice.is-error { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; border-color: #f3c9c7; background: var(--t-subtle); color: #9c2c2b; }
.sp-notice.is-error p { margin: 0; }
.sp-empty { display: grid; justify-items: center; gap: 8px; padding: 36px 16px; border: 1px dashed var(--t-line); border-radius: 14px; background: var(--t-surface); text-align: center; color: var(--sp-muted); font-size: calc(13px * var(--ui-scale, 1)); }
.sp-empty svg { width: 34px; height: 34px; color: var(--sp-accent); }
.sp-empty strong { color: var(--sp-ink); font-size: calc(16px * var(--ui-scale, 1)); }
.sp-empty .data-table-button { margin-top: 6px; text-decoration: none; }

/* Tarjetas */
.sp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.sp-card { --cat: #49506e; --cat-soft: #f1f2f6; display: grid; gap: 12px; min-width: 0; padding: 16px; border: 1px solid var(--sp-border); border-radius: 14px; background: var(--t-surface); box-shadow: 0 1px 2px #1720460a; transition: box-shadow .15s, border-color .15s; }
.sp-card:hover { border-color: var(--t-line); box-shadow: 0 10px 24px #17204614; }
.sp-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sp-tag { display: inline-flex; align-items: center; gap: 6px; max-width: 60%; padding: 5px 11px; overflow: hidden; border-radius: 8px; background: var(--cat-soft); color: var(--cat); font-size: calc(12px * var(--ui-scale, 1)); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.sp-tag .category-glyph { flex-shrink: 0; width: 15px; height: 15px; }
.sp-priority { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border: 1px solid; border-radius: 8px; font-size: calc(11px * var(--ui-scale, 1)); font-weight: 650; white-space: nowrap; }
.sp-priority svg { width: 14px; height: 14px; }
.sp-priority-alta { border-color: #f5c6c4; background: var(--t-subtle); color: #c2322f; }
.sp-priority-media { border-color: #c6e8d3; background: var(--t-subtle); color: #1f8350; }
.sp-priority-baja { border-color: #cbdcf5; background: var(--t-subtle); color: var(--t-accent); }
.sp-card-body { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 16px; }
.sp-thumb { position: relative; display: grid; align-content: start; gap: 8px; height: 148px; padding: 14px 12px; overflow: hidden; border: 1px solid var(--t-line); border-radius: 6px; background: linear-gradient(180deg, #fff, #f7f9fd); box-shadow: 4px 4px 0 -1px #fff, 4px 4px 0 0 #e3e6ef, 0 8px 18px #1d1a5a12; }
.sp-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sp-thumb-title { color: var(--cat); font-size: calc(12px * var(--ui-scale, 1)); font-weight: 750; line-height: 1.25; overflow-wrap: anywhere; }
.sp-thumb-lines { display: grid; gap: 5px; }
.sp-thumb-lines i { display: block; height: 3px; border-radius: 2px; background: #dfe3ec; }
.sp-thumb-lines i:nth-child(2) { width: 80%; }
.sp-thumb-lines i:nth-child(3) { width: 90%; }
.sp-thumb-lines i:nth-child(4) { width: 60%; }
.sp-thumb-wave { position: absolute; right: -10px; bottom: -14px; left: -10px; height: 52px; border-radius: 50% 50% 0 0; background: linear-gradient(90deg, var(--cat-soft), color-mix(in srgb, var(--cat) 35%, #fff)); }
.sp-thumb-icon { position: absolute; right: 6px; bottom: 6px; }
.sp-thumb-icon .file-icon { width: 26px; height: 31px; }
.sp-card-content { display: grid; align-content: start; gap: 6px; min-width: 0; }
.sp-card-content h3 { display: -webkit-box; margin: 0; overflow: hidden; font-size: calc(16px * var(--ui-scale, 1)); font-weight: 700; line-height: 1.35; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.sp-card-content > p:not(.sp-meta) { display: -webkit-box; margin: 0; overflow: hidden; color: var(--t-muted); font-size: calc(13px * var(--ui-scale, 1)); line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 0 0; color: var(--sp-muted); font-size: calc(12px * var(--ui-scale, 1)); }
.sp-meta svg { width: 14px; height: 14px; }
.sp-badge { padding: 2px 8px; border-radius: 99px; background: var(--sp-accent-soft); color: var(--sp-accent-dark); font-size: calc(11px * var(--ui-scale, 1)); font-weight: 600; }
.sp-badge-seen { background: var(--t-subtle); color: #1f8350; }
.sp-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: auto; padding-top: 8px; }
.sp-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 7px 12px; border: 1px solid var(--t-line); border-radius: 8px; background: var(--t-surface); color: var(--sp-accent); font: inherit; font-size: calc(12px * var(--ui-scale, 1)); font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s; }
.sp-button svg { width: 16px; height: 16px; flex-shrink: 0; }
.sp-button:hover:not(:disabled) { border-color: var(--sp-accent); background: var(--sp-accent-soft); }
.sp-button:disabled { opacity: .55; cursor: not-allowed; }
.sp-button.sp-button-primary { border-color: var(--sp-accent); background: var(--sp-accent); color: #fff; }
.sp-button.sp-button-primary:hover:not(:disabled) { border-color: var(--sp-accent-dark); background: var(--sp-accent-dark); color: #fff; }
.sp-button.sp-button-outline { border-color: var(--sp-accent); color: var(--sp-accent); }

.sp-actions .sp-helpful { min-height: 36px; }

/* Banda de valoración */
.sp-feedback { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 16px 20px; border: 1px solid var(--t-line); border-radius: 14px; background: var(--t-subtle); }
.sp-feedback-icon { color: var(--sp-accent); }
.sp-feedback-icon svg { width: 30px; height: 30px; stroke-width: 2.2; }
.sp-feedback-text { display: grid; gap: 2px; min-width: 0; }
.sp-feedback-text strong { overflow: hidden; font-size: calc(14px * var(--ui-scale, 1)); text-overflow: ellipsis; white-space: nowrap; }
.sp-feedback-text span { color: var(--sp-muted); font-size: calc(12px * var(--ui-scale, 1)); }
.sp-feedback-error { color: #a33740; font-size: calc(12px * var(--ui-scale, 1)); }
.sp-feedback-actions { display: flex; align-items: center; gap: 10px; }
.sp-vote { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--t-line); border-radius: 50%; background: var(--t-surface); color: var(--sp-accent); cursor: pointer; }
.sp-vote svg { width: 18px; height: 18px; }
.sp-vote:hover:not(:disabled) { border-color: var(--sp-accent); background: var(--sp-accent-soft); }
.sp-vote[aria-pressed="true"], .sp-vote[aria-pressed="true"]:hover:not(:disabled) { border-color: var(--sp-accent); background: var(--sp-accent); color: #fff; }
.sp-vote:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 980px) {
    .sp-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .sp-course { grid-column: 1 / -1; }
    .sp-course-button { width: 100%; max-width: none; }
    .sp-why { grid-template-columns: 1fr; }
    .sp-precision { padding: 14px 0 0; border-top: 1px solid var(--t-line); border-left: 0; }
    .sp-bars button { grid-template-columns: minmax(0, 1fr) auto; }
    .sp-bar-track { grid-column: 1 / -1; grid-row: 2; }
    .sp-feedback { grid-template-columns: auto minmax(0, 1fr); }
    .sp-feedback-actions { grid-column: 1 / -1; justify-content: flex-end; }
}
@media (max-width: 480px) {
    .sp-card-body { grid-template-columns: 1fr; }
    .sp-thumb { height: 110px; }
    .sp-actions { grid-template-columns: 1fr; }
}

/* Plan incrustado en Inicio: mismo estilo que la página, con h2. */
.study-plan .sp-header h2 { margin: 0; font-size: calc(24px * var(--ui-scale, 1)); font-weight: 700; letter-spacing: -.03em; }
.study-plan .sp-header h2 + p { margin: 8px 0 0; color: var(--t-muted); font-size: calc(13px * var(--ui-scale, 1)); }
.users-page > .study-plan { margin: 18px 0; }
