/**
 * PASCO BLE Examples - Common Styles
 * Responsive full-width layout that works on desktop, tablet, and mobile
 */

/* Reset and Base */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 20px;
  background: #f5f5f5;
  min-height: 100vh;
  line-height: 1.5;
}

/* Semantic HTML elements */
main.container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

header {
  margin-bottom: 20px;
}

footer.card {
  margin-top: 20px;
}

aside[role="alert"] {
  margin-top: 10px;
}

/* Accessibility helpers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #1976d2;
  color: white;
  padding: 8px 16px;
  z-index: 100;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  font-weight: 500;
}

.skip-link:focus {
  top: 0;
}

/* Focus indicators for keyboard navigation */
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid #1976d2;
  outline-offset: 2px;
}

input[type="range"]:focus-visible {
  outline-offset: 4px;
}

input[type="color"]:focus-visible {
  outline-offset: 2px;
}

/* Fieldset and Legend */
fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

fieldset.control-group {
  margin-bottom: 15px;
}

legend {
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
  display: block;
}

/* Typography */
h1 {
  color: #333;
  text-align: center;
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 20px;
}

h2 {
  color: #555;
  margin-top: 0;
  font-size: 1.1rem;
}

h3 {
  color: #555;
  margin-top: 0;
}

/* Output element */
output {
  display: inline-block;
}

/* Definition lists */
dl {
  margin: 0;
}

dl.current-values,
dl.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}

dt {
  font-weight: 500;
  color: #666;
}

dd {
  margin: 0;
}

/* Figure and Figcaption */
figure {
  margin: 0;
}

figure.reading {
  text-align: center;
  padding: 20px;
}

figure.reading figcaption {
  font-size: 14px;
  color: #666;
  margin-top: 5px;
}

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

/* Cards */
.card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Status Indicators */
.status {
  padding: 12px;
  border-radius: 4px;
  margin-bottom: 15px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}

.status.disconnected {
  background: #ffebee;
  color: #c62828;
}

.status.connecting {
  background: #fff3e0;
  color: #e65100;
}

.status.connected {
  background: #e8f5e9;
  color: #2e7d32;
}

/* Connection Quality Indicator */
.connection-quality {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 13px;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
}

.quality-label {
  color: #666;
}

.quality-value {
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

.quality-unit {
  color: #888;
  font-size: 12px;
}

.quality-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #bdbdbd;
  margin-left: 4px;
  transition: background-color 0.3s ease;
}

.quality-indicator.quality-good {
  background: #4caf50;
  box-shadow: 0 0 4px rgba(76, 175, 80, 0.5);
}

.quality-indicator.quality-fair {
  background: #ff9800;
  box-shadow: 0 0 4px rgba(255, 152, 0, 0.5);
}

.quality-indicator.quality-poor {
  background: #f44336;
  box-shadow: 0 0 4px rgba(244, 67, 54, 0.5);
}

/* Buttons */
button {
  padding: 10px 20px;
  font-size: 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin: 5px;
  touch-action: manipulation;
  transition: background-color 0.2s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #1976d2;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #1565c0;
}

.btn-danger {
  background: #d32f2f;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #c62828;
}

.btn-success {
  background: #4caf50;
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #43a047;
}

.btn-secondary {
  background: #757575;
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background: #616161;
}

.btn-icon {
  background: #4caf50;
  color: white;
}

.btn-icon:hover:not(:disabled) {
  background: #43a047;
}

/* Button Layouts */
.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.button-row button {
  flex: 1;
  min-width: 120px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 10px;
}

/* Form Controls */
.control-group {
  margin-bottom: 15px;
}

.control-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #555;
}

