/* Estructura de la app: barra lateral, barra superior, tarjetas y tablas. */

/* ---------------- App shell ---------------- */

.app-shell {
  display: flex;
  max-width: 1700px;
  margin: 20px auto;
  min-height: calc(100vh - 40px);
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.sidebar {
  width: 92px;
  background: var(--bg-1);
  border-right: 1px solid var(--border-soft);
  border-radius: 24px 0 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  height: calc(100vh - 40px);
  padding: 18px 0;
}

.sidebar-brand { margin-bottom: 18px; }
.side-logo {
  width: 46px; height: 46px; cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease;
  display: flex; align-items: center; justify-content: center;
}
.side-logo:hover { transform: scale(1.08); opacity: 0.85; }
.side-logo svg { width: 100%; height: 100%; display: block; }
/* El logo hereda el color del texto: blanco en oscuro, azul en claro. */
.side-logo { color: var(--text); }
html[data-tema="claro"] .side-logo { color: var(--blue); }
.login-logo, .progress-logo { color: #ffffff; }

.sidebar-nav { display: flex; flex-direction: column; gap: 6px; width: 100%; align-items: center; flex: 1; overflow-y: auto; position: relative; }
#sidebar-nav .nav-more-trigger { display: none; }
.nav-more-panel { display: contents; }

.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 74px;
  padding: 10px 4px;
  border-radius: 12px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11px;
  cursor: pointer;
  background: transparent;
  border: none;
  font-family: var(--font-body);
}
.nav-link .nav-icon { font-size: 18px; line-height: 1; }
.nav-link .nav-icon svg { width: 20px; height: 20px; }
.nav-link:hover { background: var(--hover-suave); color: var(--text); }
.nav-link.active { background: var(--teal); color: white; font-weight: 700; }

.sidebar-user { margin-top: auto; padding-top: 14px; }
.sidebar-user .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--blue);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-weight: 700; font-size: 13px;
  cursor: pointer;
  border: none;
}

.main { flex: 1; min-width: 0; padding: 22px 30px 60px; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 14px;
}
.topbar-left { position: relative; padding-left: 17px; }
.topbar-left::before {
  content: ""; position: absolute; left: 0; top: 2px; bottom: 2px; width: 4px;
  border-radius: 4px; background: var(--blue);
}
.topbar-eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 2px; color: var(--teal); text-transform: uppercase; }
.topbar h1 {
  margin: 4px 0 0; font-size: 28px; font-family: var(--font-head); font-weight: 800; letter-spacing: 0.5px;
  display: flex; align-items: center; gap: 12px;
  color: var(--text);
}
.topbar .sub { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

.topbar-right { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.topbar-clock { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-family: var(--font-mono); font-size: 13px; }
.topbar-clock strong { color: var(--text); font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.topbar-user strong { color: var(--text); }
/* Nombre de la persona antes del correo; se oculta si el usuario no tiene
   nombre cargado en usuario_roles. */
.user-nombre { margin-left: 3px; }
.user-nombre.hidden { display: none; }
.user-mail {
  color: inherit; text-decoration: none; border-radius: 6px; padding: 2px 5px;
  transition: background 0.15s ease, color 0.15s ease;
}
.user-mail:hover { background: var(--teal-dim); }
.user-mail:hover strong { color: var(--teal); text-decoration: underline; }

.pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.4px; }
.pill-teal { background: var(--teal-dim); color: var(--teal); }
/* Rol con alcance limitado: se distingue del acceso total de un vistazo. */
.pill.role-limitado { background: rgba(245,166,35,0.16); color: #f5be6a; }
.pill-gray { background: var(--pastilla); color: var(--text-dim); }

.card {
  background: var(--bg-1);
  min-width: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.card-header h2 { font-size: 15px; margin: 0; font-family: var(--font-head); display: flex; align-items: center; gap: 8px; }
.card-header .hint { font-size: 12px; color: var(--text-faint); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-family: var(--font-mono);
}
table.data-table th.sortable-th { cursor: pointer; user-select: none; transition: color 0.12s ease; }
table.data-table th.sortable-th:hover { color: var(--text); }
table.data-table th.sortable-th .sort-arrow { display: inline-block; margin-left: 4px; font-size: 9px; opacity: 0.35; }
table.data-table th.sortable-th.sort-active .sort-arrow { opacity: 1; color: var(--teal); }
table.data-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}
table.data-table tr:hover td { background: var(--hover-fila); }
.actions-cell { display: flex; gap: 6px; white-space: nowrap; }

.empty-state { text-align: center; color: var(--text-faint); padding: 30px 10px; font-size: 14px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4,10,18,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: 18px; padding: 30px 34px; width: 100%; max-width: 640px;
  max-height: 92vh; overflow-y: auto;
  animation: modalIn 0.18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 20px; font-family: var(--font-head); font-size: 22px; font-weight: 800; }
.modal .field { margin-bottom: 20px; }
.modal .field label { font-size: 13.5px; margin-bottom: 7px; }
.modal .field input, .modal .field select, .modal .field textarea { padding: 13px 15px; border-radius: 10px; font-size: 14.5px; }
.modal-backdrop { animation: fadeIn 0.15s ease; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--bg-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 14px 16px; }
.stat-card .stat-label { display: flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-faint); margin-bottom: 6px; }
.stat-card .stat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.stat-card .stat-value { font-size: 24px; font-weight: 800; font-family: var(--font-head); }
.kpi-sub { font-size: 11px; color: var(--text-faint); margin-top: 4px; font-family: var(--font-mono); }
.est-row { display: flex; align-items: center; gap: 14px; padding: 12px 10px; border-radius: var(--radius-sm); transition: background 0.15s ease, transform 0.18s ease; }
.est-row:hover { background: var(--hover-fila); transform: translateX(3px); }
.est-row + .est-row { border-top: 1px solid var(--border-soft); }
.est-icon { flex-shrink: 0; display: flex; align-items: center; }
.est-body { flex: 1; min-width: 0; }
.est-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.est-head strong { font-size: 13.5px; }
.est-pct { font-family: var(--font-mono); font-weight: 700; font-size: 13px; }
.est-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; font-family: var(--font-mono); }

.progress-bar { height: 7px; background: var(--bg-3); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress-bar-fill { height: 100%; background: var(--teal); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search], .toolbar input[type=date], .toolbar select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  background: var(--bg-2); color: var(--text); font-family: var(--font-body);
}
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.toolbar-label { font-size: 12px; color: var(--text-faint); }

.group-search { display: flex; gap: 10px; margin-bottom: 18px; }
.group-search input { flex: 1; padding: 13px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-1); color: var(--text); font-size: 14px; }
.group-actions { display: flex; gap: 10px; margin-bottom: 26px; flex-wrap: wrap; }
.group-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 14px; }

