/* ==========================================================================
   SafeGuardian Stylesheet - Core Variables & Reset
   ========================================================================== */

:root {
  --bg-primary: #090d16;
  --bg-secondary: #0f1524;
  --bg-card: rgba(15, 21, 36, 0.7);
  --bg-input: #0b0f19;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(239, 68, 68, 0.4);
  
  --text-primary: #f3f4f6;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  
  --accent-color: #ef4444; /* Emergency Red */
  --accent-color-hover: #dc2626;
  --accent-rgb: 239, 68, 68;
  
  --success-color: #10b981; /* Safe Emerald */
  --warning-color: #f59e0b; /* Alert Yellow */
  
  --font-family: 'Plus Jakarta Sans', sans-serif;
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --card-radius: 18px;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 0% 0%, rgba(239, 68, 68, 0.1) 0px, transparent 40%),
    radial-gradient(at 100% 100%, rgba(99, 102, 241, 0.05) 0px, transparent 40%);
  background-attachment: fixed;
}

/* ==========================================================================
   Header Component
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  background-color: rgba(15, 21, 36, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--accent-color);
  box-shadow: 0 0 10px var(--accent-color);
  animation: pulse-dot 1.5s infinite alternate;
}

@keyframes pulse-dot {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.logo-area h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #a0aec0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.active-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */
.main-content {
  flex: 1;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* ==========================================================================
   SOS Beacon Trigger Section
   ========================================================================== */
.sos-trigger-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3rem;
  padding: 2rem 0;
}

.beacon-container {
  position: relative;
  width: 240px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sos-button {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, #ef4444 0%, #b91c1c 100%);
  border: 4px solid rgba(255, 255, 255, 0.1);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  box-shadow: 0 10px 40px rgba(239, 68, 68, 0.4), inset 0 2px 5px rgba(255, 255, 255, 0.3);
  transition: var(--transition-smooth);
}

.sos-button:hover {
  transform: scale(1.03);
  box-shadow: 0 15px 50px rgba(239, 68, 68, 0.6), inset 0 2px 5px rgba(255, 255, 255, 0.4);
}

.sos-button:active, .sos-button.active-state {
  transform: scale(0.95);
  background: radial-gradient(circle, #b91c1c 0%, #7f1d1d 100%);
  box-shadow: 0 5px 20px rgba(239, 68, 68, 0.3);
}

.sos-text {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.sos-subtext {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  margin-top: 8px;
  opacity: 0.8;
}

/* Pulse Rings */
.pulse-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.2);
  pointer-events: none;
  animation: pulse-expand 3s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}

.ring-2 {
  animation-delay: 1.5s;
}

@keyframes pulse-expand {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}

.instruction-box {
  text-align: center;
  max-width: 460px;
}

.instruction-box h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.instruction-box p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ==========================================================================
   Telemetry Status Panel
   ========================================================================== */
.status-panel {
  width: 100%;
  transition: var(--transition-smooth);
}

.status-panel.hidden {
  display: none;
}

.status-card {
  background-color: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 1.5rem;
  box-shadow: var(--glass-shadow);
}

.status-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.status-card-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

/* Status Badges */
.badge-status {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-status.yellow {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--warning-color);
}
.badge-status.green {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
}
.badge-status.red {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--accent-color);
}

/* Telemetry Grid */
.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 600px) {
  .telemetry-grid {
    grid-template-columns: 1fr;
  }
}

.telemetry-box {
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 180px;
}

.box-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.box-header .icon {
  width: 18px;
  height: 18px;
  color: var(--accent-color);
}

.box-header h4 {
  font-size: 0.85rem;
  font-weight: 600;
}

.box-body {
  flex: 1;
}

/* Coordinates Table styling */
.coord-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  font-size: 0.85rem;
}

.coord-lbl {
  color: var(--text-muted);
}

.coord-val {
  font-family: monospace;
  font-weight: 600;
}

.box-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.02);
}

.sensor-status {
  font-size: 0.72rem;
  font-weight: 600;
}

.sensor-status.pending { color: var(--warning-color); }
.sensor-status.granted { color: var(--success-color); }
.sensor-status.denied { color: var(--accent-color); }

/* Camera stream area */
.camera-preview-wrapper {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background-color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4/3;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

#video-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror view */
}

.camera-placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.camera-rec-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: var(--accent-color);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.camera-rec-overlay::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  background-color: white;
  border-radius: 50%;
  animation: blink 0.8s infinite alternate;
}

@keyframes blink {
  from { opacity: 0.2; }
  to { opacity: 1; }
}

