/* =============================================================
   SISDEP - Estilos institucionales (mobile-first)
   Paleta derivada del logo IESTP Nasca.
   ============================================================= */
:root {
  --sd-primary: #1b2266;
  --sd-primary-rgb: 27, 34, 102;
  --sd-primary-dark: #121848;
  --sd-secondary: #0060a8;
  --sd-secondary-rgb: 0, 96, 168;
  --sd-accent: #b3263e;
  --sd-bg: #f4f6fb;
  --sd-surface: #ffffff;
  --sd-border: #e2e6f0;
  --sd-text: #1d2433;
  --sd-muted: #5b6475;
  --sd-sidebar-w: 264px;
  --sd-topbar-h: 60px;
  --sd-bottom-h: 64px;
  --sd-radius: 14px;

  --bs-primary: var(--sd-primary);
  --bs-primary-rgb: var(--sd-primary-rgb);
  --bs-secondary: var(--sd-secondary);
  --bs-secondary-rgb: var(--sd-secondary-rgb);
  --bs-link-color: var(--sd-secondary);
  --bs-link-color-rgb: var(--sd-secondary-rgb);
  --bs-link-hover-color: var(--sd-primary);
  --bs-body-color: var(--sd-text);
  --bs-body-bg: var(--sd-bg);
  --bs-border-color: var(--sd-border);
  --bs-border-radius: 10px;
  --bs-border-radius-lg: var(--sd-radius);
  --bs-secondary-color: var(--sd-muted);
  --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body { background: var(--sd-bg); font-size: 1rem; }
.xsmall { font-size: .75rem; }

/* Accesibilidad: foco siempre visible */
:focus-visible { outline: 3px solid rgba(var(--sd-secondary-rgb), .55); outline-offset: 2px; }
.skip-link { position: absolute; left: 1rem; top: .5rem; z-index: 2000; background: #fff; padding: .5rem 1rem; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Botones y controles: objetivos tactiles >= 44px */
.btn { --bs-btn-border-radius: 10px; min-height: 44px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; }
.btn-primary {
  --bs-btn-bg: var(--sd-primary); --bs-btn-border-color: var(--sd-primary);
  --bs-btn-hover-bg: var(--sd-primary-dark); --bs-btn-hover-border-color: var(--sd-primary-dark);
  --bs-btn-active-bg: var(--sd-primary-dark); --bs-btn-active-border-color: var(--sd-primary-dark);
  --bs-btn-disabled-bg: var(--sd-primary); --bs-btn-disabled-border-color: var(--sd-primary);
}
.btn-outline-primary {
  --bs-btn-color: var(--sd-primary); --bs-btn-border-color: var(--sd-primary);
  --bs-btn-hover-bg: var(--sd-primary); --bs-btn-hover-border-color: var(--sd-primary);
  --bs-btn-active-bg: var(--sd-primary); --bs-btn-active-border-color: var(--sd-primary);
}
.text-primary { color: var(--sd-primary) !important; }
.bg-secondary { background-color: var(--sd-secondary) !important; }
.text-bg-primary { background-color: var(--sd-primary) !important; color: #fff !important; }
.pagination { --bs-pagination-active-bg: var(--sd-primary); --bs-pagination-active-border-color: var(--sd-primary); --bs-pagination-color: var(--sd-secondary); }
.progress-thin { height: 6px; }
.progress-bar { background-color: var(--sd-primary); width: 0; transition: width .6s ease; }
.form-control:focus, .form-select:focus { border-color: var(--sd-secondary); box-shadow: 0 0 0 .2rem rgba(var(--sd-secondary-rgb), .2); }
.btn-icon { border: 0; background: transparent; display: inline-flex; align-items: center; gap: .5rem; padding: .25rem .5rem; }

/* Tarjetas */
.card { border: 1px solid var(--sd-border); border-radius: var(--sd-radius); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.card-header { background: transparent; border-bottom: 1px solid var(--sd-border); padding: .85rem 1rem; }
.card-title-sm { font-size: 1rem; font-weight: 600; margin: 0; color: var(--sd-primary); }
.empty-state { text-align: center; color: var(--sd-muted); padding: 1.5rem 1rem; }
.empty-state .bi { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .6; }
.profile-dl dt { font-weight: 500; color: var(--sd-muted); }
.profile-dl dd { margin-bottom: .5rem; }
.level-badge { background: #6c757d; color: #fff; font-weight: 500; }
.roadmap-list li { margin-bottom: .25rem; }

/* Listas como tarjetas (legibles en Android, sin tablas anchas) */
.min-w-0 { min-width: 0; }
.list-cards { display: grid; gap: .5rem; }
.list-card { transition: box-shadow .15s ease; }
a.list-card:hover, a.list-card:focus-visible { box-shadow: 0 4px 14px rgba(16, 24, 40, .08); }
.mini-stat { background: var(--sd-bg); border-radius: 12px; padding: .65rem .5rem; height: 100%; }
.mini-stat-value { font-size: 1.25rem; font-weight: 700; color: var(--sd-primary); line-height: 1.2; }
.mini-stat-label { font-size: .8rem; font-weight: 600; }
.notif-dot { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--sd-accent); color: #fff; font-size: .7rem; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px; }
.notif-unread { border-left: 4px solid var(--sd-secondary); }
.chip-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.date-tile { width: 52px; flex-shrink: 0; border-radius: 12px; background: rgba(var(--sd-primary-rgb), .08); color: var(--sd-primary); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: .35rem 0; height: fit-content; }
.date-tile-day { font-size: 1.3rem; font-weight: 700; line-height: 1; }
.date-tile-month { font-size: .7rem; font-weight: 600; letter-spacing: .04em; }
.module-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .5rem; }
.module-link { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .85rem .5rem; border-radius: 12px; background: var(--sd-surface); border: 1px solid var(--sd-border); color: var(--sd-primary); text-decoration: none; font-size: .85rem; font-weight: 500; text-align: center; }
.module-link .bi { font-size: 1.5rem; }
.module-link:hover { border-color: var(--sd-secondary); }
.letter-wide { letter-spacing: .25em; }
/* Firma */
.signature-canvas { width: 100%; height: 200px; border: 2px dashed var(--sd-border); border-radius: 12px; background: #fff; touch-action: none; display: block; cursor: crosshair; }
.signature-canvas.is-invalid { border-color: var(--bs-danger); }
@media (min-width: 768px) { .signature-canvas { height: 240px; } }
/* Escaner */
.scanner-box { position: relative; border-radius: 16px; overflow: hidden; background: #000; aspect-ratio: 1 / 1; max-width: 420px; margin: 0 auto; }
.scanner-box[hidden] { display: none; }
.scanner-box video { width: 100%; height: 100%; object-fit: cover; }
.scanner-guide { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35); }
/* Pantalla de proyeccion */
.present-body { background: #fff; min-height: 100vh; }
.present-main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.qr-frame { background: #fff; padding: 1rem; border-radius: 18px; box-shadow: 0 6px 30px rgba(16, 24, 40, .12); display: flex; justify-content: center; }
.qr-frame img { width: min(80vw, 70vh, 520px); height: auto; aspect-ratio: 1 / 1; }
.qr-expired { opacity: .15; }
.qr-progress { max-width: 420px; }
/* Sala: chat */
.chat-card { display: flex; flex-direction: column; height: min(65vh, 560px); }
.chat-list { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .4rem; overscroll-behavior: contain; }
.chat-msg { max-width: 85%; background: var(--sd-bg); border-radius: 12px; padding: .4rem .65rem; align-self: flex-start; font-size: .9rem; word-wrap: break-word; }
.chat-msg.chat-own { align-self: flex-end; background: rgba(var(--sd-secondary-rgb), .12); }
.chat-msg.chat-system { align-self: center; background: transparent; color: var(--sd-muted); font-size: .8rem; font-style: italic; text-align: center; }
.chat-author { display: block; font-weight: 600; font-size: .75rem; color: var(--sd-primary); }
.chat-time { display: block; font-size: .68rem; color: var(--sd-muted); text-align: right; }
.chat-form { display: flex; gap: .5rem; padding: .6rem; border-top: 1px solid var(--sd-border); }
.page-input { width: 70px; }
.scale-options { display: flex; flex-wrap: wrap; gap: .35rem; }
.scale-options .btn { min-width: 48px; }
.exam-timer { position: sticky; top: calc(var(--sd-topbar-h) + 8px); z-index: 1010; margin-left: auto; width: fit-content; background: var(--sd-primary); color: #fff; border-radius: 999px; padding: .35rem .9rem; font-weight: 600; margin-bottom: .75rem; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.option-check { padding-top: .35rem; padding-bottom: .35rem; }
.option-check .form-check-input { width: 1.25em; height: 1.25em; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
@media (min-width: 768px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi-grid .kpi-card { padding: .75rem; gap: .65rem; }
.kpi-grid .kpi-card > .bi { width: 40px; height: 40px; font-size: 1.2rem; }
.kpi-grid .kpi-value { font-size: 1.3rem; }
.kpi-grid .kpi-label { font-size: .78rem; }
a.kpi-card:hover { border-color: var(--sd-secondary); }
.filter-card summary { cursor: pointer; list-style: none; }
.filter-card summary::-webkit-details-marker { display: none; }
.chart-box { position: relative; height: 260px; }
.chart-box-sm { position: relative; height: 200px; }
.chart-box-lg { position: relative; height: 340px; }
.idpd-score { font-size: 3rem; font-weight: 800; line-height: 1; }
.level-dot { display: inline-block; width: .75rem; height: .75rem; border-radius: 50%; background: #6c757d; vertical-align: middle; }
.signature-preview { max-height: 160px; background: #fff; }
.privacy-text { max-height: 45vh; overflow-y: auto; border: 1px solid var(--sd-border); border-radius: 12px; padding: .75rem 1rem; background: var(--sd-bg); }
.avatar-photo { object-fit: cover; padding: 0; }
.session-row label { display: block; }
.session-row .form-control { margin-top: .15rem; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.detail-grid dt { font-size: .75rem; color: var(--sd-muted); font-weight: 500; }
.detail-grid dd { margin: 0; font-weight: 500; }
.action-bar { display: flex; flex-wrap: wrap; gap: .5rem; }
.tab-scroll { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
.tab-scroll .nav-link { white-space: nowrap; min-height: 44px; }

/* Avatar */
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--sd-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .9rem; flex-shrink: 0; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.2rem; }

/* KPIs */
.kpi-card { background: var(--sd-surface); border: 1px solid var(--sd-border); border-radius: var(--sd-radius); padding: 1rem; display: flex; align-items: center; gap: 1rem; height: 100%; }
.kpi-card > .bi { font-size: 1.6rem; width: 52px; height: 52px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-primary > .bi { background: rgba(var(--sd-primary-rgb), .1); color: var(--sd-primary); }
.kpi-secondary > .bi { background: rgba(var(--sd-secondary-rgb), .1); color: var(--sd-secondary); }
.kpi-accent > .bi { background: rgba(179, 38, 62, .1); color: var(--sd-accent); }
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: var(--sd-text); }
.kpi-label { font-size: .85rem; color: var(--sd-muted); }

.welcome-card { background: linear-gradient(120deg, var(--sd-primary) 0%, var(--sd-secondary) 100%); color: #fff; border-radius: var(--sd-radius); padding: 1.1rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.welcome-card img { background: #fff; border-radius: 10px; padding: 4px; }

/* ---------- Pantallas de invitado (login, errores, offline) ---------- */
.guest-body { min-height: 100vh; min-height: 100dvh; background: linear-gradient(180deg, var(--sd-primary) 0, var(--sd-secondary) 300px, var(--sd-bg) 300px) no-repeat, var(--sd-bg); }
.guest-main { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom)); }
.guest-card { width: 100%; max-width: 440px; margin: 0 auto; border-radius: 18px; }
.guest-logo { height: auto; }

/* ---------- Estructura de la aplicacion ---------- */
.app-shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: 0; z-index: 1020; height: calc(var(--sd-topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 1rem 0; background: var(--sd-surface); border-bottom: 1px solid var(--sd-border);
  display: flex; align-items: center; gap: .75rem;
}
.topbar-brand { display: flex; align-items: center; gap: .5rem; color: var(--sd-primary); text-decoration: none; font-size: 1.1rem; }
.topbar-title { font-size: 1.15rem; font-weight: 700; margin: 0; color: var(--sd-primary); }
.app-main { flex: 1; padding: 1rem 1rem calc(var(--sd-bottom-h) + 1.5rem + env(safe-area-inset-bottom)); width: 100%; max-width: 1400px; }
.app-main:focus { outline: none; }

/* Barra inferior movil */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; display: flex;
  height: calc(var(--sd-bottom-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--sd-surface); border-top: 1px solid var(--sd-border); box-shadow: 0 -2px 10px rgba(16, 24, 40, .06);
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--sd-muted); text-decoration: none; font-size: .72rem; border: 0; background: none; min-width: 0;
}
.bottom-nav-item .bi { font-size: 1.35rem; }
.bottom-nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.bottom-nav-item.active { color: var(--sd-primary); font-weight: 600; }
.more-menu { height: auto; max-height: 85vh; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.more-grid-item { display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .9rem .25rem; border-radius: 12px; background: var(--sd-bg); color: var(--sd-text); text-decoration: none; font-size: .8rem; text-align: center; }
.more-grid-item .bi { font-size: 1.4rem; color: var(--sd-primary); }

/* Barra lateral (lg+) */
.app-sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sd-sidebar-w); background: var(--sd-primary); color: #fff; z-index: 1030; }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255, 255, 255, .12); }
.sidebar-brand img { background: #fff; border-radius: 8px; padding: 2px; }
.sidebar-brand span { display: flex; flex-direction: column; line-height: 1.1; }
.sidebar-brand small { opacity: .75; font-size: .75rem; }
.sidebar-nav { padding: .75rem; gap: 2px; }
.sidebar-nav .nav-link { color: rgba(255, 255, 255, .85); border-radius: 10px; display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem; min-height: 44px; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar-nav .nav-link.active { background: #fff; color: var(--sd-primary); font-weight: 600; }
.sidebar-nav .bi { font-size: 1.1rem; }
.sidebar-footer { padding: .75rem 1.25rem; opacity: .6; }

@media (min-width: 992px) {
  .app-shell { margin-left: var(--sd-sidebar-w); }
  .app-main { padding: 1.5rem 2rem 2rem; }
  .app-topbar { padding-left: 2rem; padding-right: 2rem; }
}

/* Estado de conexion y actualizacion */
.offline-banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 2000; background: #7a4b00; color: #fff;
  font-size: .85rem; padding: calc(.35rem + env(safe-area-inset-top)) 1rem .35rem; display: flex; gap: .5rem; justify-content: center; align-items: center;
}
.offline-banner[hidden], .conn-pill[hidden] { display: none !important; }
.toast-zone { bottom: calc(var(--sd-bottom-h) + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(100%, 440px); }
@media (min-width: 992px) { .toast-zone { bottom: 0; left: auto; right: 0; transform: none; } }
.guest-body .toast-zone { bottom: env(safe-area-inset-bottom); }

/* Modo instalado (standalone): sin seleccion accidental en la navegacion */
@media (display-mode: standalone) {
  .bottom-nav, .app-topbar, .sidebar-nav { -webkit-user-select: none; user-select: none; }
}

/* Envio en curso */
.is-loading .btn-label { opacity: .6; }