.rubric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.rubric-card {
  background: var(--bg-1); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
  display: flex; flex-direction: column; gap: 12px;
}
.rubric-card:hover { border-color: var(--teal); transform: translateY(-2px); }
.rubric-card-top { display: flex; align-items: center; justify-content: space-between; }
.rubric-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 17px; background: var(--bg-3);
}
.rubric-card h3 { margin: 0; font-size: 15px; font-family: var(--font-head); }
.rubric-card .rubric-sub { font-size: 12.5px; color: var(--text-faint); font-family: var(--font-mono); }
.rubric-arrow { color: var(--text-faint); }

.detail-header { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.detail-header h2 {
  margin: 0; font-size: 17px; font-family: var(--font-head); font-weight: 700;
  border-bottom: 2px solid var(--teal); padding: 6px 10px 12px;
}
.pill-outline { background: transparent; border: 1px solid var(--teal); color: var(--teal); font-family: var(--font-mono); font-weight: 500; padding: 5px 13px; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--teal); font-family: var(--font-mono); margin-left: auto; }
.live-dot .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 0 rgba(63,124,194,0.5); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(63,124,194,0.5); } 70% { box-shadow: 0 0 0 6px rgba(63,124,194,0); } 100% { box-shadow: 0 0 0 0 rgba(63,124,194,0); } }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.35); border-top-color: white; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); z-index: 100;
  opacity: 0; transform: translateY(10px); transition: all 0.25s ease; max-width: 340px;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--red); color: #ffd7dd; }

/* Confirmación de guardado: aparece abajo a la izquierda y se va sola. */
.guardado {
  position: fixed; bottom: 24px; left: 24px; z-index: 99; display: flex; align-items: center; gap: 7px;
  background: var(--bg-2); border: 1px solid var(--ok); color: var(--ok); border-radius: 999px;
  padding: 7px 14px 7px 11px; font-size: 12.5px; font-weight: 600; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s ease, transform 0.2s ease; pointer-events: none;
}
.guardado.visible { opacity: 1; transform: translateY(0); }
.guardado svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
