:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a3140;
  --text: #e8ecf4;
  --muted: #9aa3b5;
  --accent: #5b8cff;
  --danger: #ff6b7a;
  --good: #3ecf8e;
  --topbar-h: auto;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

/* Author display rules must not override the hidden attribute. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 12px 16px;
  gap: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px 20px;
  flex: 0 0 auto;
  min-width: 0;
}

.brand {
  min-width: 0;
  overflow: hidden;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: normal;
}

.brand h1 a {
  color: var(--accent);
  text-decoration: none;
}

.brand h1 a:hover {
  text-decoration: underline;
}

.status-block {
  margin-top: 6px;
  min-width: 0;
}

.status-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.status-line-2 {
  margin-top: 2px;
  opacity: 0.92;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: max-content;
  max-width: min(760px, 62vw);
}

.mode-switch {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.options-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 10px;
  flex-wrap: wrap;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  max-width: 480px;
}

.login-panel label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-panel input[type="email"],
.login-panel input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c0e13;
  color: var(--text);
}

.row {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.hint {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.error {
  color: var(--danger);
  margin-top: 12px;
}

button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

.pause-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.device-list {
  display: grid;
  gap: 8px;
}

.device-list button {
  width: 100%;
  text-align: left;
  background: #10131a;
  border: 1px solid var(--border);
}

#loginView,
#deviceView {
  flex: 0 0 auto;
}

.stream-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

#timelineView {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 12px;
  padding-bottom: 4px;
}

.chart-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 8px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.chart-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.chart {
  width: 100%;
  min-height: 180px;
}

.chart-sm {
  min-height: 140px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.chart-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 1200px) {
  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .chart-grid,
  .chart-grid.two {
    grid-template-columns: 1fr;
  }

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

  .top-actions {
    width: 100%;
    max-width: none;
    align-items: stretch;
  }

  .mode-switch {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .options-row {
    justify-content: flex-start;
  }
}

.uplot {
  font-family: inherit;
}

.u-legend {
  font-size: 11px;
}

.mode-btn {
  background: #12161f;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.viz-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.viz-host {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #07090e;
}

.viz-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.clock-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clock-bar input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
}

.clock-label {
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 72px;
}

.clock-now {
  padding: 5px 8px;
  font-size: 0.75rem;
}

#fullscreenBtn {
  padding: 6px 10px;
  font-size: 0.78rem;
}

/* Browser fullscreen already has its own chrome; hide our Electron-style ×. */
html.platform-web .fs-exit-wrap,
body.platform-web .fs-exit-wrap {
  display: none !important;
}

.fs-exit-wrap {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: 140px;
  height: 56px;
  pointer-events: none;
}

body.is-fullscreen .fs-exit-wrap {
  pointer-events: auto;
}

.fs-exit-hotzone {
  position: absolute;
  inset: 0;
}

.fs-exit {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -110%);
  width: 44px;
  height: 36px;
  border-radius: 0 0 10px 10px;
  border: 1px solid var(--border);
  border-top: 0;
  background: rgba(18, 22, 31, 0.94);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  padding: 8px 12px;
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

/* Reveal only when the cursor is in the top-middle hotzone (or on the button). */
body.is-fullscreen .fs-exit-wrap:hover .fs-exit {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

body.is-fullscreen {
  padding: 10px 12px;
}

body.is-fullscreen .topbar {
  opacity: 0.92;
}
