:root {
  --bg: #0a0a0a;
  --card: #1a1a1a;
  --accent: #4cafef;
  --accent2: #ff6b6b;
  --accent3: #51cf66;
  --muted: #888;
  --glass: rgba(76, 175, 239, 0.1);
  --border: #333;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
}

.dashboard {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vw, 12px);
  padding: clamp(8px, 1.5vw, 12px);
  overflow: hidden;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--accent), #2196f3);
  padding: clamp(8px, 2vw, 12px) clamp(12px, 3vw, 20px);
  border-radius: clamp(8px, 1.5vw, 12px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  flex-shrink: 0;
  min-height: clamp(50px, 8vh, 80px);
}

.header h1 {
  font-size: clamp(18px, 3vw, 24px);
  font-weight: 600;
}

.controls {
  display: flex;
  gap: clamp(8px, 2vw, 16px);
  align-items: center;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: clamp(4px, 1vw, 8px);
  background: rgba(255,255,255,0.1);
  padding: clamp(4px, 1vw, 8px) clamp(6px, 1.5vw, 12px);
  border-radius: clamp(4px, 1vw, 8px);
  backdrop-filter: blur(10px);
}

.control-group label {
  font-size: clamp(11px, 1.5vw, 14px);
  white-space: nowrap;
}

select, input {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: clamp(4px, 1vw, 6px) clamp(6px, 1.5vw, 10px);
  border-radius: clamp(3px, 0.8vw, 6px);
  font-size: clamp(11px, 1.5vw, 14px);
  min-width: 60px;
}

button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: clamp(6px, 1.2vw, 8px) clamp(10px, 2vw, 16px);
  border-radius: clamp(3px, 0.8vw, 6px);
  cursor: pointer;
  font-weight: 500;
  font-size: clamp(11px, 1.5vw, 14px);
  transition: all 0.3s ease;
}

button:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-1px);
}

/* Main Content Grid */
.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(250px, 0.8fr) 2fr minmax(250px, 0.8fr);
  grid-template-rows: auto 1fr;
  gap: clamp(8px, 1.5vw, 12px);
  overflow: hidden;
  min-height: 0;
}

