@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ============================================
   ROOT VARIABLES - Theme System
   ============================================ */
:root[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --accent: #3b82f6;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.08);
  --border-dark: rgba(255, 255, 255, 0.12);
  --accent: #60a5fa;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  /* Prevent zoom on mobile */
  touch-action: pan-x pan-y;
}

/* Prevent iOS text size adjustment */
body {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ============================================
   NAVBAR - Mobile First Design
   ============================================ */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
  /* Safe area for iPhone notch */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.navbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 64px;
}

.navbar-brand {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}

.nav-right-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

/* Desktop Navigation */
.desktop-nav {
  display: none;
  gap: 6px;
  align-items: center;
}

.nav-link {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  text-decoration: none;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
}

/* Dropdown Styles */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}

.dropdown-toggle:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
}

.dropdown-arrow {
  font-size: 10px;
  transition: transform 0.3s ease;
}

.dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 1000;
  overflow: hidden;
}

.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
  display: block;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: rgba(59, 130, 246, 0.08);
  color: var(--accent);
  padding-left: 20px;
}

/* Mobile Menu Button - Always 44x44px minimum */
.mobile-menu-btn {
  display: flex;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 22px;
  flex-shrink: 0;
  padding: 0;
  color: var(--text);
}

.mobile-menu-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  border-color: var(--accent);
}

.mobile-menu-btn:active {
  transform: scale(0.95);
}

/* Theme Toggle - Always 44x44px minimum */
.theme-toggle {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 22px;
  transition: all 0.3s ease;
  flex-shrink: 0;
  color: var(--text);
}

.theme-toggle:hover {
  transform: scale(1.08);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* Mobile Dropdown Menu */
.mobile-dropdown {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9999;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.mobile-dropdown.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}

.mobile-dropdown-content {
  background: var(--surface);
  border-radius: 20px;
  width: calc(100% - 32px);
  max-width: 400px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.mobile-dropdown-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.mobile-dropdown-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.mobile-close-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(59, 130, 246, 0.1);
  border: none;
  color: var(--text);
  font-size: 28px;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
}

.mobile-close-btn:hover {
  background: var(--danger);
  color: white;
}

.mobile-close-btn:active {
  transform: scale(0.9);
}

.mobile-dropdown-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.mobile-dropdown-section:last-child {
  border-bottom: none;
  padding-bottom: 24px;
}

.mobile-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.mobile-nav-link {
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 500;
  border-radius: 10px;
  transition: all 0.2s ease;
  margin-bottom: 8px;
  min-height: 52px;
}

.mobile-nav-link:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
  transform: translateX(4px);
}

.mobile-nav-link:active {
  background: rgba(59, 130, 246, 0.15);
  transform: scale(0.98);
}

/* ============================================
   MAIN CONTENT - Responsive Container
   ============================================ */
main {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
}

/* ============================================
   CARD - Optimized for Mobile First
   ============================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--card-shadow);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

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

.section-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
  line-height: 1.3;
}

.card > div > p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

/* ============================================
   CHART CONTAINER - Responsive Height
   ============================================ */
.chart-wrapper-container {
  position: relative;
  width: 100%;
  height: 350px;
  margin-top: 16px;
  touch-action: pan-x pan-y;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ============================================
   BADGES - Inside Card with Icons
   ============================================ */
.chart-endpoint {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 30;
  pointer-events: auto;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.chart-endpoint:active {
  transform: scale(0.95);
}

.chart-endpoint.highlighted {
  transform: scale(1.12);
  z-index: 35;
}

.chart-endpoint.dimmed {
  opacity: 0.3;
  filter: grayscale(0.5);
}

/* Icon with Image */
.chart-endpoint-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  position: relative;
}

.chart-endpoint-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chart-endpoint:hover .chart-endpoint-icon {
  transform: scale(1.15);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

/* Value Box */
.chart-endpoint-value {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 10px;
  background: var(--surface);
  border: 2px solid;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: all 0.3s ease;
  line-height: 1;
}

[data-theme="light"] .chart-endpoint-value {
  color: var(--text);
  background: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .chart-endpoint-value {
  color: var(--text);
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(8px);
}

.chart-endpoint:hover .chart-endpoint-value {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* ============================================
   BADGE - Info Style
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  gap: 6px;
}

.badge-info {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent);
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* Small Mobile - 360px */
@media (max-width: 360px) {
  html {
    font-size: 14px;
  }

  .navbar-inner {
    padding: 10px 12px;
    gap: 10px;
    min-height: 60px;
  }

  .navbar-brand {
    font-size: 17px;
  }

  .mobile-menu-btn,
  .theme-toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
  }

  main {
    margin: 16px auto;
    padding: 0 12px;
  }

  .card {
    padding: 16px;
    border-radius: 14px;
  }

  .section-title {
    font-size: 18px;
  }

  .chart-wrapper-container {
    height: 280px;
  }

  .chart-endpoint-icon {
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
  }

  .chart-endpoint-value {
    font-size: 12px;
    padding: 6px 10px;
  }

  .badge {
    font-size: 11px;
    padding: 6px 10px;
  }
}

/* Mobile - 480px */
@media (min-width: 361px) and (max-width: 480px) {
  .navbar-brand {
    font-size: 18px;
  }

  .chart-wrapper-container {
    height: 320px;
  }

  .chart-endpoint-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  .chart-endpoint-value {
    font-size: 13px;
    padding: 7px 12px;
  }
}

/* Tablet Portrait - 768px */
@media (min-width: 481px) and (max-width: 768px) {
  main {
    margin: 28px auto;
    padding: 0 20px;
  }

  .card {
    padding: 24px;
  }

  .chart-wrapper-container {
    height: 400px;
  }

  .section-title {
    font-size: 24px;
  }
}

/* Tablet Landscape & Small Desktop - 1024px */
@media (min-width: 769px) {
  .desktop-nav {
    display: flex;
  }

  .mobile-menu-btn {
    display: none;
  }

  main {
    margin: 32px auto;
    padding: 0 24px;
  }

  .card {
    padding: 28px;
  }

  .chart-wrapper-container {
    height: 450px;
  }

  .navbar-inner {
    padding: 14px 24px;
  }

  .chart-endpoint-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
  }

  .chart-endpoint-value {
    font-size: 15px;
    padding: 9px 16px;
  }
}

/* Desktop - 1280px */
@media (min-width: 1025px) {
  .chart-wrapper-container {
    height: 500px;
  }

  .section-title {
    font-size: 26px;
  }
}

/* Large Desktop - 1920px */
@media (min-width: 1441px) {
  main {
    max-width: 1400px;
    padding: 0 32px;
  }

  .card {
    padding: 32px;
  }

  .chart-wrapper-container {
    height: 550px;
  }
}

/* ============================================
   LANDSCAPE MODE OPTIMIZATIONS
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
  .navbar-inner {
    min-height: 56px;
    padding: 8px 16px;
  }

  .chart-wrapper-container {
    height: 300px;
  }

  .mobile-dropdown.active {
    padding-top: 60px;
  }
}

/* ============================================
   ACCESSIBILITY & UTILITIES
   ============================================ */

/* Focus Indicators */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print Styles */
@media print {
  .navbar,
  .mobile-dropdown,
  .theme-toggle,
  .mobile-menu-btn {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .card {
    box-shadow: none;
    border: 1px solid #000;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .card {
    border-width: 2px;
  }

  .chart-endpoint-icon {
    border-width: 3px;
  }

  .chart-endpoint-value {
    border-width: 3px;
  }
}