.control-group input,
.control-group select {
  padding: 10px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 4px;
  min-width: 150px;
  width: 100%;
  max-width: 300px;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.slider-group input[type="range"] {
  flex: 1;
  min-width: 100px;
}

.slider-value {
  min-width: 60px;
  text-align: right;
  font-weight: bold;
}

.text-input {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.text-input input[type="text"] {
  flex: 1;
  min-width: 150px;
  padding: 10px;
  font-size: 16px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.color-picker {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.color-picker input[type="color"] {
  width: 60px;
  height: 44px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.input-group {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.input-group input[type="number"] {
  width: 100px;
  padding: 10px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.input-group select {
  padding: 10px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

/* Grid Layouts */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.content-grid > .card {
  margin-bottom: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.axis-config {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

/* Data Display */
.measurement-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
  gap: 10px;
}

.measurement-row:last-child {
  border-bottom: none;
}

.measurement-name {
  color: #666;
}

.measurement-value {
  font-weight: bold;
  color: #333;
  text-align: right;
}

.current-values {
  display: flex;
  justify-content: space-around;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 4px;
  margin-top: 15px;
  flex-wrap: wrap;
  gap: 15px;
}

.value-display {
  text-align: center;
  flex: 1;
  min-width: 80px;
}

.value-display .label {
  font-size: 12px;
  color: #666;
}

.value-display .value {
  font-size: clamp(18px, 4vw, 24px);
  font-weight: bold;
  color: #1976d2;
}

.value-display .unit {
  font-size: 14px;
  color: #888;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 15px;
}

.stat-box {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 4px;
  text-align: center;
}

.stat-box .label {
  font-size: 11px;
  color: #666;
}

.stat-box .value {
  font-size: 14px;
  font-weight: bold;
  color: #333;
}

.data-count {
  font-size: 12px;
  color: #666;
  margin-left: auto;
}

/* Charts */
.chart-container {
  position: relative;
  width: 100%;
  height: 400px;
}

/* Messages */
.error {
  background: #ffebee;
  color: #c62828;
  padding: 12px;
  border-radius: 4px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.error-message {
  flex: 1;
}

.error-close {
  background: transparent;
  border: none;
  color: #c62828;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  margin: 0;
  opacity: 0.7;
  flex-shrink: 0;
}

.error-close:hover {
  opacity: 1;
}

/* Browser compatibility warning */
.browser-warning {
  background: #fff3e0;
  color: #e65100;
  padding: 16px;
  border-radius: 4px;
  border-left: 4px solid #f57c00;
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.5;
}

.browser-warning a {
  color: #e65100;
  font-weight: 500;
}

.browser-warning a:hover {
  text-decoration: none;
}

.info {
  background: #e3f2fd;
  color: #1565c0;
  padding: 12px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
}

/* Keyboard shortcut styling */
kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 12px;
  color: #333;
  background: #f7f7f7;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.shortcuts-help {
  font-size: 13px;
  margin-top: 15px;
}

.shortcuts-help summary {
  cursor: pointer;
  color: #666;
  font-weight: 500;
  padding: 8px 0;
  user-select: none;
}

.shortcuts-help summary:hover {
  color: #1976d2;
}

.shortcuts-help ul {
  list-style: none;
  padding: 0;
  margin: 10px 0 0 0;
}

.shortcuts-help li {
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #eee;
}

.shortcuts-help li:last-child {
  border-bottom: none;
}

.log,
pre.log {
  background: #263238;
  color: #aed581;
  padding: 15px;
  border-radius: 4px;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: auto;
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.log-entry {
  margin: 2px 0;
  display: block;
}

/* Big Value Reading Display */
.reading {
  text-align: center;
  padding: 30px;
}

.reading .value {
  font-size: clamp(48px, 12vw, 72px);
  font-weight: bold;
  color: #1976d2;
}

.reading .unit {
  font-size: clamp(18px, 4vw, 24px);
  color: #666;
}

.reading .label {
  font-size: 14px;
  color: #999;
  margin-top: 10px;
}

/* Utility */
.sample-rate-display {
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-top: 5px;
}

/* Multi-Sensor Specific */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.sensor-card {
  background: white;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sensor-card h3 {
  margin: 0 0 10px 0;
  color: #333;
  font-size: 16px;
}

.id-filter {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.id-filter label {
  font-size: 14px;
  color: #666;
}

.id-filter input {
  width: 80px;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.sensor-reading {
  text-align: center;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 4px;
  margin-top: 10px;
}

.sensor-reading .value {
  font-size: clamp(24px, 6vw, 36px);
  font-weight: bold;
  color: #1976d2;
}

.sensor-reading .unit {
  font-size: 16px;
  color: #666;
}

.sensor-reading .label {
  font-size: 12px;
  color: #999;
  margin-top: 5px;
}

.graph-container {
  position: relative;
  height: 400px;
  margin-top: 20px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 15px;
}

.time-display {
  font-size: 14px;
  color: #666;
  margin-left: auto;
}

.measurement-select {
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  min-width: 150px;
  width: 100%;
  max-width: 250px;
}

.color-indicator {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
}

/* Playback Controls */
.playback-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  flex-wrap: wrap;
}

.playback-slider {
  flex: 1;
  min-width: 150px;
}

.playback-time {
  font-size: 12px;
  color: #666;
  min-width: 80px;
  text-align: center;
  font-family: monospace;
}

.playback-speed {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #666;
}

.playback-speed select {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.btn-playback {
  background: #1976d2;
  color: white;
  min-width: 70px;
}

.btn-playback:hover:not(:disabled) {
  background: #1565c0;
}

.btn-playback.playing {
  background: #f57c00;
}

.btn-playback.playing:hover:not(:disabled) {
  background: #ef6c00;
}

/* Reconnect notification */
.reconnect-notice {
  background: #fff3e0;
  color: #e65100;
  padding: 10px 15px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.reconnect-notice .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #e65100;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Sensor-specific button variants */
.btn-connect {
  background: #1976d2;
  color: white;
}

.btn-connect:hover:not(:disabled) {
  background: #1565c0;
}

.btn-disconnect {
  background: #d32f2f;
  color: white;
}

.btn-disconnect:hover:not(:disabled) {
  background: #c62828;
}

.btn-clear {
  background: #757575;
  color: white;
}

.btn-clear:hover:not(:disabled) {
  background: #616161;
}

.btn-start {
  background: #388e3c;
  color: white;
}

.btn-start:hover:not(:disabled) {
  background: #2e7d32;
}

.btn-stop {
  background: #f57c00;
  color: white;
}

.btn-stop:hover:not(:disabled) {
  background: #ef6c00;
}

/* Touch Target Sizing - WCAG 2.5.5 (44x44px minimum) */
@media (pointer: coarse) {
  button {
    min-height: 44px;
    min-width: 44px;
  }

  input[type="range"] {
    min-height: 44px;
  }

  input[type="color"] {
    min-height: 44px;
    min-width: 44px;
  }

  select {
    min-height: 44px;
  }

  input[type="text"],
  input[type="number"] {
    min-height: 44px;
  }

  .error-close {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Tablet Responsive (768px) */
@media (max-width: 768px) {
  body {
    padding: 15px;
  }

  .card {
    padding: 15px;
  }

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

  .chart-container {
    height: 300px;
  }

  .graph-container {
    height: 300px;
  }

  .button-row {
    justify-content: center;
  }

  .data-count {
    width: 100%;
    text-align: center;
    margin-left: 0;
  }

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

  .controls {
    justify-content: center;
  }

  .time-display {
    width: 100%;
    text-align: center;
    margin-left: 0;
  }
}

/* Mobile Responsive (480px) */
@media (max-width: 480px) {
  body {
    padding: 10px;
  }

  .card {
    padding: 12px;
    border-radius: 6px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .button-row {
    flex-direction: column;
  }

  .button-row button {
    width: 100%;
    min-width: auto;
    margin: 5px 0;
  }

  .control-group input,
  .control-group select {
    max-width: none;
  }

  .slider-group {
    flex-direction: column;
    align-items: stretch;
  }

  .slider-group span:first-child {
    min-width: auto;
  }

  .slider-value {
    text-align: left;
  }

  .color-picker {
    flex-direction: column;
    align-items: stretch;
  }

  .color-picker input[type="color"] {
    width: 100%;
  }

  .text-input {
    flex-direction: column;
  }

  .text-input input[type="text"] {
    width: 100%;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-container {
    height: 250px;
  }

  .graph-container {
    height: 250px;
  }

  .sensor-card {
    padding: 12px;
  }

  .sensor-card button {
    width: 100%;
    margin-right: 0;
  }

  .id-filter {
    flex-direction: column;
    align-items: stretch;
  }

  .id-filter input {
    width: 100%;
  }

  .measurement-select {
    max-width: none;
  }

  .input-group {
    flex-direction: column;
    align-items: stretch;
  }

  .input-group input[type="number"],
  .input-group select,
  .input-group button {
    width: 100%;
  }
}