/* System Log console */
.system-logs {
  background-color: #05080e;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--success-color);
  max-height: 90px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-item {
  word-break: break-all;
  line-height: 1.4;
}

/* Dynamic progress bar */
.progress-bar-container {
  width: 100%;
  height: 4px;
  background-color: rgba(255,255,255,0.05);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 1rem;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--warning-color), var(--accent-color));
  transition: width 0.1s linear;
}

/* ==========================================================================
   Success Panel Layout
   ========================================================================== */
.success-panel {
  width: 100%;
}

.success-panel.hidden {
  display: none;
}

.success-card {
  background-color: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--card-radius);
  padding: 2.5rem;
  text-align: center;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4), 0 0 30px rgba(16, 185, 129, 0.08);
}

.check-icon-container {
  width: 72px;
  height: 72px;
  background-color: rgba(16, 185, 129, 0.12);
  border: 2px solid var(--success-color);
  color: var(--success-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

.check-svg {
  width: 32px;
  height: 32px;
}

.success-card h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
}

.success-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto 1.5rem;
}

.incident-details {
  background-color: rgba(0,0,0,0.15);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.8rem;
  display: inline-block;
  margin-bottom: 2rem;
  text-align: left;
}

.incident-details p {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.incident-details p:last-child {
  margin-bottom: 0;
}

.incident-details span {
  font-family: monospace;
  font-weight: 700;
  color: var(--text-primary);
}

/* ==========================================================================
   Admin Interface Login Panel
   ========================================================================== */
.admin-login-body {
  justify-content: center;
  align-items: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background-color: var(--bg-card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 2rem;
  box-shadow: var(--glass-shadow);
  margin: auto;
}

.login-card-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-card-header h2 {
  font-size: 1.25rem;
  font-weight: 800;
}

.login-card-header p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-smooth);
}

.form-control:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.15);
}

.error-alert {
  background-color: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--accent-color);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.78rem;
  margin-bottom: 1.25rem;
  font-weight: 500;
}

/* Common Buttons */
.btn {
  font-family: var(--font-family);
  border: 1px solid transparent;
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
}

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

.btn-primary {
  background-color: var(--accent-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--accent-color-hover);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

/* ==========================================================================
   Admin Console Layout
   ========================================================================== */
.admin-view-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  gap: 1.5rem;
}

.admin-console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.admin-header-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.admin-header-title h2 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
}

.admin-console-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  flex: 1;
}

@media (max-width: 900px) {
  .admin-console-grid {
    grid-template-columns: 1fr;
  }
}

.admin-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--glass-shadow);
  max-height: calc(100vh - 140px);
  overflow: hidden;
}

@media (max-width: 900px) {
  .admin-card {
    max-height: none;
  }
}

.admin-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* Filters */
.filter-group-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.filter-group-row .form-control {
  padding: 0.5rem;
  font-size: 0.8rem;
}

.search-input-wrapper {
  margin-bottom: 1.25rem;
}

.search-input-wrapper .form-control {
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
}

/* Alert list */
.alerts-list-container {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 4px;
}

.alert-item-card {
  background-color: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.alert-item-card:hover {
  background-color: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.15);
}

.alert-item-card.active {
  background-color: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}

.alert-item-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.alert-item-badge {
  font-size: 0.6rem;
  font-weight: 700;
  background-color: rgba(239, 68, 68, 0.12);
  color: var(--accent-color);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.alert-item-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.alert-item-coord {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alert-item-ip {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Detail panel empty state */
.empty-detail-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.alert-detail-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding-right: 4px;
}

.detail-pane-header {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
}

.detail-pane-header h4 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
}

.detail-pane-header p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.detail-grid-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 600px) {
  .detail-grid-layout {
    grid-template-columns: 1fr;
  }
}

.detail-sub-card {
  background-color: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.detail-sub-card h5 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
}

.device-info-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
  background-color: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.02);
  border-radius: 6px;
  padding: 0.5rem;
  font-family: monospace;
  word-break: break-all;
}

.photo-wrapper-card {
  align-items: center;
}

.img-container {
  width: 100%;
  aspect-ratio: 4/3;
  background-color: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scaleX(-1); /* Keep front capture aligned */
}

/* Map frame */
.map-iframe-container {
  width: 100%;
  height: 200px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.map-iframe-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ==========================================================================
   Footer Component
   ========================================================================== */
.app-footer {
  text-align: center;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
  background-color: rgba(15, 21, 36, 0.3);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.admin-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition-smooth);
}

.admin-link:hover {
  color: var(--accent-color);
}
