/* CSS Principal - Estética Premium para Tecco-Citofonía */

:root {
  --bg-color: #0d0f17;
  --bg-gradient: radial-gradient(circle at top right, #1a1b2e 0%, #0d0f17 100%);
  --panel-bg: rgba(25, 28, 48, 0.45);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f1f3f9;
  --text-secondary: #9aa0b9;
  --accent-color: #7c4dff;
  --accent-hover: #651fff;
  --success-color: #00e676;
  --danger-color: #ff1744;
  --warning-color: #ffc400;
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-color);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.app-container {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.app-header {
  text-align: center;
  padding-bottom: 8px;
}

.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.logo-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 10px var(--accent-color));
}

.logo-title {
  font-weight: 700;
  font-size: 2.2rem;
  background: linear-gradient(to right, #ffffff, #a382ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.logo-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 6px;
  font-weight: 300;
  letter-spacing: 1px;
}

/* Grids and Cards */
.app-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 20px;
}

.card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(124, 77, 255, 0.25);
}

.auth-card {
  grid-column: span 6;
}

.identity-card {
  grid-column: span 6;
}

.comms-card {
  grid-column: span 4;
}

.video-card {
  grid-column: span 8;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.25px;
  color: #fff;
}

.card-body {
  padding: 20px;
}

/* Form controls */
.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

textarea, input[type="text"], select {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: none;
}

textarea:focus, input[type="text"]:focus, select:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.15);
}

select option {
  background-color: #14182e;
  color: #fff;
}

/* Badges */
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-block;
  transition: background 0.3s;
}

.badge-disconnected {
  background: rgba(255, 23, 68, 0.15);
  color: var(--danger-color);
  border: 1px solid rgba(255, 23, 68, 0.3);
}

.badge-connected {
  background: rgba(0, 230, 118, 0.15);
  color: var(--success-color);
  border: 1px solid rgba(0, 230, 118, 0.3);
  animation: pulse-border 2s infinite;
}

/* Buttons */
.btn-group {
  display: flex;
  gap: 12px;
}

.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary {
  background: var(--accent-color);
  color: #fff;
  box-shadow: 0 4px 12px rgba(124, 77, 255, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(124, 77, 255, 0.5);
}

.btn-danger {
  background: rgba(255, 23, 68, 0.1);
  color: var(--danger-color);
  border: 1px solid rgba(255, 23, 68, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-color);
  color: #fff;
}

.btn-success {
  background: var(--success-color);
  color: #000;
  box-shadow: 0 4px 12px rgba(0, 230, 118, 0.3);
}

.btn-success:hover:not(:disabled) {
  background: #00b0ff;
  box-shadow: 0 4px 16px rgba(0, 176, 255, 0.5);
  color: #fff;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--panel-border);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

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

.modal-input {
  width: 100%;
  font-size: 1.05rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-family: var(--font-sans);
  margin-top: 12px;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.btn-full {
  width: 100%;
}

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.info-value {
  font-size: 0.95rem;
  font-weight: 600;
  word-break: break-all;
}

/* Video components */
.video-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-height: 220px;
}

.video-wrapper {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.video-wrapper h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  font-weight: 500;
}

video {
  width: 100%;
  height: 160px;
  background: #000;
  border-radius: 8px;
  object-fit: cover;
  transform: scaleX(-1); /* Espejo para video local */
}

#remote-video {
  transform: none; /* No espejo para remoto */
}

/* Modal overlays (Glassmorphism) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 7, 14, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: rgba(20, 24, 46, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  width: 90%;
  max-width: 420px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content {
  transform: translateY(-20px);
}

.modal-header {
  margin-bottom: 20px;
}

.modal-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
}

.modal-icon.ringing {
  animation: ring 1s infinite alternate;
}

.modal-icon.dialing {
  animation: dial 1.5s infinite ease-in-out;
}

.modal-header h3 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}

.modal-body {
  margin-bottom: 28px;
}

.modal-body p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.caller-highlight {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-color);
  background: rgba(124, 77, 255, 0.1);
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid rgba(124, 77, 255, 0.2);
  display: inline-block;
}

/* Call Control Bar */
.active-call-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 24, 46, 0.9);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  padding: 12px 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  gap: 28px;
  z-index: 999;
  transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.active-call-bar.hidden {
  bottom: -100px;
}

