/* ==========================================================================
   AetherLink Core Design System (Vanilla CSS) - UPDATED FOR DYNAMIC DEVICES & PINs
   ========================================================================== */

/* --- Custom Properties & Tokens --- */
:root {
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Color Palette (HSL Tailored for sleek dark mode) */
  --bg-main: #080c14;
  --bg-gradient-1: #0a1128;
  --bg-gradient-2: #050811;
  
  --panel-bg: rgba(13, 20, 38, 0.45);
  --panel-border: rgba(255, 255, 255, 0.07);
  --panel-border-hover: rgba(59, 130, 246, 0.4);
  
  --color-primary: #3b82f6;      /* Electric Blue */
  --color-primary-glow: rgba(59, 130, 246, 0.35);
  --color-success: #10b981;      /* Emerald Green */
  --color-success-glow: rgba(16, 185, 129, 0.3);
  --color-warning: #f59e0b;      /* Amber */
  --color-warning-glow: rgba(245, 158, 11, 0.3);
  --color-danger: #ef4444;       /* Crimson */
  --color-danger-glow: rgba(239, 68, 68, 0.3);
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  /* Animations */
  --transition-smooth: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: all 0.2s ease;
}

/* --- Base Styles & Reset --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%),
    linear-gradient(180deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
}

/* --- Layout Structure --- */
.app-container {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
  width: 260px;
  background: rgba(8, 12, 20, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--panel-border);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 10;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 3rem;
}

.brand-logo {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-success));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px var(--color-primary-glow);
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-grow: 1;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 10px;
  font-weight: 500;
  transition: var(--transition-smooth);
}

.nav-item.active a, .nav-item a:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active a {
  border-left: 3px solid var(--color-primary);
  background: rgba(59, 130, 246, 0.08);
}

.nav-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* User Card in Sidebar */
.user-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.username {
  font-size: 0.875rem;
  font-weight: 600;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  overflow-y: auto;
  max-width: 1600px;
  margin: 0 auto;
  width: calc(100% - 260px);
}

/* Header Section */
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.page-title h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  background: linear-gradient(to right, #ffffff, #9ca3af);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.page-title p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  gap: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition-smooth);
  border: none;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 4px 15px var(--color-primary-glow);
}

.btn-primary:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

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

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

/* --- Device Grid --- */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.75rem;
}

/* Glassmorphic Device Card */
.device-card {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  transition: var(--transition-smooth);
  position: relative;
  overflow: hidden;
  animation: cardFadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.device-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.05) 0%, transparent 100%);
  opacity: 0;
  transition: var(--transition-smooth);
  pointer-events: none;
}

.device-card:hover {
  transform: translateY(-5px);
  border-color: var(--panel-border-hover);
  box-shadow: 0 12px 30px rgba(8, 12, 20, 0.5), 0 0 20px rgba(59, 130, 246, 0.15);
}

.device-card:hover::before {
  opacity: 1;
}

/* Card Header */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.device-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.os-icon-wrapper {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.device-title {
  display: flex;
  flex-direction: column;
}

.device-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.device-ip {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-online {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-online .pulse-dot {
  background-color: var(--color-success);
  box-shadow: 0 0 8px var(--color-success-glow);
}

.status-sleep {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-sleep .pulse-dot {
  background-color: var(--color-warning);
  box-shadow: 0 0 8px var(--color-warning-glow);
}

.status-offline {
  background: rgba(107, 114, 128, 0.1);
  color: var(--text-secondary);
  border: 1px solid rgba(107, 114, 128, 0.2);
}

.status-offline .pulse-dot {
  background-color: var(--text-muted);
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  animation: pulse-ring 1.8s infinite ease-in-out;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.5; }
}

/* Screen Previews */
.screen-preview-container {
  width: 100%;
  height: 160px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-preview-gradient {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  opacity: 0.8;
  position: absolute;
  top: 0;
  left: 0;
}

.screen-content-mockup {
  width: 85%;
  height: 80%;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 2;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mockup-desktop-wallpaper {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  transition: var(--transition-smooth);
}

.mockup-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 12, 20, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  gap: 0.5rem;
  z-index: 3;
}

/* Card Specs / Details */
.card-details {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 1rem;
}

.spec-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.spec-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.spec-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Card Footer Action */
.card-actions {
  margin-top: auto;
  display: flex;
  gap: 0.75rem;
}

.card-actions .btn {
  flex: 1;
  justify-content: center;
}

/* --- Dynamic Forms & Modals Styling --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(4, 6, 12, 0.8);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: rgba(13, 20, 38, 0.8);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  width: 90%;
  max-width: 520px;
  padding: 2.25rem;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  transform: scale(0.9);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.1);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input, .form-select {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.35);
  color: white;
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 10px var(--color-primary-glow);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* PIN Verification Input */
.pin-challenge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  text-align: center;
}

.pin-input-field {
  width: 240px;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 12px;
  text-align: center;
  padding: 0.5rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.4);
  color: var(--color-success);
  text-shadow: 0 0 10px var(--color-success-glow);
  font-family: monospace;
}

.pin-input-field:focus {
  outline: none;
  border-color: var(--color-success);
  box-shadow: 0 0 15px var(--color-success-glow);
}

/* --- Connection Overlay (Futuristic Connecting Dialog) --- */
.connection-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 8, 17, 0.95);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.connection-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.connection-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  max-width: 480px;
  width: 90%;
  text-align: center;
}

.scanner-ring {
  position: relative;
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-circle {
  position: absolute;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--color-primary);
  border-bottom-color: var(--color-success);
  width: 100%;
  height: 100%;
  animation: spin 3s linear infinite;
}

.scanner-circle-inner {
  position: absolute;
  border-radius: 50%;
  border: 1px dashed rgba(59, 130, 246, 0.4);
  width: 80%;
  height: 80%;
  animation: spin-reverse 8s linear infinite;
}

.scanner-core {
  width: 80px;
  height: 80px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid var(--color-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  box-shadow: 0 0 30px var(--color-primary-glow);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes spin-reverse {
  0% { transform: rotate(360deg); }
  100% { transform: rotate(0deg); }
}

.connection-status-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.connection-status-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.connection-log {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
  text-align: left;
  font-family: monospace;
  font-size: 0.8rem;
  height: 120px;
  overflow-y: auto;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.log-line {
  display: flex;
  gap: 0.5rem;
}

.log-time {
  color: var(--text-muted);
}

.log-success {
  color: var(--color-success);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: rgba(16, 185, 129, 0.9);
  backdrop-filter: blur(10px);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transform: translateY(150%);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1000;
}

.toast.active {
  transform: translateY(0);
}

/* --- Responsive Layout adjustments --- */
@media (max-width: 1024px) {
  .sidebar {
    width: 80px;
    padding: 2rem 1rem;
  }
  .brand-name, .user-info {
    display: none;
  }
  .main-content {
    width: calc(100% - 80px);
  }
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: 70px;
    flex-direction: row;
    padding: 0.5rem 1.5rem;
  }
  .brand-section {
    margin-bottom: 0;
  }
  .nav-menu {
    flex-direction: row;
    justify-content: center;
    gap: 1rem;
  }
  .user-card {
    display: none;
  }
  .main-content {
    width: 100%;
    padding: 1.5rem;
  }
}