/* KPI Section */
.kpi-section {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: clamp(6px, 1.2vw, 12px);
  max-height: clamp(80px, 12vh, 120px);
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: clamp(6px, 1.2vw, 12px);
  padding: clamp(8px, 2vw, 16px);
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: clamp(70px, 10vh, 100px);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

.kpi-value {
  font-size: clamp(18px, 4vw, 28px);
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 2px;
  line-height: 1;
}

.kpi-label {
  font-size: clamp(10px, 1.5vw, 12px);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.kpi-change {
  font-size: clamp(9px, 1.3vw, 11px);
}

.positive { color: var(--accent3); }
.negative { color: var(--accent2); }

/* Left Panel - Team Performance */
.team-performance {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: clamp(6px, 1.2vw, 12px);
  padding: clamp(8px, 2vw, 16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-title {
  font-size: clamp(14px, 2.2vw, 16px);
  font-weight: 600;
  margin-bottom: clamp(8px, 1.5vw, 12px);
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: clamp(4px, 1vw, 8px);
  flex-shrink: 0;
}

.person-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.person-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(4px, 1vw, 8px) clamp(6px, 1.5vw, 12px);
  margin: clamp(2px, 0.5vw, 4px) 0;
  background: rgba(255,255,255,0.05);
  border-radius: clamp(4px, 1vw, 8px);
  border-left: 3px solid var(--accent);
  transition: all 0.3s ease;
}

.person-item:hover {
  background: rgba(255,255,255,0.1);
  transform: translateX(4px);
}

.person-name {
  font-weight: 500;
  font-size: clamp(12px, 1.8vw, 14px);
}

.person-smv {
  font-size: clamp(10px, 1.5vw, 12px);
  color: var(--accent);
  font-weight: 600;
}

.person-progress {
  width: 100%;
  height: clamp(2px, 0.5vw, 4px);
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: clamp(2px, 0.5vw, 4px);
  overflow: hidden;
}

.person-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent3));
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* Center Panel - Main Charts */
.main-charts {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: clamp(8px, 1.5vw, 12px);
  overflow: hidden;
  min-height: 0;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: clamp(6px, 1.2vw, 12px);
  padding: clamp(8px, 2vw, 16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chart-container {
  flex: 1;
  position: relative;
  min-height: 0;
  width: 100%;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Right Panel - Analytics */
.analytics-panel {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: clamp(8px, 1.5vw, 12px);
  overflow: hidden;
  min-height: 0;
}

.analytics-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: clamp(6px, 1.2vw, 12px);
  padding: clamp(8px, 2vw, 16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Target Progress Ring */
.target-ring {
  position: relative;
  width: clamp(80px, 15vw, 120px);
  height: clamp(80px, 15vw, 120px);
  margin: 0 auto clamp(8px, 2vw, 16px);
  flex-shrink: 0;
}

.target-progress {
  font-size: clamp(14px, 3vw, 20px);
  font-weight: bold;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
}

.target-info {
  text-align: center;
  font-size: clamp(10px, 1.5vw, 12px);
  color: var(--muted);
  flex-shrink: 0;
}

.target-info div {
  margin: clamp(2px, 0.5vw, 4px) 0;
}

/* Leaderboard */
#leaderboard {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.5vw, 12px);
  padding: clamp(4px, 1vw, 8px);
  margin: clamp(2px, 0.5vw, 4px) 0;
  border-radius: clamp(4px, 1vw, 8px);
  background: rgba(255,255,255,0.05);
}

.rank {
  width: clamp(20px, 3.5vw, 24px);
  height: clamp(20px, 3.5vw, 24px);
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(10px, 1.5vw, 12px);
  font-weight: bold;
  flex-shrink: 0;
}

.rank.gold { background: #ffd700; color: #000; }
.rank.silver { background: #c0c0c0; color: #000; }
.rank.bronze { background: #cd7f32; color: white; }

.leaderboard-name {
  font-weight: 500;
  font-size: clamp(12px, 1.8vw, 14px);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-smv {
  font-size: clamp(10px, 1.5vw, 12px);
  color: var(--muted);
  flex-shrink: 0;
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
  .main-grid {
    grid-template-columns: minmax(220px, 1fr) 2fr minmax(220px, 1fr);
  }
}

@media (max-width: 1024px) {
  .dashboard {
    gap: clamp(6px, 1vw, 8px);
    padding: clamp(6px, 1vw, 8px);
  }
  
  .main-grid {
    grid-template-columns: 1fr 1.5fr 1fr;
  }
  
  .kpi-section {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .header {
    flex-direction: column;
    gap: clamp(6px, 1.5vw, 8px);
    min-height: clamp(70px, 12vh, 100px);
  }
  
  .controls {
    justify-content: center;
    width: 100%;
  }
}

@media (max-width: 768px) {
  .main-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(200px, 1fr) minmax(150px, 0.8fr);
  }
  
  .team-performance {
    grid-row: 2;
    min-height: 200px;
  }
  
  .main-charts {
    grid-row: 2;
    grid-column: 1;
    min-height: 200px;
  }
  
  .analytics-panel {
    grid-row: 3;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
    min-height: 150px;
  }
  
  .kpi-section {
    grid-template-columns: repeat(2, 1fr);
    max-height: clamp(140px, 20vh, 160px);
  }
  
  .kpi-card {
    min-height: clamp(60px, 8vh, 70px);
  }
}

@media (max-width: 600px) {
  .dashboard {
    padding: clamp(4px, 1vw, 6px);
    gap: clamp(4px, 1vw, 6px);
  }
  
  .kpi-section {
    grid-template-columns: 1fr 1fr;
  }
  
  .main-grid {
    grid-template-rows: auto 1fr auto auto;
  }
  
  .analytics-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  
  .controls {
    gap: clamp(4px, 1vw, 6px);
  }
  
  .control-group {
    min-width: auto;
    flex: 1;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .kpi-section {
    grid-template-columns: 1fr;
    max-height: clamp(300px, 35vh, 400px);
  }
  
  .main-grid {
    grid-template-rows: auto minmax(150px, 1fr) minmax(120px, 0.6fr) minmax(120px, 0.6fr);
  }
  
  .analytics-panel {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  
  .header h1 {
    font-size: clamp(16px, 4vw, 20px);
  }
}

/* Height-specific media queries */
@media (max-height: 600px) {
  .kpi-section {
    max-height: clamp(60px, 8vh, 80px);
  }
  
  .kpi-card {
    min-height: clamp(50px, 6vh, 60px);
    padding: clamp(4px, 1vh, 8px);
  }
  
  .kpi-value {
    font-size: clamp(14px, 3vh, 20px);
  }
  
  .target-ring {
    width: clamp(60px, 12vh, 80px);
    height: clamp(60px, 12vh, 80px);
  }
}

@media (max-height: 500px) {
  .dashboard {
    gap: clamp(2px, 0.5vh, 4px);
    padding: clamp(2px, 0.5vh, 4px);
  }
  
  .header {
    min-height: clamp(40px, 8vh, 60px);
    padding: clamp(4px, 1vh, 8px) clamp(8px, 2vh, 12px);
  }
  
  .kpi-section {
    max-height: clamp(50px, 10vh, 70px);
  }
  
  .main-grid {
    gap: clamp(2px, 0.5vh, 4px);
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: clamp(2px, 0.5vw, 4px);
}

::-webkit-scrollbar-track {
  background: var(--card);
}

::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 2px;
}

/* Loading Animation */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(60px, 15vh, 100px);
  color: var(--muted);
  font-size: clamp(12px, 1.8vw, 14px);
}

.spinner {
  width: clamp(16px, 3vw, 20px);
  height: clamp(16px, 3vw, 20px);
  border: 2px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: clamp(4px, 1vw, 8px);
}

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

/* Animation Classes */
.fade-in {
  animation: fadeIn 0.5s ease-in;
}

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

.slide-up {
  animation: slideUp 0.6s ease-out;
}

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

/* Prevent text selection on dashboard elements */
.kpi-card, .panel-title, .rank {
  user-select: none;
}

/* Ensure proper aspect ratio for charts */
.chart-container {
  aspect-ratio: auto;
}

/* Fix for very wide screens */
@media (min-width: 1600px) {
  .dashboard {
    max-width: 1600px;
    margin: 0 auto;
  }
}