:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #d5d9e0;
  --text: #1b1f27;
  --text-muted: #5b6472;
  --accent: #2058c7;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --online: #1a8f4c;
  --offline: #9aa1ab;
  --banner-bg: #fbe4e2;
  --banner-border: #d9534f;
  --banner-text: #7a1f1a;
}

* {
  box-sizing: border-box;
}

/* Any author `display` rule beats the UA's `[hidden] { display: none }`,
   whatever its specificity — so every element this sheet gives a display to
   would ignore the hidden attribute that app.js's show()/hide() set. That
   produced three separate visible bugs (the account bar and Log out button on
   the login page, the Forgot-password card on page load, and the Log in card
   refusing to step aside for it), so state it once, globally, rather than
   remembering a `[hidden]` guard beside every new display rule. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 1.5rem;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

h1 {
  font-size: 1.4rem;
  margin: 0;
}

h2 {
  font-size: 1.1rem;
  margin: 0;
}

#account-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  color: var(--banner-text);
  border-radius: 6px;
}

.banner button {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.auth-forms {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.auth-forms form {
  flex: 1 1 260px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  background: var(--border);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: default;
}

button:disabled:hover {
  filter: none;
}

button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8em;
  height: 1.8em;
  padding: 0;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  line-height: 1;
}

.icon-btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.icon-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.close-btn {
  padding: 0.1rem 0.25rem;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.2rem 0 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.claim-code-panel {
  border: 1px dashed var(--accent);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  text-align: center;
}

.claim-code {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin: 0.4rem 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

th {
  color: var(--text-muted);
  font-weight: 600;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.status-dot {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
}

.status-dot.online {
  background: var(--online);
}

.status-dot.offline {
  background: var(--offline);
}

.name-editor input {
  padding: 0.15rem 0.4rem;
  width: 10rem;
}

.name-display {
  cursor: pointer;
  border-bottom: 1px dotted var(--text-muted);
}

.actions {
  display: flex;
  gap: 0.4rem;
  white-space: nowrap;
}

.control-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.seg {
  display: flex;
  margin-bottom: 0.9rem;
}

.seg button {
  flex: 1;
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.seg button:first-child {
  border-radius: 5px 0 0 5px;
}

.seg button:last-child {
  border-radius: 0 5px 5px 0;
}

.seg button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.seg button.paused-pressed {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.seg button:disabled {
  color: var(--text-muted);
  cursor: default;
  filter: none;
}

.control-block {
  margin-top: 0.75rem;
}

.control-inline-apply {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.control-inline-apply input {
  width: 10rem;
}

/* Each device renders as two table rows — the main cells and a full-width
   telemetry line. The divider moves under the telemetry line so the pair
   reads as one row. */
.device-row td {
  border-bottom: none;
}

.telemetry-row td {
  padding-top: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.live-status {
  font-weight: 600;
}

.live-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.field {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.field label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.field span {
  font-size: 1.3rem;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.history-chart-block {
  margin-bottom: 1.5rem;
}

.history-chart-block:last-child {
  margin-bottom: 0;
}

.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.chart-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.csv-link {
  font-size: 0.85rem;
  white-space: nowrap;
}

.history-canvas {
  display: block;
  width: 100%;
  height: 220px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
}

.chart-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.25rem;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

#restore-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-width: 320px;
  margin-top: 0.75rem;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
}

/* ---- device detail view ------------------------------------------------ */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
  align-items: start;
}

.detail-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  /* Grid items default to min-width auto, so one long unbreakable value
     would otherwise widen the whole track past the card. */
  min-width: 0;
}

/* Status/config values are raw JSON.stringify output with no natural break
   points; without these the table's min-content width overruns the card. */
.detail-card table {
  table-layout: fixed;
}

.detail-card td {
  overflow-wrap: anywhere;
}

.detail-card h3 {
  font-size: 1rem;
  margin: 0;
}

.detail-card h4 {
  font-size: 0.85rem;
  margin: 0.75rem 0 0.3rem;
  color: var(--text-muted);
}

.result-pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.1em;
  margin: 0.5rem 0 0;
}

.config-section {
  margin-bottom: 1rem;
}

.config-section:last-child {
  margin-bottom: 0;
}

.config-textarea {
  display: block;
  width: 100%;
  min-height: 90px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  margin-bottom: 0.5rem;
}

.vehicle-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem 0 0;
}

.vehicle-actions label {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.vehicle-actions input[type="number"] {
  width: 4.5rem;
}

.snapshot-view {
  margin-top: 0.75rem;
  border-top: 1px dashed var(--border);
  padding-top: 0.75rem;
}
