/* Casas de Vida - Estilos v3.0 - Mobile First */

/* ============================================
   VARIABLES
   ============================================ */
:root {
  --primary: #1a1a1a;
  --secondary: #4a4a4a;
  --accent: #64748B;
  --success: #059669;
  --danger: #DC2626;
  --touch-target: 44px;
  --card-radius: 12px;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

body {
  background-color: #F8FAFC;
  -webkit-font-smoothing: antialiased;
}

/* ============================================
   CONTENEDOR DE TABLA - COMÚN
   ============================================ */
.table-container {
  background: white;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.table-header {
  padding: 16px;
  border-bottom: 1px solid #F3F4F6;
}

.table-content {
  overflow-x: auto;
}

/* ============================================
   MÓVIL - TARJETAS (< 768px) - DEFAULT
   ============================================ */
.data-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.data-card {
  background: white;
  border-radius: var(--card-radius);
  padding: 16px;
  box-shadow: var(--card-shadow);
  border: 1px solid #F3F4F6;
  position: relative;
}

.data-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #F9FAFB;
  min-height: 44px;
}

.data-card-row:last-of-type {
  border-bottom: none;
}

.data-card-label {
  font-weight: 600;
  font-size: 11px;
  color: #9CA3AF;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  min-width: 80px;
}

.data-card-value {
  text-align: right;
  flex: 1;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.data-card-value.editable {
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.15s ease;
  min-height: var(--touch-target);
}

.data-card-value.editable:hover {
  background-color: #F1F5F9;
}

.data-card-value.editable:active {
  background-color: #E2E8F0;
}

/* Acciones en tarjeta móvil */
.data-card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
}

/* Tarjeta nueva en móvil */
.data-card.new-card {
  background: #F8FAFC;
  border: 2px dashed var(--accent);
}

.data-card.new-card .data-card-row {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.data-card.new-card .data-card-label {
  text-align: left;
  margin-bottom: 4px;
}

.new-card-button {
  margin-top: 12px;
  width: 100%;
}

/* ============================================
   DESKTOP - TABLA (>= 768px)
   ============================================ */
@media (min-width: 768px) {
  .data-grid {
    display: none;
  }
  
  .data-table {
    display: table !important;
    width: 100%;
    border-collapse: collapse;
  }
  
  .data-table thead {
    display: table-header-group;
  }
  
  .data-table thead tr {
    display: table-row;
    background: #F9FAFB;
  }
  
  .data-table th {
    display: table-cell;
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
  }
  
  .data-table th.text-right {
    text-align: right;
  }
  
  .data-table th.text-center {
    text-align: center;
  }
  
  .data-table tbody {
    display: table-row-group;
  }
  
  .data-table tbody tr {
    display: table-row;
    transition: background 0.15s ease;
  }
  
  .data-table tbody tr:hover {
    background: #F9FAFB;
  }
  
  .data-table td {
    display: table-cell;
    padding: 12px 16px;
    border-bottom: 1px solid #F3F4F6;
    vertical-align: middle;
  }
  
  .data-table td.text-right {
    text-align: right;
  }
  
  .data-table td.text-center {
    text-align: center;
  }
  
  /* Celdas editables en desktop */
  .data-table td .editable {
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.15s ease;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
  }
  
  .data-table td .editable:hover {
    background-color: #F1F5F9;
  }
  
  /* Fila nueva en desktop */
  .data-table tr.new-row {
    background: #F8FAFC !important;
  }
  
  .data-table tr.new-row td {
    border-top: 2px dashed var(--accent);
    padding: 8px 16px;
  }
  
  /* Botón eliminar en desktop */
  .row-actions-desktop {
    opacity: 0;
    transition: opacity 0.15s ease;
  }
  
  .data-table tbody tr:hover .row-actions-desktop {
    opacity: 1;
  }
}

/* Ocultar tabla en móvil */
@media (max-width: 767px) {
  .data-table {
    display: none !important;
  }
}

/* ============================================
   EDICIÓN INLINE
   ============================================ */
.editing {
  background-color: white !important;
  box-shadow: 0 0 0 2px var(--secondary);
  padding: 0 !important;
}

.editing input,
.editing select {
  width: 100%;
  min-height: var(--touch-target);
  padding: 10px 12px;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  background: white;
}

.editing input:focus,
.editing select:focus {
  outline: none;
}

/* ============================================
   INPUTS GENERALES
   ============================================ */
.input-field {
  width: 100%;
  min-height: var(--touch-target);
  font-size: 16px;
  padding: 10px 14px;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  transition: all 0.15s ease;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

/* ============================================
   BOTONES
   ============================================ */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  min-height: var(--touch-target);
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s ease;
  border: none;
  cursor: pointer;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #000000, var(--secondary));
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-delete {
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s ease;
  color: #EF4444;
  background: transparent;
  border: none;
  cursor: pointer;
}

.btn-delete:hover {
  background: #FEE2E2;
}

/* ============================================
   BADGES / TAGS
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-sm {
  padding: 2px 8px;
  font-size: 11px;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar-item {
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
  transition: all 0.15s ease;
}

.sidebar-item:hover {
  background-color: rgba(26, 26, 26, 0.05);
}

.sidebar-item:active {
  background-color: rgba(26, 26, 26, 0.1);
}

.sidebar-item.active {
  background-color: rgba(26, 26, 26, 0.08);
  border-left: 3px solid var(--primary);
}

/* ============================================
   CARDS GENERALES
   ============================================ */
.card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) {
  .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(26, 26, 26, 0.1);
  }
}

/* ============================================
   LOGIN
   ============================================ */
.login-bg {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 40%, #334155 70%, #475569 100%);
  min-height: 100vh;
  min-height: 100dvh;
}

.glass-card {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(100, 116, 139, 0.2);
}

/* ============================================
   TOAST
   ============================================ */
#toast-container {
  pointer-events: none;
}

