/* ============================================
   COMPONENTES - botones, cards, tablas, badges, etc.
   ============================================ */

/* ===== SUBNAV (tabs horizontales) ===== */
.subnav {
  display: flex;
  gap: 4px;
  background: var(--blanco);
  padding: 6px;
  border-radius: var(--radio-lg);
  margin-bottom: 22px;
  box-shadow: var(--sombra);
  overflow-x: auto;
  border: 1px solid var(--borde);
}

.subnav-item {
  padding: 9px 18px;
  border-radius: var(--radio-sm);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.2s;
  color: var(--texto-suave);
}

.subnav-item:hover { background: var(--nude-light); color: var(--marron); }
.subnav-item.active { background: var(--marron); color: white; }

/* ===== CARDS ===== */
.card {
  background: var(--blanco);
  border-radius: var(--radio-lg);
  padding: 22px;
  box-shadow: var(--sombra);
  margin-bottom: 22px;
  border: 1px solid var(--borde);
}

.card-title {
  font-size: 17px;
  color: var(--marron);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 400;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== FILTROS Y FORMS ===== */
.filtros {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.filtro-group { display: flex; flex-direction: column; gap: 5px; }

.filtro-label {
  font-size: 10px;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.input, .select {
  padding: 9px 12px;
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  font-size: 13px;
  background: white;
  color: var(--texto);
  font-family: inherit;
}

.input:focus, .select:focus {
  outline: none;
  border-color: var(--tierra);
  box-shadow: 0 0 0 3px rgba(180, 159, 139, 0.15);
}

textarea.input {
  resize: vertical;
  min-height: 70px;
  font-family: inherit;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-group label {
  font-size: 10px;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 1px;
}

@media (max-width: 768px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ===== BOTONES ===== */
.btn {
  padding: 9px 16px;
  border: none;
  border-radius: var(--radio-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  text-decoration: none;
}

.btn-primary { background: var(--marron); color: white; }
.btn-primary:hover { background: var(--negro); }

.btn-secondary { background: var(--nude); color: var(--marron); }
.btn-secondary:hover { background: var(--tierra); color: white; }

.btn-tierra { background: var(--tierra); color: white; }
.btn-tierra:hover { background: var(--tierra-dark); }

.btn-success { background: var(--exito); color: white; }
.btn-success:hover { opacity: 0.85; }

.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { opacity: 0.85; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--tierra);
  color: var(--marron);
}
.btn-outline:hover { background: var(--nude-light); }

.btn-sm { padding: 5px 10px; font-size: 11px; }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--blanco);
  padding: 20px;
  border-radius: var(--radio-md);
  box-shadow: var(--sombra);
  border: 1px solid var(--borde);
  border-left: 4px solid var(--tierra);
}

.stat-card.marron { border-left-color: var(--marron); }
.stat-card.dorado { border-left-color: var(--aviso); }
.stat-card.nude { border-left-color: var(--nude); }
.stat-card.exito { border-left-color: var(--exito); }

.stat-label {
  font-size: 10px;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-value {
  font-size: 26px;
  color: var(--marron);
  margin: 8px 0 3px;
  font-family: var(--font-titulo);
  font-weight: 400;
}

.stat-change { font-size: 11px; color: var(--exito); }
.stat-change.down { color: var(--error); }

/* ===== TABLA ===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

/* Las celdas no se comprimen: si la tabla es ancha, aparece scroll horizontal */
.table-wrap thead th,
.table-wrap tbody td { white-space: nowrap; }

/* Permitir wrap solo en celdas que contengan textos largos (con clase explícita) */
.table-wrap .nowrap-off { white-space: normal; }

/* ⭐ Celdas con grupos de botones de acción: que NO se envuelvan en vertical
   Esto fuerza a la tabla a hacerse más ancha y por tanto aparezca la barra de scroll */
.table-wrap td > div[style*="flex"],
.table-wrap td[style*="flex"] {
  display: inline-flex !important;
  flex-wrap: nowrap !important;
  gap: 4px !important;
  align-items: center;
  vertical-align: middle;
  white-space: nowrap;
}

/* Scrollbar visible y estilizada en table-wrap */
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-track {
  background: var(--nude-light);
  border-radius: 5px;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--tierra);
  border-radius: 5px;
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--tierra-dark); }

/* Indicador visual cuando la tabla puede desplazarse */
.table-wrap {
  background:
    linear-gradient(90deg, white 30%, rgba(255,255,255,0)) 0 0,
    linear-gradient(-90deg, white 30%, rgba(255,255,255,0)) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(180,159,139,0.4), rgba(180,159,139,0)) 0 0,
    radial-gradient(farthest-side at 100% 50%, rgba(180,159,139,0.4), rgba(180,159,139,0)) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

thead th {
  text-align: left;
  padding: 11px 14px;
  background: var(--nude-light);
  color: var(--marron);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 2px solid var(--borde);
}

tbody td { padding: 9px 11px; border-bottom: 1px solid var(--borde); font-size: 12px; }
tbody tr:hover { background: var(--perla); }

/* Botones de acción dentro de tablas: compactos */
.table-wrap td .btn-sm {
  padding: 4px 7px;
  min-width: 26px;
  height: 26px;
  font-size: 11px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.table-wrap td .btn {
  padding: 5px 9px;
  font-size: 11px;
}

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success { background: #E2E8D5; color: #5C6E45; }
.badge-warning { background: #F5E6CB; color: #8A6E2E; }
.badge-danger  { background: #F0D5CF; color: var(--error); }
.badge-info    { background: var(--nude); color: var(--marron); }
.badge-neutro  { background: var(--perla); color: var(--texto-suave); }

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  background: white;
  padding: 14px;
  border-radius: var(--radio-md);
  box-shadow: var(--sombra);
  margin-bottom: 18px;
  border: 1px solid var(--borde);
}

.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  font-size: 14px;
  font-family: inherit;
}

/* ===== PROF CHIPS ===== */
.prof-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.prof-chip {
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--nude-light);
  font-size: 11px;
  cursor: pointer;
  border: 1px solid var(--borde);
  transition: all 0.2s;
  color: var(--marron);
}

.prof-chip:hover { border-color: var(--tierra); }
.prof-chip.active { background: var(--marron); color: white; border-color: var(--marron); }

/* ===== EMPTY / FEATURE BOX ===== */
.empty { text-align: center; padding: 40px; color: var(--texto-suave); }

.subsection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.feature-box {
  background: white;
  border-radius: var(--radio-md);
  padding: 18px;
  box-shadow: var(--sombra);
  border: 1px solid var(--borde);
  border-top: 3px solid var(--tierra);
}

.feature-box h4 { color: var(--marron); margin-bottom: 8px; font-size: 14px; }
.feature-box p { font-size: 12px; color: var(--texto-suave); line-height: 1.5; }

/* ===== SWITCH ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--nude-light);
  border-radius: 24px;
  transition: 0.3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.switch input:checked + .slider { background: var(--exito); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 2px dashed var(--borde);
  border-radius: var(--radio-md);
  padding: 24px;
  text-align: center;
  background: var(--nude-light);
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover { border-color: var(--tierra); background: var(--nude); }

/* ===== DOC ITEMS ===== */
.doc-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  background: white;
  border: 1px solid var(--borde);
  border-radius: var(--radio-md);
  margin-bottom: 8px;
}

.doc-icon { font-size: 24px; color: var(--tierra); }
.doc-info { flex: 1; }
.doc-name { font-size: 13px; font-weight: 600; color: var(--marron); }
.doc-meta { font-size: 11px; color: var(--texto-suave); }

/* ===== INDICADOR ESTADO ===== */
.estado-indicador {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.estado-on { background: var(--exito); }
.estado-off { background: var(--texto-suave); }

/* ===== PERMISOS GRID ===== */
.permisos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 14px;
  background: var(--nude-light);
  border-radius: var(--radio-md);
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 6px 10px;
  background: white;
  border-radius: var(--radio-sm);
  border: 1px solid var(--borde);
  cursor: pointer;
}

.perm-item input { accent-color: var(--marron); }

/* ===== PROF AVATAR ===== */
.prof-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
  background: var(--tierra);
  margin: 0 auto 10px;
  font-family: var(--font-titulo);
}

.prof-card { text-align: center; }
.prof-card h4 { font-size: 15px; }

/* ============================================================================
   ⭐ MÓVIL — TODOS los overrides al FINAL del archivo para tener máxima prioridad
   ============================================================================ */
@media (max-width: 600px) {
  .card { padding: 14px; margin-bottom: 14px; }
  .card-title { font-size: 15px; flex-wrap: wrap; gap: 8px; }

  /* Stats en 1 columna en móviles (más legible que 2 apretadas) */
  .stats-grid { grid-template-columns: 1fr !important; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }

  /* Filtros apilados */
  .filtros { flex-direction: column; align-items: stretch; gap: 10px; }
  .filtros .filtro-group { width: 100%; }
  .filtros .filtro-group .input,
  .filtros .filtro-group .select { width: 100%; }

  /* Modales */
  .modal { padding: 18px; max-height: 96vh; }
  .modal.lg { max-width: 100%; }
  .modal-title { font-size: 16px; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .btn { width: 100%; justify-content: center; }

  /* Subnav y tabs */
  .subnav { padding: 4px; gap: 2px; }
  .subnav-item { padding: 7px 10px; font-size: 11px; }
  .tabs-row { padding: 3px; }
  .tab-item { padding: 7px 10px; font-size: 11px; }
  .subsection-grid { grid-template-columns: 1fr !important; gap: 10px; }

  /* ⭐ TABLAS EN MÓVIL: card-stack (cada fila se vuelve una tarjeta) */
  .table-wrap { overflow: visible !important; background: none !important; }
  .table-wrap table {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; width: 100%; }
  .table-wrap tr {
    display: block;
    width: 100%;
    background: white;
    border: 1px solid var(--borde);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  }
  .table-wrap td {
    display: block;
    border: none !important;
    padding: 3px 0 !important;
    text-align: left !important;
    white-space: normal !important;
    font-size: 13px;
    min-height: 0;
  }
  /* Primera celda (nombre / título) destacada como cabecera de la tarjeta */
  .table-wrap tr > td:first-child {
    font-weight: 700;
    font-size: 14.5px;
    color: var(--marron);
    padding-bottom: 8px !important;
    border-bottom: 1px solid var(--borde) !important;
    margin-bottom: 6px;
  }
  /* Última celda (acciones) separada visualmente */
  .table-wrap tr > td:last-child {
    margin-top: 10px;
    padding-top: 10px !important;
    border-top: 1px solid var(--borde) !important;
  }
  /* Contenedor de botones de acción en móvil: centrado, botones grandes */
  .table-wrap tr > td:last-child > div,
  .table-wrap tr > td:last-child .le-acciones {
    display: flex !important;
    justify-content: center !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
    width: 100%;
  }
  .table-wrap tr > td:last-child .btn-sm,
  .table-wrap tr > td:last-child .btn {
    width: 38px !important;
    height: 38px !important;
    font-size: 14px !important;
    padding: 0 !important;
  }

  /* Topbar más compacto */
  .topbar { padding: 12px 14px; }
  .topbar-title { font-size: 16px; }
  .topbar .user-chip > div { display: none; }
  .topbar .user-chip { padding: 4px; }
  .topbar .avatar { width: 30px; height: 30px; font-size: 11px; }
}
