/* Design System & Tokens */
:root {
  --font-display: 'Outfit', sans-serif;
  --font-sans: 'Inter', sans-serif;

  /* Colors */
  --bg-dark: #070913;
  --bg-glow: radial-gradient(circle at 50% -20%, rgba(30, 41, 59, 0.45), rgba(7, 9, 19, 0.98));
  --card-bg: rgba(15, 23, 42, 0.45);
  --card-border: rgba(255, 255, 255, 0.05);
  --card-hover-border: rgba(255, 255, 255, 0.1);
  
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dimmed: #4b5563;

  /* App Themes */
  --radarr-color: #ff8533;
  --radarr-glow: rgba(255, 133, 51, 0.15);
  
  --sonarr-color: #3b82f6;
  --sonarr-glow: rgba(59, 130, 246, 0.15);
  
  --lidarr-color: #10b981;
  --lidarr-glow: rgba(16, 185, 129, 0.15);
  
  --readarr-color: #a855f7;
  --readarr-glow: rgba(168, 85, 247, 0.15);
  
  --tdarr-color: #ec4899;
  --tdarr-glow: rgba(236, 72, 153, 0.15);

  --status-online: #10b981;
  --status-offline: #ef4444;
  
  /* Utils */
  --radius-lg: 16px;
  --radius-md: 10px;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Stunning Dynamic Background */
.glass-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-glow);
  z-index: -2;
}

.glass-bg::after {
  content: '';
  position: absolute;
  top: 10%;
  left: 20%;
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.08) 0%, rgba(0,0,0,0) 70%);
  z-index: -1;
  filter: blur(80px);
  pointer-events: none;
}

.glass-bg::before {
  content: '';
  position: absolute;
  bottom: 10%;
  right: 20%;
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(236, 72, 153, 0.05) 0%, rgba(0,0,0,0) 70%);
  z-index: -1;
  filter: blur(80px);
  pointer-events: none;
}

/* Layout Container */
.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header Section */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  color: var(--sonarr-color);
}

.header-logo h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.header-logo h1 span {
  background: linear-gradient(135deg, var(--sonarr-color) 0%, var(--tdarr-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.refresh-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.dropdown {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  outline: none;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.dropdown:hover, .dropdown:focus {
  border-color: var(--sonarr-color);
  background: rgba(15, 23, 42, 0.95);
}

/* Sync Button */
.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-primary {
  background: linear-gradient(135deg, var(--sonarr-color) 0%, #1d4ed8 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.35);
}

.btn-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.6s ease;
}

.btn:hover .btn-icon {
  transform: rotate(180deg);
}

/* Dashboard Layout split */
.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 28px;
  flex-grow: 1;
}

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

/* Left Main Content Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

/* Premium Card Glassmorphism */
.app-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.app-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  transition: var(--transition-smooth);
}

.card-radarr::before { background: var(--radarr-color); }
.card-sonarr::before { background: var(--sonarr-color); }
.card-lidarr::before { background: var(--lidarr-color); }
.card-readarr::before { background: var(--readarr-color); }
.card-tdarr::before { background: var(--tdarr-color); }

.app-card:hover {
  transform: translateY(-4px);
  border-color: var(--card-hover-border);
}

.card-radarr:hover { box-shadow: 0 10px 30px var(--radarr-glow); }
.card-sonarr:hover { box-shadow: 0 10px 30px var(--sonarr-glow); }
.card-lidarr:hover { box-shadow: 0 10px 30px var(--lidarr-glow); }
.card-readarr:hover { box-shadow: 0 10px 30px var(--readarr-glow); }
.card-tdarr:hover { box-shadow: 0 10px 30px var(--tdarr-glow); }

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

.app-identity {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.icon-radarr { color: var(--radarr-color); background: rgba(255, 133, 51, 0.08); }
.icon-sonarr { color: var(--sonarr-color); background: rgba(59, 130, 246, 0.08); }
.icon-lidarr { color: var(--lidarr-color); background: rgba(16, 185, 129, 0.08); }
.icon-readarr { color: var(--readarr-color); background: rgba(168, 85, 247, 0.08); }
.icon-tdarr { color: var(--tdarr-color); background: rgba(236, 72, 153, 0.08); }

.app-identity h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Status Indicators */
.status-indicator {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-smooth);
}

.status-indicator::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.status-indicator.online {
  background: rgba(16, 185, 129, 0.1);
  color: var(--status-online);
}

.status-indicator.online::before {
  background: var(--status-online);
  box-shadow: 0 0 8px var(--status-online);
  animation: pulse 2s infinite;
}

.status-indicator.offline {
  background: rgba(239, 68, 68, 0.1);
  color: var(--status-offline);
}

.status-indicator.offline::before {
  background: var(--status-offline);
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.6; }
  100% { transform: scale(0.9); opacity: 1; }
}

/* Card Content / Stats Grid */
.card-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  gap: 8px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  padding: 10px 4px;
  text-align: center;
  transition: var(--transition-smooth);
}

