/* Adaptación a celular y tableta. */

/* ---------------- Responsive ---------------- */

@media (max-width: 1024px) {
  .main { padding: 20px 20px 50px; }
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; margin: 10px; border-radius: 18px; min-height: calc(100vh - 20px); }
  .sidebar {
    width: 100%; height: auto; flex-direction: row; align-items: center; justify-content: space-between;
    position: sticky; top: 10px; z-index: 40; padding: 10px 14px;
    border-right: none; border-bottom: 1px solid var(--border-soft);
    border-radius: 18px 18px 0 0;
  }
  .sidebar-brand { margin: 0 8px 0 0; }
  .side-logo { width: 32px; height: 32px; }
  .sidebar-nav {
    flex-direction: row; align-items: center; justify-content: space-between;
    width: auto; flex: 1; gap: 2px; padding: 0; margin: 0; overflow: visible;
  }
  .nav-link {
    flex-direction: column; width: auto; min-width: 0; flex: 1; gap: 3px;
    padding: 7px 4px; font-size: 10px; border-radius: 10px;
  }
  .nav-link .nav-icon { font-size: 15px; }
  .nav-link .nav-icon svg { width: 15px; height: 15px; }
  #sidebar-nav .nav-more-trigger { display: flex; }
  .nav-more-panel {
    display: flex; position: absolute; top: calc(100% + 10px); right: 0;
    flex-direction: column; background: var(--bg-2); border: 1px solid var(--border-soft);
    border-radius: 12px; padding: 6px; min-width: 190px;
    box-shadow: 0 16px 36px rgba(0,0,0,0.45); z-index: 80; gap: 2px;
    opacity: 0; transform: translateY(-6px) scale(0.97); pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s cubic-bezier(.2,.8,.2,1);
    transform-origin: top right;
  }
  .nav-more-panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
  .nav-more-panel .nav-link {
    flex-direction: row; justify-content: flex-start; width: 100%; gap: 10px;
    padding: 10px 12px; font-size: 13px; border-radius: 8px;
  }
  .nav-more-panel .nav-link .nav-icon { font-size: 17px; }
  .nav-more-panel .nav-link .nav-icon svg { width: 17px; height: 17px; }
  .sidebar-user { margin: 0 0 0 6px; padding: 0; }
  .sidebar-user .avatar { width: 34px; height: 34px; font-size: 11px; }
  .main { padding: 14px 12px 36px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; padding-bottom: 12px; margin-bottom: 16px; }
  .topbar-left { padding-left: 13px; }
  .topbar-eyebrow { font-size: 10px; letter-spacing: 1.4px; }
  .topbar h1 { font-size: 18px; gap: 8px; margin-top: 3px; }
  .topbar .sub { font-size: 12px; }
  .topbar-right { gap: 8px 14px; justify-content: flex-start; }
  .topbar-clock { font-size: 11.5px; }
  .topbar-user { font-size: 11.5px; flex-wrap: wrap; }
  .detail-header h2 { font-size: 15px; }
  .group-search { flex-direction: column; }
  .group-search .btn { justify-content: center; }
  .group-actions { flex-direction: column; }
  .group-actions .btn { flex: 1; justify-content: center; width: 100%; }
  .rubric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .rubric-card { padding: 14px; }
  .rubric-card h3 { font-size: 13.5px; }
  .rubric-card .rubric-sub { font-size: 11.5px; }
  .rubric-icon { font-size: 15px; width: 34px; height: 34px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 11px 13px; }
  .stat-card .stat-label { font-size: 10px; }
  .stat-card .stat-value { font-size: 18px; }
  .kpi-sub { font-size: 10px; }
  .card-header h2 { font-size: 13.5px; }
  .group-title { font-size: 11.5px; }
  .est-row { gap: 10px; padding: 10px 6px; }
  .est-head strong { font-size: 12.5px; }
  .est-pct { font-size: 12px; }
  .est-meta { font-size: 10.5px; }
  .struct-card { min-width: 104px; padding: 10px 12px; }
  .struct-card .sc-name { font-size: 11px; }
  .struct-card .sc-abscisa { font-size: 10.5px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input[type=search] { min-width: 0; flex: 1; }
  .toolbar-label { font-size: 11px; }
  .card { padding: 13px 13px; }
  .btn { font-size: 12.5px; padding: 8px 13px; }
  .btn-small { font-size: 11.5px; padding: 6px 10px; }
  table.data-table { font-size: 12px; }
  table.data-table th { font-size: 9.5px; padding: 8px 8px; }
  table.data-table td { padding: 8px 8px; font-size: 12px; }
  .chk-table th, .chk-table td { padding: 6px 8px; font-size: 11.5px; line-height: 1.2; }
  .chk-table tbody td:first-child { font-size: 12px; max-width: 128px; overflow: hidden; text-overflow: ellipsis; }
  .chk-box { width: 24px; height: 24px; }
  .chk-box svg { width: 13px; height: 13px; }
  .chk-medida { font-size: 8.5px; margin-top: 2px; }
  .chk-matrix-wrap { max-height: 60vh; box-shadow: inset -14px 0 12px -12px rgba(0,0,0,0.45); }
  .modal h3 { font-size: 18px; }
  .modal .field label { font-size: 12.5px; }
  .modal .field input, .modal .field select, .modal .field textarea { padding: 11px 13px; font-size: 13.5px; }
  .modal { padding: 18px; }
  .login-form-side { padding: 32px 24px; }
  .login-side { padding: 32px 24px; }
  .chk-actions { flex-wrap: wrap; }
  .chk-actions .btn { flex: 1; justify-content: center; min-width: 120px; }
  .activity-row { font-size: 12px; }
  .activity-meta { font-size: 10.5px; }
}

