/* ============================================
   FrameServer - Modern Dark Theme
   ============================================ */

/* Design Tokens */
:root {
  /* Background layers */
  --bg-base: #0d0d14;
  --bg-surface: #141420;
  --bg-elevated: #1a1a2e;
  --bg-overlay: #222238;

  /* Accent colors */
  --accent-primary: #e94560;
  --accent-secondary: #7c3aed;
  --accent-gradient: linear-gradient(135deg, #e94560 0%, #7c3aed 100%);

  /* Text colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Status colors */
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.15);

  /* Effects */
  --glow-accent: rgba(233, 69, 96, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--glow-accent);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 { font-size: 2rem; margin-bottom: var(--space-6); }
h2 { font-size: 1.5rem; margin-bottom: var(--space-4); }
h3 { font-size: 1.25rem; margin-bottom: var(--space-3); }

p { color: var(--text-secondary); }

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--text-primary);
}

/* ============================================
   Navigation
   ============================================ */

nav {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-4) var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: var(--space-6);
  align-items: center;
}

.nav-links a {
  color: var(--text-secondary);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.nav-links a:hover {
  color: var(--text-primary);
  background: var(--bg-overlay);
}

/* Mobile menu toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-2);
}

@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-4);
    gap: 0;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    width: 100%;
  }

  .nav-links a:last-child {
    border-bottom: none;
  }
}

/* ============================================
   Container & Layout
   ============================================ */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-6);
  animation: fadeInUp 0.4s ease-out;
}

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

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-4);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9375rem;
  cursor: pointer;
  border: none;
  transition: all var(--transition-base);
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: var(--bg-overlay);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.btn-sm {
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
}

.btn-icon {
  padding: var(--space-2);
  background: transparent;
  color: var(--text-muted);
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-overlay);
}

/* ============================================
   Cards
   ============================================ */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--transition-base);
}

.card:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

.card-lift:hover {
  transform: translateY(-4px);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-lg);
}

/* Glass effect card */
.card-glass {
  background: linear-gradient(
    145deg,
    rgba(22, 33, 62, 0.8),
    rgba(26, 26, 46, 0.9)
  );
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ============================================
   Forms
   ============================================ */

.form-group {
  margin-bottom: var(--space-5);
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: all var(--transition-base);
}

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

.form-group input::placeholder {
  color: var(--text-muted);
}

.form-group small {
  display: block;
  margin-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Checkbox */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.checkbox-group input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.checkbox-group label {
  margin: 0;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-6);
}

@media (max-width: 480px) {
  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }
}

/* ============================================
   Flash Messages
   ============================================ */

.flash {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  animation: slideIn 0.3s ease-out;
  position: relative;
  overflow: hidden;
}

.flash::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.flash.success {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.flash.success::before { background: var(--success); }

.flash.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.flash.error::before { background: var(--error); }

.flash.info {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.flash.info::before { background: var(--info); }

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

/* ============================================
   Status Badges & Indicators
   ============================================ */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.status-badge.active,
.status-badge.online {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.status-badge.inactive,
.status-badge.offline {
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-muted);
}

.status-badge.idle {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.status-badge.never_connected {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: relative;
}

.status-dot.online {
  background: var(--success);
}

.status-dot.online::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--success);
  animation: ripple 2s ease-out infinite;
}

.status-dot.idle { background: var(--warning); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.never_connected { background: var(--error); }

@keyframes ripple {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* ============================================
   Video/Item List
   ============================================ */

.item-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.item-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  transition: all var(--transition-base);
  position: relative;
}

.item-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent-primary);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.item-card:hover {
  background: var(--bg-overlay);
  border-color: var(--border-default);
  transform: translateX(4px);
}

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

.item-card.disabled {
  opacity: 0.5;
}

.item-info {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
  flex: 1;
}

.item-details h3 {
  font-size: 1rem;
  font-weight: 500;
  margin: 0 0 var(--space-1) 0;
  word-break: break-word;
}

.item-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.item-meta span:not(:last-child)::after {
  content: '•';
  margin-left: var(--space-2);
  opacity: 0.5;
}

.item-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Drag handle */
.drag-handle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--space-2);
  cursor: grab;
  opacity: 0.4;
  transition: opacity var(--transition-fast);
}