.stat-box:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

.stat-value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 2px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

/* Special Highlighting Box Types */
.warning-box { border-color: rgba(239, 68, 68, 0.15); }
.warning-box .stat-value { color: #fca5a5; }

.info-box { border-color: rgba(59, 130, 246, 0.15); }
.info-box .stat-value { color: #93c5fd; }

.success-box { border-color: rgba(16, 185, 129, 0.15); }
.success-box .stat-value { color: #a7f3d0; }

/* Progress / Completion Bar */
.progress-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-bar-outer {
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}

.bar-radarr { background: linear-gradient(90deg, var(--radarr-color), #f97316); }
.bar-sonarr { background: linear-gradient(90deg, var(--sonarr-color), #2563eb); }
.bar-lidarr { background: linear-gradient(90deg, var(--lidarr-color), #059669); }
.bar-readarr { background: linear-gradient(90deg, var(--readarr-color), #7c3aed); }
.bar-tdarr { background: linear-gradient(90deg, var(--tdarr-color), #db2777); }

/* SIDEBAR LAYOUT */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-panel h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  border-left: 3px solid var(--sonarr-color);
  padding-left: 10px;
  letter-spacing: -0.01em;
}

/* System Metrics inside Sidebar */
.metric-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-bar-outer {
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
}

.metric-bar-inner {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease-out;
  width: 0%;
}

.cpu-bar { background: var(--tdarr-color); }
.ram-bar { background: var(--sonarr-color); }
.disk-bar { background: var(--lidarr-color); }

/* qBittorrent Panel Details */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vpn-badge {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 12px;
  transition: var(--transition-smooth);
}

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

.badge-inactive {
  background: rgba(239, 68, 68, 0.15);
  color: var(--status-offline);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.qbt-speeds {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.speed-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 10px;
  border-radius: var(--radius-md);
}

.speed-arrow {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: bold;
}

.speed-arrow.down { color: var(--sonarr-color); }
.speed-arrow.up { color: var(--lidarr-color); }

.speed-detail {
  display: flex;
  flex-direction: column;
}

.speed-val {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
}

.speed-lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.qbt-torrent-stats {
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.qbt-torrent-stats .stat-box {
  padding: 10px 6px;
}

.qbt-torrent-stats .stat-value {
  font-size: 1.2rem;
}

/* Pipeline overview (Bazarr/Prowlarr) */
.pipeline-item {
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: var(--transition-smooth);
}

.pipeline-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

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

.pipeline-title {
  font-size: 0.8rem;
  font-weight: 600;
}

.pipeline-val {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--sonarr-color);
}

.pipeline-details {
  font-size: 0.725rem;
  color: var(--text-muted);
}

.pipeline-details.issue-warn {
  color: #fca5a5;
}

/* Recently Added list */
.recent-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  transition: var(--transition-smooth);
}

.recent-item:hover {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.06);
}

.recent-title {
  font-weight: 500;
  max-width: 230px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-date {
  font-size: 0.7rem;
  color: var(--text-dimmed);
}

.empty-list {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dimmed);
  padding: 12px;
}

/* Sync loading animation */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading .btn-icon {
  animation: spin 1.2s linear infinite;
}

.app-card.card-offline {
  opacity: 0.65;
}

.active-glow {
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.4);
}

/* Footer styling */
.app-footer {
  margin-top: 40px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dimmed);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 20px;
}
