/* ============================================================================
   ESTILOS PWA - APP-LIKE MOBILE-FIRST
   Objetivo: apariencia nativa con safe-areas y navegacion inferior
   ========================================================================== */

:root {
  --app-primary: #0d47a1;
  --app-primary-dark: #002171;
  --app-surface: #ffffff;
  --app-background: #f5f7fb;
  --app-on-surface: #1a1a1a;
  --app-border: #e0e0e0;
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
  --safe-area-left: env(safe-area-inset-left);
  --safe-area-right: env(safe-area-inset-right);
  --header-height: 60px;
  --bottom-nav-height: 70px;
}

.app-body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--app-background);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-height) + var(--safe-area-top));
  background: var(--app-primary);
  color: #fff;
  z-index: 1000;
  border-bottom: 1px solid var(--app-primary-dark);
  padding-top: var(--safe-area-top);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

.app-header .container-fluid {
  height: var(--header-height);
  display: flex;
  align-items: center;
}

.app-title {
  display: flex;
  align-items: center;
  font-size: 1.1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.connectivity-indicator {
  font-size: 1.1rem;
  opacity: 0.9;
}

.connectivity-indicator.offline {
  color: #ff9800;
}

.app-content {
  position: fixed;
  top: calc(var(--header-height) + var(--safe-area-top));
  left: var(--safe-area-left);
  right: var(--safe-area-right);
  bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.app-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
  background: var(--app-surface);
  border-top: 1px solid var(--app-border);
  z-index: 1000;
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

.nav-container {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: var(--bottom-nav-height);
  align-items: center;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #6c757d;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.5rem 0.25rem;
  transition: all 0.2s ease;
  border-radius: 8px;
  margin: 0 0.25rem;
  min-height: 44px;
}

.nav-item i {
  font-size: 1.4rem;
  margin-bottom: 0.25rem;
  transition: transform 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
  color: var(--app-primary);
  background: rgba(13, 71, 161, 0.08);
}

.nav-item.active i {
  transform: scale(1.1);
}

.page {
  padding: 1rem;
  min-height: 100%;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--app-on-surface);
  margin-bottom: 0.5rem;
}

.app-card {
  background: var(--app-surface);
  border-radius: 12px;
  border: 1px solid var(--app-border);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.app-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--app-border);
  background: rgba(13, 71, 161, 0.02);
}

.app-card-body {
  padding: 1.25rem;
}

.btn-app {
  border-radius: 8px;
  font-weight: 500;
  padding: 0.75rem 1.5rem;
  min-height: 44px;
  border: none;
  transition: all 0.2s ease;
}

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

.btn-primary.btn-app {
  background: var(--app-primary);
  box-shadow: 0 2px 8px rgba(13, 71, 161, 0.3);
}

.toast-container {
  position: fixed;
  bottom: calc(16px + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(420px, 92vw);
  z-index: 2000;
  pointer-events: none;
}

.toast-item {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  padding: 0.75rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toast-in 180ms ease-out;
  pointer-events: auto;
  position: relative;
}

.toast-item.hide {
  animation: toast-out 150ms ease-in forwards;
}

.toast-title {
  font-weight: 700;
  margin-bottom: 2px;
  color: #111;
}

.toast-message {
  color: #444;
  font-size: 0.95rem;
}

.toast-content {
  flex: 1;
}

.toast-action {
  border: none;
  background: transparent;
  color: var(--app-primary);
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.toast-close {
  border: none;
  background: transparent;
  color: #777;
  font-size: 1.1rem;
  cursor: pointer;
}

.toast-success {
  border-left: 4px solid #28a745;
}

.toast-warning {
  border-left: 4px solid #ffc107;
}

.toast-error {
  border-left: 4px solid #dc3545;
}

.toast-info {
  border-left: 4px solid #0d6efd;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, 16px);
  }
}

.global-loader {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1900;
}

.global-loader.active {
  display: flex;
}

.loader-backdrop {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.35);
}

.loader-body {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 2;
}

.loader-spinner,
.inline-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid #e5e7eb;
  border-top-color: var(--app-primary);
  animation: spin 0.9s linear infinite;
}

.loader-message {
  color: #333;
  font-weight: 600;
}

.inline-loader {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  border-radius: inherit;
}

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

.login-body {
  background: linear-gradient(135deg, #0d47a1 0%, #0d6efd 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-wrapper {
  width: min(420px, 96vw);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}

.login-card .form-control {
  min-height: 48px;
  border-radius: 12px;
}

.login-card .btn {
  min-height: 48px;
  border-radius: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.9rem;
}

.user-chip .user-role {
  font-size: 0.75rem;
  opacity: 0.85;
}

.btn-logout {
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  border-radius: 999px;
}

@media (min-width: 768px) {
  :root {
    --header-height: 64px;
  }
  .app-title {
    font-size: 1.25rem;
  }
  .nav-item {
    font-size: 0.8rem;
  }
  .nav-item i {
    font-size: 1.5rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app-header {
    padding-top: 0;
  }
  .nav-item span {
    display: none;
  }
  .nav-item i {
    margin-bottom: 0;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-surface: #1a1a1a;
    --app-background: #121212;
    --app-on-surface: #ffffff;
    --app-border: #333333;
  }
}