#toast-container > div {
  pointer-events: auto;
  min-height: var(--touch-target);
}

/* ============================================
   ANIMATIONS
   ============================================ */
.shake {
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.fade-in {
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.spinner {
  border: 3px solid #E2E8F0;
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.saving {
  position: relative;
  opacity: 0.7;
}

.saving::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border: 2px solid #E2E8F0;
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #F3F4F6;
}

::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 3px;
}

.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

/* ============================================
   SAFE AREA (iPhone notch/island)
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
  .login-bg {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================
   UTILITIES
   ============================================ */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-primary { color: var(--primary); }
.text-secondary { color: var(--secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.bg-primary { background-color: var(--primary); }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 24px; }

.text-gray-400 { color: #9CA3AF; }
.text-gray-500 { color: #6B7280; }
.text-gray-600 { color: #4B5563; }
.text-gray-700 { color: #374151; }

/* Loading state */
.loading-overlay {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px;
}

/* ============================================
   TABS
   ============================================ */
.tab-btn {
  background: white;
  border: 1px solid #E5E7EB;
  color: #6B7280;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  background: #F9FAFB;
  color: var(--primary);
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  border-color: transparent;
}

/* ============================================
   CHART CONTAINER
   ============================================ */
canvas {
  max-width: 100%;
  height: auto !important;
}

/* ============================================
   FILTROS Y BÚSQUEDA
   ============================================ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-bar .input-field {
  min-height: 38px;
  font-size: 14px;
  padding: 8px 12px;
}

/* Input de búsqueda con icono */
.filter-bar .input-field.search-input {
  padding-left: 36px;
}

.filter-bar select.input-field {
  min-width: 120px;
  max-width: 180px;
}

/* ============================================
   FORMULARIO AGREGAR (ARRIBA)
   ============================================ */
.add-form {
  border-bottom: 1px solid #E5E7EB;
}

.add-form .form-group {
  display: flex;
  flex-direction: column;
}

.add-form .form-group label {
  font-size: 11px;
  color: #6B7280;
  margin-bottom: 4px;
  font-weight: 500;
}

.add-form .input-field {
  font-size: 14px;
  padding: 8px 12px;
  min-height: 38px;
}

/* ============================================
   PAGINACIÓN
   ============================================ */
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pagination-btn {
  min-width: 32px;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid #E5E7EB;
  background: white;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pagination-btn:hover:not(.disabled):not(.active) {
  background: #F9FAFB;
  border-color: var(--secondary);
  color: var(--primary);
}

.pagination-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.pagination-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   TARJETAS MÓVILES MEJORADAS
   ============================================ */
.data-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #F3F4F6;
}

.data-card-title {
  font-size: 16px;
  font-weight: 600;
  color: #1F2937;
  flex: 1;
  padding-right: 8px;
  word-break: break-word;
}

.data-card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.btn-delete-sm {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #9CA3AF;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-delete-sm:hover {
  background: #FEE2E2;
  color: #EF4444;
}

/* ============================================
   BOTÓN SECUNDARIO
   ============================================ */
.btn-secondary {
  background: white;
  color: var(--primary);
  border: 1px solid #E5E7EB;
  min-height: 38px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s ease;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #F9FAFB;
  border-color: var(--secondary);
}

/* ============================================
   MEJORAS RESPONSIVE
   ============================================ */

/* Móvil pequeño (< 375px) */
@media (max-width: 374px) {
  .table-header {
    padding: 12px;
  }
  
  .data-grid {
    padding: 8px;
    gap: 8px;
  }
  
  .data-card {
    padding: 12px;
  }
  
  .data-card-label {
    font-size: 10px;
    min-width: 60px;
  }
  
  .data-card-title {
    font-size: 14px;
  }
  
  .filter-bar {
    padding: 8px !important;
  }
  
  .add-form {
    padding: 8px !important;
  }
  
  .badge {
    padding: 2px 6px;
    font-size: 10px;
  }
}

/* Móvil (375px - 640px) */
@media (min-width: 375px) and (max-width: 639px) {
  .add-form .grid {
    gap: 8px;
  }
}

/* Tablet (640px - 768px) */
@media (min-width: 640px) and (max-width: 767px) {
  .data-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  
  .data-card {
    height: fit-content;
  }
}

/* ============================================
   MEJORAS GENERALES RESPONSIVE
   ============================================ */
@media (max-width: 640px) {
  /* Inputs más pequeños en móvil */
  .input-field {
    font-size: 16px; /* Evita zoom en iOS */
  }
  
  /* Botones más compactos */
  .btn-primary {
    padding: 0 14px;
    font-size: 13px;
    min-height: 40px;
  }
  
  /* Tarjetas de stats más compactas */
  .card {
    padding: 12px !important;
  }
  
  /* Textos más pequeños */
  .text-2xl {
    font-size: 20px;
  }
  
  .text-xl {
    font-size: 18px;
  }
  
  .text-lg {
    font-size: 16px;
  }
}

/* Ocultar elementos en móvil con clase específica */
@media (max-width: 767px) {
  .hidden-mobile {
    display: none !important;
  }
}

/* ============================================
   LINE CLAMP
   ============================================ */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================
   ANIMACIONES
   ============================================ */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.animate-fade-in {
  animation: fade-in 0.2s ease-out;
}

/* Scrollbar hide utility */
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.scrollbar-hide::-webkit-scrollbar {
  display: none;
}
