/* General Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Mobile-First Body Styles */
body {
  background-color: #121212;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #e0e0e0;
  line-height: 1.5;
  padding: 0 4vw;
  min-height: 100vh;
}

/* Mobile Dashboard Layout */
.dashboard {
  background-color: #1b1b1b;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
  width: 100%;
  margin: 1rem auto;
  transition: transform 0.25s ease-in-out;
}

/* Mobile Vital Box - Horizontal layout for professional look */
.vital-box {
  background-color: none;
  display: flex;
  flex-direction: row;
  padding: 0;
  align-items: stretch;
  gap: 1rem;
  width: 100%;
}

/* Mobile Vital Info - Left side */
.vital-info {
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  width: 30%;
  min-height: 160px;
  background-color: #00000079;
  justify-content: space-between;
  padding: 1rem;
  order: 1;
}

/* Mobile Chart Wrapper - Right side */
.chart-wrapper {
  position: relative;
  font-family: Arial, Helvetica, sans-serif;
  width: 70%;
  height: 160px;
  overflow: hidden;
  order: 2;
}

/* Mobile Vital Header */
.vital-header {
  font-size: 0.9rem;
  color: #ffffff;
  margin-bottom: 0.5rem;
}

/* Mobile Vital Value */
.vital-value {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.vital-labelrr {
  font-size: 0.7rem;
  color: #aaa;
}

.vital-valuerr {
  font-size: 0.5rem;
  font-weight: bold;
}

/* Mobile Graph Name */
.graph-name, 
.vital-graph-label {
  font-size: 0.75rem;
  color: #888;
  margin-top: auto;
}

/* Mobile Canvas Graph */
canvas {
  display: flex;
  width: 100% !important;
  height: 160px !important;
  background-color: #121212;
  border-radius: 12px;
}

/* Unique Value Colors */
.green { color: Green; }
.yellow { color: #E6B800; }
.red { color: red; }
.orange { color: orange; }

/* Mobile ETCO2 Specific Styles */
.vital-header-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.vital-label-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.vital-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #aaa;
  margin-bottom: 0.125rem;
}

/* Mobile Sweep Bar - PRESERVED ANIMATION */
.sweep-bar {
  position: absolute;
  top: 0;
  left: -10%;
  width: 1.25%;
  height: 100%;
  background-color: #121212;
  animation: sweepGap 5s linear infinite;
  animation-delay: 5s;
  z-index: 2;
  pointer-events: none;
}

/* Mobile Reveal Bar - PRESERVED ANIMATION */
.reveal-bar {
  position: absolute;
  top: 0;
  left: 100%;
  width: 100%;
  height: 100%;
  background-color: #121212;
  animation: revealGraph 5s ease-out forwards;
  animation-delay: 0s;
  z-index: 3;
  pointer-events: none;
}

/* Mobile ETCO2-specific Animations - PRESERVED */
.sweep-bar-etco2 {
  position: absolute;
  top: 0;
  left: -10%;
  width: 1.25%;
  height: 100%;
  background-color: #121212;
  animation: sweepETCO2 10s linear infinite;
  animation-delay: 10s;
  z-index: 2;
  pointer-events: none;
}

.reveal-bar-etco2 {
  position: absolute;
  top: 0;
  left: 100%;
  width: 100%;
  height: 100%;
  background-color: #121212;
  animation: revealETCO2 10s ease-out forwards;
  animation-delay: 0s;
  z-index: 3;
  pointer-events: none;
}

/* Sweep animation - PRESERVED */
@keyframes sweepGap {
  0% {
    left: -10%;
  }
  100% {
    left: 100%;
  }
}

/* Reveal animation - PRESERVED */
@keyframes revealGraph {
  from {
    left: 0%;
  }
  to {
    left: 100%;
  }
}

/* ETCO2 Sweep animation - PRESERVED */
@keyframes sweepETCO2 {
  0% {
    left: 0%;
  }
  100% {
    left: 100%;
  }
}

/* ETCO2 Reveal animation - PRESERVED */
@keyframes revealETCO2 {
  from {
    left: 0%;
  }
  to {
    left: 100%;
  }
}

/* Mobile Button Container */
.button-container {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
  margin-bottom: 3rem;
  width: 100%;
}

/* Mobile Button Styles */
.left-button,
.right-button {
  padding: 1rem 2rem;
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 280px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile Button Colors */
.left-button {
  background-color: #388e3c;
}

.right-button {
  background-color: #7b1fa2;
}

/* Mobile Hover Effects */
.left-button:hover {
  background-color: #2e7d32;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.right-button:hover {
  background-color: #6a1b9a;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

/* Mobile Popup Overlay */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(10, 10, 10, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  padding: 1rem;
}

.popup-content {
  background: linear-gradient(135deg, #121212, #1e1e1e);
  padding: 1.5rem;
  border-radius: 16px;
  text-align: center;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 0 0.1px black;
  color: #f0f0f0;
  font-family: 'Segoe UI', sans-serif;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Heartbeat animation only when hovered - PRESERVED */
.popup-content:hover {
  animation: heartbeat 0.75s 1;
}

@keyframes heartbeat {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0.1px black;
  }
  50% {
    transform: scale(1.03);
    box-shadow: 0 0 0.2px black;
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0.4px black;
  }
}

/* Mobile Size Controls */
.size-controls {
  margin: 1.5rem 0;
}

.size-controls button {
  font-size: 1.2rem;
  margin: 0 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 10px;
  background: #00e676;
  color: #111;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.3s ease;
  min-height: 44px;
}

.size-controls button:hover {
  transform: scale(1.1);
  background: #00c853;
}

.close-popup {
  margin-top: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: #2c2c2c;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.3s ease;
  width: 100%;
  min-height: 44px;
}

.close-popup:hover {
  background: #444;
}

/* Mobile Graph Toggle Buttons */
.toggle-graph-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.toggle-btn {
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
  background-color: #388e3c;
  min-height: 44px;
  width: 100%;
}

.toggle-btn:hover {
  transform: scale(1.05);
}

/* Mobile Floating Zoom Controls */
.floating-zoom-controls {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
}

.floating-zoom-controls button {
  background: linear-gradient(145deg, #1c1c1c, #2a2a2a);
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 10px;
  font-size: 1.125rem;
  font-weight: 600;
  width: 44px;
  height: 44px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6),
              inset 0 1px 2px rgba(255, 255, 255, 0.1);
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.floating-zoom-controls button:hover {
  background: linear-gradient(145deg, #2e2e2e, #3a3a3a);
  color: #F90618;
  transform: scale(1.08);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.7),
              inset 0 1px 3px rgba(255, 255, 255, 0.1);
}

.floating-zoom-controls button:active {
  transform: scale(0.92);
  background: linear-gradient(145deg, #1a1a1a, #242424);
  color: #2E3192;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.8),
              inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* Hide element */
.hidden {
  display: none;
}

/* ==========================================================
   SMALL MOBILE OPTIMIZATIONS (≤480px)
   ========================================================== */
@media (max-width: 480px) {
  body {
    padding: 0 3vw;
  }
  
  .dashboard {
    padding: 1.25rem 0.75rem;
    border-radius: 14px;
    gap: 1.25rem;
  }
  
  .vital-box {
    gap: 0.75rem;
  }
  
  .vital-info {
    width: 35%;
    min-height: 140px;
    padding: 0.75rem;
  }
  
  .chart-wrapper {
    width: 65%;
    height: 140px;
  }
  
  canvas {
    height: 140px !important;
  }
  
  .vital-header {
    font-size: 0.85rem;
  }
  
  .vital-value {
    font-size: 1.3rem;
  }
  
  .vital-labelrr {
    font-size: 0.65rem;
  }
  
  .graph-name,
  .vital-graph-label {
    font-size: 0.7rem;
  }
  
  .vital-label {
    font-size: 0.6rem;
  }
  
  .button-container {
    margin-top: 1.5rem;
    margin-bottom: 2rem;
    gap: 0.75rem;
  }
  
  .left-button,
  .right-button {
    padding: 0.9rem 1.5rem;
    font-size: 0.9rem;
    max-width: 260px;
    min-height: 44px;
  }
  
  .popup-content {
    padding: 1.25rem;
    max-width: 280px;
  }
  
  .size-controls button {
    font-size: 1.1rem;
    padding: 0.6rem 1.25rem;
    min-height: 40px;
  }
  
  .toggle-btn {
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    min-height: 40px;
  }
  
  .floating-zoom-controls {
    bottom: 0.75rem;
    right: 0.75rem;
  }
  
  .floating-zoom-controls button {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
}

/* ==========================================================
   VERY SMALL MOBILE OPTIMIZATIONS (≤360px)
   ========================================================== */
@media (max-width: 360px) {
  body {
    padding: 0 2vw;
  }
  
  .dashboard {
    padding: 1rem 0.5rem;
    border-radius: 12px;
    gap: 1rem;
  }
  
  .vital-box {
    gap: 0.5rem;
  }
  
  .vital-info {
    width: 40%;
    min-height: 120px;
    padding: 0.6rem;
  }
  
  .chart-wrapper {
    width: 60%;
    height: 120px;
  }
  
  canvas {
    height: 120px !important;
  }
  
  .vital-header {
    font-size: 0.8rem;
  }
  
  .vital-value {
    font-size: 1.1rem;
  }
  
  .vital-labelrr {
    font-size: 0.6rem;
  }
  
  .graph-name,
  .vital-graph-label {
    font-size: 0.65rem;
  }
  
  .vital-label {
    font-size: 0.55rem;
  }
  
  .button-container {
    margin-top: 1.25rem;
    margin-bottom: 1.5rem;
  }
  
  .left-button,
  .right-button {
    padding: 0.8rem 1.25rem;
    font-size: 0.85rem;
    max-width: 240px;
    min-height: 42px;
  }
  
  .popup-content {
    padding: 1rem;
    max-width: 260px;
  }
  
  .size-controls button {
    font-size: 1rem;
    padding: 0.5rem 1rem;
    min-height: 38px;
    margin: 0 0.25rem;
  }
  
  .toggle-btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    min-height: 38px;
  }
  
  .floating-zoom-controls {
    bottom: 0.5rem;
    right: 0.5rem;
  }
  
  .floating-zoom-controls button {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
  }
}

/* ==========================================================
   LANDSCAPE ORIENTATION SUPPORT
   ========================================================== */
@media (max-width: 768px) and (orientation: landscape) {
  .dashboard {
    padding: 1rem;
    gap: 1rem;
  }
  
  .vital-box {
    gap: 1rem;
  }
  
  .vital-info {
    width: 25%;
    min-height: 140px;
  }
  
  .chart-wrapper {
    width: 75%;
    height: 140px;
  }
  
  canvas {
    height: 140px !important;
  }
  
  .button-container {
    flex-direction: row;
    gap: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 2rem;
  }
  
  .left-button,
  .right-button {
    width: auto;
    flex: 1;
    max-width: none;
    padding: 0.8rem 1rem;
  }
}

/* ==========================================================
   TABLET OPTIMIZATIONS (769px - 1024px)
   ========================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
  .dashboard {
    max-width: 90%;
    padding: 2rem 1.5rem;
    gap: 2rem;
  }
  
  .vital-info {
    width: 25%;
    min-height: 180px;
    padding: 1.25rem;
  }
  
  .chart-wrapper {
    width: 75%;
    height: 180px;
  }
  
  canvas {
    height: 180px !important;
  }
  
  .vital-header {
    font-size: 1rem;
  }
  
  .vital-value {
    font-size: 1.8rem;
  }
  
  .vital-labelrr {
    font-size: 0.8rem;
  }
  
  .graph-name,
  .vital-graph-label {
    font-size: 0.85rem;
  }
  
  .button-container {
    flex-direction: row;
    gap: 2rem;
  }
  
  .left-button,
  .right-button {
    max-width: 200px;
  }
}

/* ==========================================================
   ACCESSIBILITY & TOUCH OPTIMIZATIONS
   ========================================================== */
@media (hover: none) and (pointer: coarse) {
  .left-button:hover,
  .right-button:hover,
  .toggle-btn:hover,
  .size-controls button:hover,
  .floating-zoom-controls button:hover {
    transform: none;
  }
  
  .left-button:active,
  .right-button:active,
  .toggle-btn:active,
  .size-controls button:active,
  .floating-zoom-controls button:active {
    transform: scale(0.95);
  }
}

/* Reduced motion for accessibility - PRESERVES ANIMATIONS */
@media (prefers-reduced-motion: reduce) {
  .dashboard,
  .popup-content,
  .left-button,
  .right-button,
  .toggle-btn,
  .size-controls button,
  .floating-zoom-controls button {
    transition: none !important;
  }
  
  /* Only remove animations if user prefers reduced motion */
  .sweep-bar,
  .reveal-bar,
  .sweep-bar-etco2,
  .reveal-bar-etco2 {
    animation: none !important;
  }
  
  .popup-content:hover {
    animation: none !important;
  }
}

/* Ensure proper touch targets */
.left-button,
.right-button,
.toggle-btn,
.size-controls button,
.close-popup,
.floating-zoom-controls button {
  min-height: 44px;
}

/* Safe area insets for notched devices */
@supports(padding: max(0px)) {
  body {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  .floating-zoom-controls {
    bottom: max(1rem, env(safe-area-inset-bottom));
    right: max(1rem, env(safe-area-inset-right));
  }
}