/* En pantallas angostas la fecha se pasa debajo del texto en vez de competir
   por el ancho con el detalle del cambio. */
@media (max-width: 640px) {
  .activity-row { flex-wrap: wrap; }
  .activity-row > .activity-meta:last-child {
    width: 100%; padding-left: 40px; margin-top: 2px; order: 3;
  }
  .activity-detalle { white-space: normal; }
}

@media (max-width: 520px) {
  .rubric-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .topbar-clock { font-size: 11px; }
  .topbar-user { font-size: 11px; flex-wrap: wrap; }
  .actions-cell { flex-direction: column; }
  .actions-cell .btn { padding: 6px 9px; font-size: 11.5px; width: 100%; justify-content: center; }
  .toast { left: 14px; right: 14px; max-width: none; }
  .guardado { left: 14px; bottom: 14px; }
  .topbar h1 { font-size: 16.5px; gap: 6px; }
  .struct-card { min-width: 96px; }
  .est-head strong { font-size: 12px; }
  .stat-card .stat-value { font-size: 16.5px; }
  .card-header h2 { font-size: 13px; }
  .rubric-card h3 { font-size: 13px; }
  .nav-link { font-size: 8.8px; padding: 6px 2px; }
  .nav-link .nav-icon { font-size: 14px; }
  .nav-link .nav-icon svg { width: 14px; height: 14px; }
  .side-logo { width: 26px; height: 26px; }
  .sidebar-user .avatar { width: 28px; height: 28px; font-size: 10px; }
  .chk-table th, .chk-table td { padding: 5px 6px; font-size: 10.5px; }
  .chk-table tbody td:first-child { max-width: 96px; font-size: 11px; }
  .chk-box { width: 21px; height: 21px; border-radius: 6px; }
  .chk-box svg { width: 11px; height: 11px; }
  .chk-medida { font-size: 8px; }
  .chk-matrix-wrap { max-height: 54vh; }
  .struct-cards { gap: 8px; }
  .activity-row { font-size: 11px; padding: 7px 0; gap: 8px; }
  .activity-icon { width: 26px; height: 26px; }
  .activity-meta { font-size: 10px; }
  .cva-filters { gap: 7px; }
  .cva-filters input[type="text"], .cva-filters select { padding: 7px 10px; font-size: 12px; }
  .cva-filters input[type="text"] { min-width: 0; }
  .cva-table thead th:first-child { min-width: 88px; }
  .cva-name-id { font-size: 11px; }
  .cva-name-meta { font-size: 9px; }
  .cva-pct-cell { min-width: 62px; }
  .cva-pct { font-size: 9px; }
  .cva-ficha-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cva-ficha-head h3 { font-size: 17px; }
  .cva-ficha-list li { font-size: 12px; padding: 7px 9px; }
  .cva-tabs { gap: 5px; margin-bottom: 12px; }
  .cva-tab { padding: 8px 13px; font-size: 14px; gap: 7px; }
  .cva-tab-badge { font-size: 11px; padding: 2px 6px; }
  .resumen-grid { grid-template-columns: 1fr; gap: 16px; }
  .resumen-chart { height: 180px; }
  .resumen-centro-num { font-size: 28px; }
  .resumen-rubricas { grid-template-columns: 1fr; }
  .cva-planos-body { grid-template-columns: 1fr; gap: 10px; padding: 4px 10px 12px; }
  .cva-planos-head { padding: 9px 11px; font-size: 12px; }
  .cva-plano figcaption { font-size: 10px; }
}

/* En el celular la tabla de registros se lee como tarjetas: una por fila, con
   el nombre de cada columna a la izquierda y el valor a la derecha. */
@media (max-width: 640px) {
  .tabla-tarjetas thead { display: none; }
  .tabla-tarjetas, .tabla-tarjetas tbody, .tabla-tarjetas tr, .tabla-tarjetas td { display: block; width: 100%; }
  .tabla-tarjetas tr {
    background: var(--bg-1); border: 1px solid var(--border); border-radius: 12px;
    padding: 6px 12px; margin-bottom: 10px;
  }
  table.data-table.tabla-tarjetas td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none; border-bottom: 1px solid var(--border-soft, var(--border)); padding: 8px 0; text-align: right;
  }
  table.data-table.tabla-tarjetas td:last-child { border-bottom: none; }
  .tabla-tarjetas td::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em;
  }
  .tabla-tarjetas td[data-label=""]::before { display: none; }
  .tabla-tarjetas .actions-cell { flex-direction: row; justify-content: flex-end; padding-top: 10px; }
  .tabla-tarjetas .actions-cell .btn { width: auto; }
}