.call-details {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--success-color);
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite;
}

#active-partner-display {
  font-weight: 600;
  font-size: 0.9rem;
}

.call-controls {
  display: flex;
  gap: 12px;
}

.btn-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-circle:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.08);
}

.btn-circle.btn-danger {
  background: var(--danger-color);
  border: none;
}

.btn-circle.btn-danger:hover {
  background: #d50000;
}

.btn-circle.active {
  background: rgba(124, 77, 255, 0.3);
  border-color: var(--accent-color);
}

/* Animations */
@keyframes pulse-border {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 230, 118, 0.4);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(0, 230, 118, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 230, 118, 0);
  }
}

@keyframes pulse-dot {
  0% {
    transform: scale(0.9);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(0.9);
    opacity: 0.8;
  }
}

@keyframes ring {
  0% {
    transform: rotate(0) scale(1);
  }
  20% {
    transform: rotate(10deg) scale(1.1);
  }
  40% {
    transform: rotate(-10deg) scale(1.1);
  }
  60% {
    transform: rotate(10deg) scale(1.1);
  }
  80% {
    transform: rotate(-10deg) scale(1.1);
  }
  100% {
    transform: rotate(0) scale(1);
  }
}

@keyframes dial {
  0% {
    transform: translateY(0);
    opacity: 0.7;
  }
  50% {
    transform: translateY(-8px);
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }
}

/* Panel de Administración: cuadrícula de estadísticas y CRUD de residentes */
.admin-login-card {
  grid-column: 1 / -1;
  max-width: 420px;
  margin: 0 auto;
}

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

.admin-crud-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
  align-items: start;
}

/* Responsive */
@media (max-width: 900px) {
  .auth-card, .identity-card, .comms-card, .video-card {
    grid-column: span 12;
  }
  .info-grid {
    grid-template-columns: 1fr;
  }
  .video-grid {
    grid-template-columns: 1fr;
  }
  .admin-crud-grid {
    grid-template-columns: 1fr;
  }
  .admin-stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}

/* Historial de Llamadas */
.history-card {
  grid-column: span 12;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.history-table th, .history-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
}

.history-table th {
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.history-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.status-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-block;
}

.status-answered {
  background: rgba(0, 230, 118, 0.15);
  color: var(--success-color);
  border: 1px solid rgba(0, 230, 118, 0.3);
}

.status-missed {
  background: rgba(255, 23, 68, 0.15);
  color: var(--danger-color);
  border: 1px solid rgba(255, 23, 68, 0.3);
}

.status-rejected {
  background: rgba(255, 196, 0, 0.15);
  color: var(--warning-color);
  border: 1px solid rgba(255, 196, 0, 0.3);
}

/* Tab Navigation */
.tab-nav {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 12px;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  color: var(--text-secondary);
  padding: 10px 20px;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.tab-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 20px rgba(124, 77, 255, 0.3);
}

/* Tab content toggling */
.tab-content.hidden {
  display: none !important;
}

/* Admin Dashboard Specific Styles */
.stat-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  background: rgba(255, 255, 255, 0.03);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.05);
}

.stat-value {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
}

/* Status text for resident table */
.status-active {
  color: var(--success-color);
  font-weight: 600;
}

.status-inactive {
  color: var(--text-secondary);
  font-weight: 400;
}

/* Connection Tabs & Form Panels */
.login-tab-btn {
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.login-tab-btn:hover {
  background: rgba(255, 255, 255, 0.05) !important;
  color: var(--text-primary) !important;
  transform: translateY(-0.5px);
}

.login-tab-btn.active {
  background: rgba(124, 77, 255, 0.15) !important;
  border-color: rgba(124, 77, 255, 0.4) !important;
  color: #c7a4ff !important; /* lightened for dark background */
  font-weight: 600;
  box-shadow: 0 0 10px rgba(124, 77, 255, 0.1);
}

.login-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeIn 0.2s ease-out;
}

.login-panel.hidden {
  display: none !important;
}

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