/* =====================================================================
   SIA TecnoCaribe — Estilos institucionales
   Paleta: Azul marino #003366 · Celeste #0099FF · Dorado #FFC000 · Gris #F8F9FA
   ===================================================================== */
:root {
    --inst-navy: #003366;
    --inst-navy-dark: #00264d;
    --inst-navy-light: #0b4a85;
    --inst-sky: #0099FF;
    --inst-gold: #FFC000;
    --inst-gray: #F8F9FA;
    --header-h: 60px;
    --footer-h: 36px;
    --sidebar-w: 262px;
    --bs-primary: #003366;
    --bs-primary-rgb: 0, 51, 102;
    --bs-link-color: #0077cc;
    --bs-link-hover-color: #0099FF;
    --bs-body-bg: #F8F9FA;
    --bs-font-sans-serif: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { background: var(--inst-gray); }

/* ---------- Botones y componentes con la paleta ---------- */
.btn-primary { --bs-btn-bg: var(--inst-navy); --bs-btn-border-color: var(--inst-navy); --bs-btn-hover-bg: var(--inst-navy-light);
    --bs-btn-hover-border-color: var(--inst-navy-light); --bs-btn-active-bg: var(--inst-navy-dark); --bs-btn-active-border-color: var(--inst-navy-dark);
    --bs-btn-disabled-bg: #5d7a97; --bs-btn-disabled-border-color: #5d7a97; }
.btn-outline-primary { --bs-btn-color: var(--inst-navy); --bs-btn-border-color: var(--inst-navy); --bs-btn-hover-bg: var(--inst-navy);
    --bs-btn-hover-border-color: var(--inst-navy); --bs-btn-active-bg: var(--inst-navy-dark); }
.btn-sky { --bs-btn-color: #fff; --bs-btn-bg: var(--inst-sky); --bs-btn-border-color: var(--inst-sky); --bs-btn-hover-bg: #0084db;
    --bs-btn-hover-border-color: #0084db; --bs-btn-hover-color: #fff; --bs-btn-active-bg: #0070bb; --bs-btn-active-color: #fff; }
.btn-gold, .btn-edit { --bs-btn-color: #2b2100; --bs-btn-bg: var(--inst-gold); --bs-btn-border-color: var(--inst-gold);
    --bs-btn-hover-bg: #e6ad00; --bs-btn-hover-border-color: #e6ad00; --bs-btn-hover-color: #2b2100; --bs-btn-active-bg: #cc9a00; }
.text-navy { color: var(--inst-navy) !important; }
.text-sky { color: var(--inst-sky) !important; }
.bg-navy { background: var(--inst-navy) !important; color: #fff; }
.bg-gold { background: var(--inst-gold) !important; color: #2b2100; }
.badge-gold { background: var(--inst-gold); color: #2b2100; }
a { color: #0077cc; }
a:hover { color: var(--inst-sky); }
.form-control:focus, .form-select:focus { border-color: var(--inst-sky); box-shadow: 0 0 0 .2rem rgba(0, 153, 255, .2); }
.form-check-input:checked { background-color: var(--inst-navy); border-color: var(--inst-navy); }
.nav-tabs .nav-link.active { color: var(--inst-navy); border-top: 3px solid var(--inst-sky); font-weight: 600; }
.nav-tabs .nav-link { color: #4b5d70; }
.page-link { color: var(--inst-navy); }
.page-item.active .page-link { background: var(--inst-navy); border-color: var(--inst-navy); }
.page-link:hover { color: var(--inst-sky); }
.alert-warning { border-left: 4px solid var(--inst-gold); }
.required::after { content: " *"; color: #d63384; }

/* ---------- Header fijo ---------- */
.app-header { height: var(--header-h); background: var(--inst-navy); border-bottom: 3px solid var(--inst-gold); z-index: 1040; }
.app-badge-sistema { background: rgba(255,255,255,.12); color: #e9f4ff; font-weight: 500; border: 1px solid rgba(255,255,255,.2); }
.app-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--inst-gold); color: var(--inst-navy); display: inline-flex;
    align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.app-rol { font-size: .72rem; color: #b8d4ef; }

/* ---------- Sidebar ---------- */
.app-sidebar, .offcanvas-lg.app-sidebar { background-color: var(--inst-navy-dark) !important; width: var(--sidebar-w); }
@media (min-width: 992px) {
    .app-sidebar { position: fixed; top: var(--header-h); bottom: var(--footer-h); left: 0; overflow-y: auto; }
    .app-main { margin-left: var(--sidebar-w); }
}
.app-sidebar .offcanvas-header { background: var(--inst-navy); }
.app-nav { padding: .75rem .5rem 1.5rem; }
.app-nav-top, .app-nav-group { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .6rem .8rem; border-radius: .5rem;
    color: #dbe8f5; text-decoration: none; background: transparent; border: 0; font-weight: 600; font-size: .92rem; text-align: left; }
.app-nav-top:hover, .app-nav-group:hover { background: rgba(255,255,255,.07); color: #fff; }
.app-nav-top.active { background: var(--inst-sky); color: #fff; }
.app-nav-group .app-chevron { transition: transform .2s; font-size: .75rem; }
.app-nav-group.collapsed .app-chevron { transform: rotate(-90deg); }
.app-nav-section { margin-bottom: .15rem; }
.app-nav-link { display: block; padding: .42rem .8rem .42rem 2.45rem; color: #b8cde2; text-decoration: none; font-size: .87rem;
    border-left: 3px solid transparent; border-radius: 0 .4rem .4rem 0; margin: 1px 0; }
.app-nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.app-nav-link.active { color: #fff; border-left-color: var(--inst-sky); background: rgba(0,153,255,.18); font-weight: 600; }
.app-nav-link.destacado { color: var(--inst-gold); font-weight: 600; }
.app-nav-link.destacado.active { color: #fff; }

/* ---------- Contenido y footer fijo ---------- */
.app-main { padding-top: var(--header-h); padding-bottom: calc(var(--footer-h) + 1rem); min-height: 100vh; }
.app-footer { position: fixed; bottom: 0; left: 0; right: 0; height: var(--footer-h); background: #fff; border-top: 1px solid #dee2e6;
    display: flex; align-items: center; justify-content: space-between; padding: 0 1rem; font-size: .78rem; color: #6c757d; z-index: 1030; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { font-size: 1.4rem; color: var(--inst-navy); margin: 0; font-weight: 700; }
.page-head .breadcrumb { margin: 0; font-size: .8rem; }
.card { border: 1px solid #e3e8ee; border-radius: .75rem; }
.card-header { background: #fff; border-bottom: 1px solid #e9eef3; font-weight: 600; color: var(--inst-navy); }
.card-accent { border-top: 3px solid var(--inst-sky); }

/* Tablas */
.table-inst thead th { background: var(--inst-navy); color: #fff; font-weight: 600; font-size: .8rem; white-space: nowrap; vertical-align: middle;
    border-color: var(--inst-navy-light); }
.table-inst tbody td { font-size: .86rem; vertical-align: middle; }
.table-inst tfoot td, .table-inst tfoot th { background: #fff8db; font-weight: 700; color: var(--inst-navy); }
.table-inst tbody tr:hover { background: #f1f8ff; }
.table-responsive { border-radius: .5rem; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

/* KPIs */
.kpi { border: 0; border-radius: .9rem; background: #fff; box-shadow: 0 1px 3px rgba(0,30,60,.08); padding: 1rem 1.1rem; height: 100%;
    border-left: 4px solid var(--inst-sky); }
.kpi.kpi-gold { border-left-color: var(--inst-gold); }
.kpi.kpi-navy { border-left-color: var(--inst-navy); }
.kpi.kpi-danger { border-left-color: #dc3545; }
.kpi-label { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: #5b6f84; font-weight: 600; }
.kpi-value { font-size: 1.45rem; font-weight: 700; color: var(--inst-navy); line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi-icon { font-size: 1.6rem; color: var(--inst-sky); opacity: .85; }
.total-hoy { background: linear-gradient(120deg, var(--inst-navy), var(--inst-navy-light)); color: #fff; border-radius: 1rem; padding: 1.1rem 1.4rem;
    border-bottom: 4px solid var(--inst-gold); }
.total-hoy .valor { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Barras simples */
.bar-row { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: .6rem; align-items: center; font-size: .82rem; margin-bottom: .45rem; }
.bar-track { background: #eaf2fa; border-radius: 999px; height: 9px; overflow: hidden; }
.bar-fill { background: var(--inst-sky); height: 100%; border-radius: 999px; }

/* Autocompletar */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 1060; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid #cfd8e3; border-radius: .5rem;
    box-shadow: 0 .5rem 1rem rgba(0,0,0,.12); max-height: 320px; overflow-y: auto; display: none; }
.ac-list.show { display: block; }
.ac-item { padding: .5rem .75rem; cursor: pointer; border-bottom: 1px solid #f0f3f6; font-size: .88rem; }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.active { background: #e8f5ff; }
.ac-item small { color: #6c757d; }
.ac-empty { padding: .6rem .75rem; color: #6c757d; font-size: .85rem; }

/* Selección de estudiante */
.selected-card { border: 1px dashed var(--inst-sky); background: #f3faff; border-radius: .75rem; }

/* Wizard de matrícula */
.wizard-step { border-left: 3px solid #dbe5ef; padding-left: 1rem; margin-bottom: 1.25rem; }
.wizard-step.done { border-left-color: var(--inst-sky); }
.wizard-num { width: 28px; height: 28px; border-radius: 50%; background: var(--inst-navy); color: #fff; display: inline-flex; align-items: center;
    justify-content: center; font-weight: 700; font-size: .85rem; margin-right: .5rem; }

/* Planilla de notas */
.grade-input { width: 4.6rem; text-align: center; font-weight: 600; }
.grade-input.changed { background: #fff6d6; border-color: var(--inst-gold); }
.grade-input.new-grade { background: #eaf7ff; border-color: var(--inst-sky); }
.grade-low { color: #c1121f; }
.badge-promedio { background: var(--inst-gold); color: #2b2100; font-weight: 700; }
.nota-audit { font-size: .7rem; color: #6c757d; display: block; line-height: 1.2; }

/* Login */
.auth-body { min-height: 100vh; background: radial-gradient(circle at top right, var(--inst-navy-light), var(--inst-navy) 45%, var(--inst-navy-dark)); }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 480px; border-radius: 1.1rem; overflow: hidden; }
.auth-card.wide { max-width: 640px; }
.auth-brand { background: #fff; padding: 1.5rem 1.75rem .9rem; text-align: center; border-bottom: 4px solid var(--inst-gold); }
.auth-brand img { max-width: 340px; width: 100%; height: auto; }

/* Recibo */
.recibo { max-width: 820px; margin: 0 auto; background: #fff; border: 1px solid #dfe5ec; border-radius: .75rem; padding: 1.5rem; }
.recibo-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 3px solid var(--inst-gold); padding-bottom: .75rem; }
.recibo-num { background: var(--inst-navy); color: #fff; border-radius: .5rem; padding: .5rem .9rem; text-align: right; }
.recibo-num .n { font-size: 1.15rem; font-weight: 700; letter-spacing: .03em; }
.recibo-anulado { position: relative; }
.recibo-anulado::after { content: "ANULADO"; position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); font-size: 5rem;
    font-weight: 900; color: rgba(220, 53, 69, .18); pointer-events: none; }

/* Impresión */
.print-body { background: #fff; }
.print-toolbar { padding: .5rem 1rem; background: #f1f4f8; display: flex; gap: .5rem; }
.print-page { padding: 1rem 1.25rem; }
.print-header { display: flex; align-items: center; gap: 1rem; border-bottom: 3px solid var(--inst-gold); padding-bottom: .6rem; margin-bottom: .8rem; }
.print-header img { height: 54px; }
.print-inst { font-weight: 700; color: var(--inst-navy); font-size: 1.05rem; }
.print-footer { margin-top: 1rem; font-size: .72rem; color: #6c757d; border-top: 1px solid #dee2e6; padding-top: .4rem; }
.print-table { font-size: .72rem; }
.print-table th { background: var(--inst-navy) !important; color: #fff !important; }

@media print {
    @page { size: auto; margin: 12mm 10mm; }
    .no-print, .app-header, .app-sidebar, .app-footer, .page-head .btn, .btn, form.filters, .pagination, #app-alerts { display: none !important; }
    .app-main { margin: 0 !important; padding: 0 !important; }
    body { background: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .card { border: 0 !important; box-shadow: none !important; }
    .table-inst thead th { background: var(--inst-navy) !important; color: #fff !important; }
    a { color: inherit; text-decoration: none; }
    .recibo { border: 0; }
}

@media (max-width: 575.98px) {
    .page-head h1 { font-size: 1.2rem; }
    .kpi-value { font-size: 1.2rem; }
    .total-hoy .valor { font-size: 1.5rem; }
}

/* ---- Columnas ordenables ---- */
th.th-sort a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; }
th.th-sort a:hover, th.th-sort a:focus-visible { text-decoration: underline; }
th.th-sort .sort-ind { font-size: .7em; opacity: .45; }
th.th-sort.sorted .sort-ind { opacity: 1; color: var(--inst-gold); }
.table-light th.th-sort.sorted .sort-ind, thead.table-light th.th-sort.sorted .sort-ind { color: var(--inst-sky); }
@media print { th.th-sort .sort-ind { display: none; } }

/* ---- Registros anulados / eliminados en vistas históricas ---- */
tr.row-anulado td { color: #6c757d; }
tr.row-eliminado td { color: #842029; background: #fff5f5; }
tr.row-eliminado td.tachado, tr.row-anulado td.tachado { text-decoration: line-through; }
.zona-peligro { border: 1px solid #f1aeb5; border-radius: .5rem; background: #fff8f8; }
.quick-actions .btn { display: flex; align-items: center; gap: .5rem; justify-content: flex-start; }
.report-card { transition: box-shadow .15s; }
.report-card:hover { box-shadow: 0 .25rem .75rem rgba(0, 51, 102, .15); }
.boletin-salto { page-break-before: always; break-before: page; height: 0; margin: 2rem 0; border-top: 2px dashed #ccd; }
@media print { .boletin-salto { border: 0; margin: 0; } }

/* ---------- Calendario de los campos de fecha (v1.5) ---------- */
.input-group-fecha { flex-wrap: nowrap; }
.cal-btn { display: inline-flex; align-items: center; color: var(--bs-secondary-color, #6c757d); }
.cal-btn:hover, .cal-btn[aria-expanded="true"] { color: #fff; background: #003366; border-color: #003366; }
.cal-pop { position: absolute; z-index: 1090; width: 272px; background: #fff; border: 1px solid #d0d7de; border-radius: .5rem; padding: .5rem; font-size: .875rem; }
.cal-head { display: flex; gap: .25rem; align-items: center; margin-bottom: .35rem; }
.cal-head select[data-mes] { flex: 1.4; }
.cal-head select[data-anio] { flex: 1; }
.cal-head .btn { padding: .1rem .55rem; font-size: 1.1rem; line-height: 1.2; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: .72rem; font-weight: 600; color: #6c757d; padding: .15rem 0; }
.cal-day { border: 0; background: transparent; border-radius: .35rem; padding: .32rem 0; text-align: center; color: #212529; }
.cal-day:hover:not([disabled]), .cal-day:focus-visible { background: #e7f1fb; outline: none; }
.cal-day.hoy { box-shadow: inset 0 0 0 1px #0d6efd; font-weight: 600; }
.cal-day.sel { background: #003366; color: #fff; font-weight: 600; }
.cal-day[disabled] { color: #c3c8cd; cursor: not-allowed; }
.cal-foot { display: flex; justify-content: space-between; border-top: 1px solid #eef0f2; margin-top: .35rem; padding-top: .25rem; }
.cal-foot .btn { padding: .1rem .35rem; font-size: .8rem; text-decoration: none; }
@media print { .cal-btn, .cal-pop { display: none !important; } }
.total-hoy-compacto { padding: .7rem 1rem; border-radius: .75rem; }
.total-hoy-compacto .valor { font-size: 1.6rem; }

/* ---------- Membrete institucional en documentos HTML (v1.5) ---------- */
.membrete { display: flex; gap: 1rem; align-items: center; }
.membrete-logo { height: 58px; width: auto; max-width: 45%; object-fit: contain; }
.membrete-texto { line-height: 1.25; }
.recibo-membrete { display: flex; gap: .9rem; align-items: center; }
.recibo-membrete .print-inst { font-weight: 700; color: var(--inst-navy, #003366); }
.cert-head.membrete .membrete-logo { height: auto; width: 1.85in; max-width: none; }
.cert-head .print-inst { font-weight: 700; color: #003366; font-size: 12pt; line-height: 1.2; }
.documento-pie { text-align: center; font-weight: 600; color: #003366; border-top: 1px solid #dee2e6; margin-top: 1rem; padding-top: .3rem; font-size: .8rem; }
.diploma .escudo { width: auto; height: .95in; }

/* v1.6: roles */
.rol-badge { background: #eef3fa; color: #003366; border: 1px solid #c9d8ec; font-weight: 600; }
.permisos-modulo legend { font-size: .95rem; }
.matriz-permisos th, .matriz-permisos td { white-space: nowrap; }
.matriz-permisos td:first-child { white-space: normal; }
@media print { .matriz-permisos { font-size: 9px; } }

/* v1.7: libro de asistencia */
.libro-asistencia { max-height: 70vh; }
.libro-asistencia table { font-size: .85rem; }
.libro-asistencia thead th { position: sticky; top: 0; z-index: 2; background: #f1f4f8; }
.libro-asistencia .libro-fijo { position: sticky; left: 0; z-index: 1; background: #fff; min-width: 210px; box-shadow: 1px 0 0 #dee2e6; }
.libro-asistencia thead .libro-fijo { z-index: 3; background: #f1f4f8; }
.libro-asistencia .libro-sesion { min-width: 46px; white-space: nowrap; }
.libro-asistencia .libro-celda .badge { min-width: 1.6em; }
.libro-celda-vacia { color: #adb5bd; font-weight: 700; }

/* ===== Editor de plantillas de documentos (v1.8) ===== */
.editor-lienzo { display: flex; flex-direction: column; gap: 1rem; align-items: center; min-height: 200px; }
.editor-hoja { position: relative; width: 100%; max-width: 820px; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .14); user-select: none; }
.editor-hoja svg { display: block; width: 100%; height: auto; }
.editor-capa { position: absolute; inset: 0; }
.editor-caja { position: absolute; outline: 1px dashed rgba(0, 51, 102, .35); cursor: move; touch-action: none; min-height: 4px; }
.editor-caja.flujo { outline-color: rgba(13, 110, 253, .35); }
.editor-caja:hover { outline: 1px dashed rgba(0, 51, 102, .8); background: rgba(0, 51, 102, .04); }
.editor-caja.activa { outline: 2px solid #0d6efd; background: rgba(13, 110, 253, .06); z-index: 2; }
.editor-asa { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: #0d6efd; border: 1px solid #fff; cursor: nwse-resize; display: none; }
.editor-caja.activa .editor-asa { display: block; }
.editor-panel .tab-content { max-height: 70vh; overflow-y: auto; }
.editor-campos { max-height: 60vh; overflow-y: auto; }
.editor-campos code { white-space: normal; word-break: break-all; }
.archivo-miniatura { max-width: 80px; max-height: 60px; object-fit: contain; border: 1px solid #dee2e6; background: #fff; }
