:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #3b82f6;
  --blue-hover: #2563eb;
  --green: #10b981;
  --red: #ef4444;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font: inherit;
  transition: all 0.2s ease;
}

.shell {
  display: flex;
  width: min(1280px, calc(100% - 28px));
  min-height: 100dvh;
  flex-direction: column;
  gap: 12px;
  margin: 0 auto;
  padding: 16px 0;
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow, h1, h2, p { margin: 0; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(1.4rem, 2.2vw, 2rem);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.status, .panel-meta span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: 6px 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.status.connected {
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--green);
  background: rgba(16, 185, 129, 0.05);
}

.status.disconnected {
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--red);
  background: rgba(239, 68, 68, 0.05);
}

.toolbar {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) auto;
  gap: 12px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

button {
  min-height: 42px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: #ffffff;
  padding: 8px 16px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.secondary {
  border-color: var(--line);
  background: #ffffff;
  color: var(--text);
}

button:disabled { cursor: wait; opacity: 0.7; }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); }

button:not(.secondary):hover { background: var(--blue-hover); border-color: var(--blue-hover); }
button.secondary:hover { background: #f8fafc; border-color: #cbd5e1; }

.panel-meta {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
}

#modeBadge {
  border-color: rgba(59, 130, 246, 0.3);
  color: var(--blue);
  background: rgba(59, 130, 246, 0.05);
}

.chart-panel {
  display: flex;
  min-height: 400px;
  flex: 1 1 auto;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 16px;
  box-shadow: var(--shadow);
}

.chart-header {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.chart-header h2 { margin-bottom: 4px; font-size: 1.1rem; font-weight: 800; }
.chart-header p { color: var(--muted); font-size: 0.9rem; }
.chart-header strong {
  max-width: 48%;
  color: var(--text);
  font-size: clamp(1rem, 1.5vw, 1.4rem);
  line-height: 1.2;
  text-align: right;
  overflow-wrap: anywhere;
}

.chart-wrapper {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  height: clamp(340px, 58dvh, 620px);
  min-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  overflow: hidden;
}

.chart-scroll {
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
  overscroll-behavior-x: contain;
  scrollbar-color: #cbd5e1 transparent;
  scrollbar-width: thin;
  touch-action: pan-x pinch-zoom;
  -webkit-overflow-scrolling: touch;
}

.chart-scroll.dragging { cursor: grabbing; user-select: none; }

.chart-canvas-track {
  position: relative;
  height: 100%;
  min-width: 100%;
  padding: 8px;
  touch-action: pan-x pinch-zoom;
}

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

/* Glassmorphism Tooltip */
.chart-tooltip {
  position: absolute;
  z-index: 3;
  display: grid;
  width: 180px;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
  padding: 12px;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.3;
  pointer-events: none;
  transition: opacity 0.2s, top 0.1s, left 0.1s;
}

.chart-tooltip strong { margin-bottom: 4px; color: var(--text); font-size: 0.82rem; display: block; border-bottom: 1px solid rgba(0,0,0,0.05); padding-bottom: 4px; }
.chart-tooltip span { font-weight: 700; display: flex; justify-content: space-between; }

/* Zoom Controls Overlay */
.zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.9);
  padding: 6px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
}

.zoom-controls button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.82rem;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 6px;
  box-shadow: none;
}

.zoom-controls button:hover { background: rgba(0,0,0,0.05); transform: none; }
.zoom-controls button:active { background: rgba(0,0,0,0.1); }
#zoomResetBtn { font-weight: 800; min-width: 54px; letter-spacing: -0.5px; }

@media (max-width: 820px) {
  .shell { width: min(100% - 16px, 1280px); gap: 10px; padding: 12px 0; }
  .topbar { align-items: flex-start; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .actions { grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  button { padding-right: 8px; padding-left: 8px; font-size: 0.88rem; }
  .chart-header { align-items: flex-start; }
  .chart-header p { display: none; }
  .chart-header strong { max-width: 52%; font-size: 1rem; }
  .chart-wrapper { height: 58dvh; min-height: 350px; }
  .zoom-controls { bottom: 10px; right: 10px; padding: 4px; }
  .zoom-controls button { padding: 4px 8px; min-height: 28px; }
}

@media (max-width: 520px) {
  .topbar { gap: 8px; }
  h1 { font-size: 1.15rem; }
  .status { min-height: 30px; padding: 5px 12px; font-size: 0.8rem; }
  label { font-size: 0.8rem; }
  input, button { min-height: 38px; }
  .chart-panel { padding: 12px; min-height: 420px; }
  .chart-wrapper { height: 52dvh; min-height: 340px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .shell { gap: 8px; padding: 8px 0; }
  .eyebrow, .chart-header p, .panel-meta { display: none; }
  h1 { font-size: 1.1rem; }
  .toolbar { grid-template-columns: 1fr 1fr auto; gap: 8px; padding: 8px; }
  input, button { min-height: 34px; }
  .actions { display: flex; gap: 8px; }
  .chart-panel { padding: 8px; min-height: 300px; }
  .chart-wrapper { height: 260px; min-height: 240px; }
  .chart-header { margin-bottom: 6px; }
  .chart-header h2 { font-size: 1rem; }
}