.drag-handle:active {
  cursor: grabbing;
}

.item-card:hover .drag-handle {
  opacity: 0.8;
}

.drag-handle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 1px;
}

/* Dragging state */
.item-card.dragging {
  opacity: 0.9;
  transform: scale(1.02) rotate(0.5deg);
  box-shadow: var(--shadow-lg);
  z-index: 10;
}

/* ============================================
   Device Grid
   ============================================ */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-5);
}

.device-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--transition-base);
}

.device-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-lg);
}

.device-card h3 {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-2) 0;
}

.device-card h3 a {
  color: var(--text-primary);
}

.device-card h3 a:hover {
  color: var(--accent-primary);
}

.device-location {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
}

.device-stats {
  display: flex;
  gap: var(--space-5);
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.device-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-3);
}

/* ============================================
   Info Grid
   ============================================ */

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.info-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  transition: border-color var(--transition-fast);
}

.info-card:hover {
  border-color: var(--accent-primary);
}

.info-card label {
  display: block;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.info-card .value {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* ============================================
   API Key Box
   ============================================ */

.api-key-box {
  background: linear-gradient(135deg, rgba(233, 69, 96, 0.08), rgba(124, 58, 237, 0.08));
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}

.api-key-box h3 {
  color: var(--accent-primary);
  margin: 0 0 var(--space-2) 0;
}

.api-key-value {
  font-family: var(--font-mono);
  background: var(--bg-base);
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  word-break: break-all;
  margin: var(--space-4) 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}

.api-key-warning {
  color: var(--warning);
  font-size: 0.875rem;
}

/* ============================================
   Drop Zone (Upload)
   ============================================ */

.drop-zone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-gradient);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent-primary);
  background: rgba(233, 69, 96, 0.05);
}

.drop-zone:hover::before,
.drop-zone.dragover::before {
  opacity: 0.03;
}

.drop-zone h2 {
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  position: relative;
}

.drop-zone p {
  margin-bottom: var(--space-4);
  position: relative;
}

.drop-zone input[type="file"] {
  display: none;
}

.drop-zone-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  display: block;
  transition: transform var(--transition-base);
}

.drop-zone:hover .drop-zone-icon {
  transform: translateY(-8px);
}

/* File info display */
.file-info {
  background: var(--bg-base);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-top: var(--space-4);
  display: none;
}

.file-info.visible {
  display: block;
}

.file-info .filename {
  font-weight: 500;
  word-break: break-word;
}

.file-info .filesize {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-base);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: var(--space-4);
  display: none;
}

.progress-bar.visible {
  display: block;
}

.progress-bar .progress {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: var(--radius-full);
  width: 0%;
  transition: width 0.3s ease;
  position: relative;
}

.progress-bar .progress::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.empty-state h2 {
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.empty-state p {
  margin-bottom: var(--space-6);
}

/* ============================================
   Section Headers
   ============================================ */

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: var(--space-8) 0 var(--space-4) 0;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.section-header h2 {
  margin: 0;
}

/* ============================================
   Login Page Specific
   ============================================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(ellipse at top, rgba(233, 69, 96, 0.1) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(124, 58, 237, 0.1) 0%, transparent 50%),
    var(--bg-base);
}

.login-box {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(145deg, rgba(22, 33, 62, 0.9), rgba(26, 26, 46, 0.95));
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.login-box h1 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: var(--space-8);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-box .btn {
  width: 100%;
  padding: var(--space-4);
  font-size: 1rem;
  margin-top: var(--space-4);
}

/* ============================================
   Utility Classes
   ============================================ */

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.hidden { display: none; }

/* Form inline display */
form { display: inline; }

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 768px) {
  .container {
    padding: var(--space-4);
  }

  h1 { font-size: 1.5rem; }

  .btn {
    min-height: 44px;
  }

  .form-group input,
  .form-group select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom */
  }

  .item-card {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
  }

  .item-info {
    flex-direction: column;
    align-items: flex-start;
  }

  .item-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .device-grid {
    grid-template-columns: 1fr;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .header-row {
    flex-direction: column;
    align-items: stretch;
  }

  .header-row .btn {
    width: 100%;
  }
}
