/* =========================================================
   JX IMU Studio — web host UI
   Dark instrument theme, no external dependencies.
   ========================================================= */

:root {
  --bg: #070b11;
  --bg-soft: #0b1119;
  --panel: #0e1620;
  --panel-2: #111b26;
  --line: rgba(148, 163, 184, 0.13);
  --line-strong: rgba(148, 163, 184, 0.24);
  --text: #e7eef7;
  --muted: #8596aa;
  --faint: #5a6a7e;
  --accent: #2fe3c4;
  --accent-2: #4c8dff;
  --accent-soft: rgba(47, 227, 196, 0.12);
  --amber: #ffbc5c;
  --danger: #ff6b7a;
  --violet: #b18cff;
  --x: #2fe3c4;
  --y: #58a6ff;
  --z: #ffbc5c;
  --w: #b18cff;
  --radius: 16px;
  --radius-sm: 11px;
  --mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Segoe UI Variable", "Segoe UI", ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  background:
    radial-gradient(1100px 720px at 12% -12%, rgba(47, 227, 196, 0.10), transparent 60%),
    radial-gradient(980px 680px at 92% -6%, rgba(76, 141, 255, 0.09), transparent 55%),
    radial-gradient(900px 700px at 55% 118%, rgba(177, 140, 255, 0.06), transparent 62%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 90% 65% at 50% 0%, #000 20%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 90% 65% at 50% 0%, #000 20%, transparent 80%);
}

h1, h2, h3, p, ul { margin: 0; }
button { font-family: inherit; }

/* ---------------- Top bar ---------------- */

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 3.2vw, 40px) 14px;
  max-width: 1480px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
  filter: drop-shadow(0 0 14px rgba(47, 227, 196, 0.28));
}

.brand-copy h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-copy p {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-side { display: flex; align-items: center; gap: 10px; flex: none; }

.lang-btn {
  height: 32px;
  min-width: 46px;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.lang-btn:hover { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.05); }

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(90, 106, 126, 0.14);
  transition: background .2s ease, box-shadow .2s ease;
}
.status-pill[data-state="connecting"] { color: var(--amber); border-color: rgba(255, 188, 92, 0.35); background: rgba(255, 188, 92, 0.07); }
.status-pill[data-state="connecting"] .status-dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(255, 188, 92, 0.16); animation: pulse 1.2s ease-in-out infinite; }
.status-pill[data-state="on"] { color: var(--accent); border-color: rgba(47, 227, 196, 0.35); background: rgba(47, 227, 196, 0.07); }
.status-pill[data-state="on"] .status-dot { background: var(--accent); box-shadow: 0 0 10px rgba(47, 227, 196, 0.75); }
.status-pill[data-state="lost"], .status-pill[data-state="error"] { color: var(--danger); border-color: rgba(255, 107, 122, 0.4); background: rgba(255, 107, 122, 0.07); }
.status-pill[data-state="lost"] .status-dot, .status-pill[data-state="error"] .status-dot { background: var(--danger); box-shadow: 0 0 10px rgba(255, 107, 122, 0.65); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------------- Layout shell ---------------- */

.shell {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin: 0 auto;
  padding: 6px clamp(16px, 3.2vw, 40px) 34px;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012)), var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.26);
}

.muted { color: var(--muted); }

/* ---------------- Connection card ---------------- */

.conn-card { padding: 16px 18px 12px; }

.conn-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 18px;
}

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > label {
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.field-narrow { width: 112px; }
.port-field { width: min(280px, 100%); }
.field-connect { margin-left: auto; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  height: 38px;
  align-items: stretch;
}
.segmented button {
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s ease, background .15s ease, box-shadow .15s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.04));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 2px 8px rgba(0, 0, 0, 0.3);
}
.segmented button:disabled { opacity: 0.45; cursor: not-allowed; }

.select-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  width: 100%;
  padding: 0 12px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.select-btn svg { width: 17px; height: 17px; color: var(--accent); flex: none; }
.select-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-btn:hover:not(:disabled) { border-color: var(--line-strong); }
.select-btn:disabled { opacity: 0.5; cursor: not-allowed; }

select, input[type="number"] {
  height: 38px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select { padding: 0 34px 0 11px; width: 100%; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
input[type="number"] { padding: 0 10px; width: 100%; font-family: var(--mono); }
select:focus, input[type="number"]:focus { border-color: rgba(47, 227, 196, 0.55); box-shadow: 0 0 0 3px var(--accent-soft); }
select:disabled, input:disabled { opacity: 0.5; cursor: not-allowed; }

.input-suffix { position: relative; display: flex; align-items: center; }
.input-suffix input { padding-right: 30px; }
.input-suffix > span {
  position: absolute;
  right: 11px;
  color: var(--faint);
  font-size: 12px;
  pointer-events: none;
}

.toggles-field { flex-direction: row; gap: 16px; padding-bottom: 9px; }

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 34px;
  height: 19px;
  flex: none;
  background: #1b2633;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background .18s ease, border-color .18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #7b8da2;
  transition: transform .18s ease, background .18s ease;
}
.switch-row input:checked + .switch { background: rgba(47, 227, 196, 0.2); border-color: rgba(47, 227, 196, 0.5); }
.switch-row input:checked + .switch::after { transform: translateX(15px); background: var(--accent); }
.switch-row input:focus-visible + .switch { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-row:hover { color: var(--text); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 22px;
  color: #04231e;
  background: linear-gradient(135deg, #37efcf, #1fc2a7);
  border: 1px solid rgba(47, 227, 196, 0.6);
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(31, 194, 167, 0.22);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease, background .15s ease;
}
.btn-primary svg { width: 17px; height: 17px; }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 26px rgba(31, 194, 167, 0.3); filter: brightness(1.04); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn-primary.danger {
  color: #2a0509;
  background: linear-gradient(135deg, #ff8390, #f25566);
  border-color: rgba(255, 107, 122, 0.55);
  box-shadow: 0 8px 22px rgba(242, 85, 102, 0.2);
}

.conn-info {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  color: var(--text);
  font-size: 12px;
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}
.conn-info .muted { font-size: 12px; }
.conn-info .sep { color: var(--faint); }
.conn-info .info-key { color: var(--faint); }
.conn-info .warn { color: var(--amber); }

/* ---------------- Tabs ---------------- */

.tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 14px;
  padding: 5px;
  background: rgba(11, 17, 25, 0.85);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.tab-btn svg { width: 17px; height: 17px; opacity: .8; }
.tab-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.035); }
.tab-btn.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(47, 227, 196, 0.13), rgba(47, 227, 196, 0.05));
  border-color: rgba(47, 227, 196, 0.28);
}
.tab-btn.active svg { color: var(--accent); opacity: 1; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: panel-in .22s ease both; }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- Common card bits ---------------- */

.card-head, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head h2, .panel-head h2 {
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: 0.015em;
}
.unit-chip {
  padding: 3px 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  white-space: nowrap;
}
.tag {
  padding: 4px 9px;
  color: var(--accent);
  background: rgba(47, 227, 196, 0.08);
  border: 1px solid rgba(47, 227, 196, 0.2);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
.value-badge {
  padding: 4px 10px;
  color: var(--accent);
  background: rgba(47, 227, 196, 0.08);
  border: 1px solid rgba(47, 227, 196, 0.22);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.value-badge.soft { color: var(--muted); background: rgba(255, 255, 255, 0.035); border-color: var(--line); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.btn-ghost svg { width: 15px; height: 15px; }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.06); }
.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost.active { color: var(--amber); border-color: rgba(255, 188, 92, 0.35); background: rgba(255, 188, 92, 0.08); }

.btn-mini {
  height: 26px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 11.5px;
  cursor: pointer;
}
.btn-mini:hover { color: var(--text); border-color: var(--line-strong); }

/* ---------------- Monitor ---------------- */

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

.sensor-card {
  padding: 16px;
  min-height: 142px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: border-color .2s ease, transform .2s ease;
}
.sensor-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.sensor-card.highlight {
  background:
    linear-gradient(180deg, rgba(47, 227, 196, 0.055), rgba(47, 227, 196, 0.012)),
    var(--panel);
  border-color: rgba(47, 227, 196, 0.2);
}

.axes { display: grid; gap: 12px 10px; align-items: start; }
.axes-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.axes-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.axes-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }

.axis { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.axis-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.axis-label::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
  opacity: .9;
}
.ax-x { color: var(--x); }
.ax-y { color: var(--y); }
.ax-z { color: var(--z); }
.ax-w { color: var(--w); }
.ax-roll { color: var(--accent); }
.ax-pitch { color: var(--accent-2); }
.ax-yaw { color: var(--amber); }
.axes-2 .axis-label { color: var(--muted); }
.axes-2 .axis-label::before { background: var(--muted); opacity: .5; }

.axis-value {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .2s ease;
}
.sensor-card.highlight .axis-value.big { color: var(--accent); font-size: 22px; }

.meter {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}
.meter i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 2px;
  background: currentColor;
  opacity: .7;
  transition: width .12s linear;
}
.axis:nth-child(1) .meter i { background: var(--x); }
.axis:nth-child(2) .meter i { background: var(--y); }
.axis:nth-child(3) .meter i { background: var(--z); }
.axis:nth-child(4) .meter i { background: var(--w); }

/* ---------------- Plot ---------------- */

.chart-panel { padding: 14px 16px 16px; }

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.toolbar-spacer { flex: 1; }

.group-seg { height: 36px; }
.group-seg button { padding: 0 12px; font-size: 12px; }

.rate-chip {
  padding: 3px 8px;
  color: var(--faint);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-area {
  position: relative;
  height: clamp(360px, calc(100vh - 330px), 640px);
  min-height: 320px;
  border: 1px solid rgba(148, 163, 184, 0.09);
  border-radius: 12px;
  background:
    radial-gradient(900px 420px at 50% 0%, rgba(76, 141, 255, 0.045), transparent 70%),
    #0a1119;
  overflow: hidden;
}
.chart-area canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------- 3D attitude ---------------- */

.attitude-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.85fr);
  gap: 14px;
}

.viewport-card { display: flex; flex-direction: column; padding: 14px 16px 16px; }

.viewport-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.readout {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.readout span { color: var(--faint); font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.readout strong { font-family: var(--mono); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.zero-badge {
  margin-left: auto;
  padding: 4px 10px;
  color: var(--amber);
  background: rgba(255, 188, 92, 0.08);
  border: 1px solid rgba(255, 188, 92, 0.25);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
}

.viewport-body {
  position: relative;
  flex: 1;
  min-height: clamp(430px, calc(100vh - 360px), 640px);
  border: 1px solid rgba(148, 163, 184, 0.09);
  border-radius: 12px;
  background:
    radial-gradient(520px 360px at 50% 45%, rgba(47, 227, 196, 0.06), transparent 70%),
    radial-gradient(700px 520px at 50% 120%, rgba(76, 141, 255, 0.05), transparent 70%),
    #0a1119;
  overflow: hidden;
}
.viewport-body canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
.viewport-body canvas:active { cursor: grabbing; }

.viewport-actions {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 5px;
  background: rgba(9, 14, 20, 0.82);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.viewport-hint {
  position: absolute;
  right: 14px;
  top: 12px;
  color: var(--faint);
  font-size: 11px;
  pointer-events: none;
}

.compass-side { display: flex; flex-direction: column; padding: 14px 16px 16px; }
.gauge-body { position: relative; flex: 1; min-height: 300px; }
.gauge-body canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------- Instruments ---------------- */

.instruments-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.gauge-card { padding: 14px 16px 12px; display: flex; flex-direction: column; }
.gauge-card .gauge-body { min-height: clamp(340px, calc(100vh - 380px), 560px); }

.gauge-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  color: var(--muted);
  font-size: 12px;
}
.gauge-foot strong { color: var(--text); font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums; }
.gauge-foot.double { justify-content: space-between; gap: 16px; }
.gauge-foot.double > span { display: inline-flex; align-items: baseline; gap: 8px; }
.gauge-foot.double label { color: var(--faint); font-size: 11px; }
.gauge-foot .hint { color: var(--faint); font-size: 11px; }

/* ---------------- Calibration ---------------- */

.cal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 14px;
  align-items: stretch;
}
.cal-left { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.cal-intro { padding: 16px 18px 18px; }
.intro-text { margin-top: 9px; color: var(--muted); font-size: 12.5px; line-height: 1.65; }

.cal-guide { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 11px; }
.cal-guide li { display: flex; gap: 11px; align-items: flex-start; }
.guide-icon {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: rgba(47, 227, 196, 0.07);
  border: 1px solid rgba(47, 227, 196, 0.18);
  border-radius: 9px;
}
.guide-icon.warn { color: var(--amber); background: rgba(255, 188, 92, 0.07); border-color: rgba(255, 188, 92, 0.22); }
.guide-icon svg { width: 16px; height: 16px; }
.cal-guide b { display: block; font-size: 12.5px; font-weight: 650; }
.cal-guide small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.5; margin-top: 2px; }

.cal-actions { padding: 16px 18px 18px; }
.cal-status {
  padding: 4px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
.cal-status[data-state="running"] { color: var(--amber); border-color: rgba(255, 188, 92, 0.35); background: rgba(255, 188, 92, 0.07); animation: pulse 1.3s ease-in-out infinite; }

.cal-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.cal-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 13px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.cal-tile:hover:not(:disabled) { border-color: rgba(47, 227, 196, 0.35); background: rgba(47, 227, 196, 0.05); transform: translateY(-1px); }
.cal-tile:disabled { opacity: 0.45; cursor: not-allowed; }
.cal-tile strong { font-size: 12.5px; font-weight: 650; }
.cal-tile small { color: var(--muted); font-size: 10.5px; line-height: 1.4; }
.tile-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: rgba(47, 227, 196, 0.08);
  border-radius: 8px;
  margin-bottom: 2px;
}
.tile-icon svg { width: 17px; height: 17px; }
.cal-tile.danger .tile-icon { color: var(--danger); background: rgba(255, 107, 122, 0.08); }
.cal-tile.danger:hover:not(:disabled) { border-color: rgba(255, 107, 122, 0.4); background: rgba(255, 107, 122, 0.05); }
.cal-tile.running { border-color: rgba(255, 188, 92, 0.45); background: rgba(255, 188, 92, 0.06); }
.cal-tile.running .tile-icon { color: var(--amber); background: rgba(255, 188, 92, 0.1); animation: pulse 1.2s ease-in-out infinite; }

.temp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  flex-wrap: wrap;
}
.temp-row > label { color: var(--muted); font-size: 12px; }
.temp-row .input-suffix { width: 104px; }
.temp-row .btn-ghost { margin-left: auto; }

.cal-log-card { display: flex; flex-direction: column; padding: 16px 18px 16px; }
.cal-log {
  flex: 1;
  min-height: 300px;
  max-height: 600px;
  margin-top: 12px;
  padding: 12px 14px;
  background: #070d13;
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 11px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.75;
}
.log-line { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.log-time { color: var(--faint); flex: none; font-variant-numeric: tabular-nums; }
.log-text { color: var(--muted); }
.log-line.ok .log-text { color: var(--accent); }
.log-line.warn .log-text { color: var(--amber); }
.log-line.error .log-text { color: var(--danger); }
.log-line.hint .log-text { color: var(--faint); font-style: italic; }

/* ---------------- Footer / toasts ---------------- */

.footer {
  padding: 20px 4px 0;
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 14px;
  color: var(--text);
  background: #101a24;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: 11px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  font-size: 12.5px;
  line-height: 1.5;
  animation: toast-in .2s ease both;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--amber); }
.toast.leaving { animation: toast-out .18s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(6px); } }

.noscript {
  position: fixed;
  inset: auto 20px 20px;
  padding: 12px 16px;
  background: #2a0f13;
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: var(--text);
  z-index: 60;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 1120px) {
  .monitor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attitude-grid { grid-template-columns: minmax(0, 1fr); }
  .compass-side .gauge-body { min-height: 360px; }
  .cal-grid { grid-template-columns: minmax(0, 1fr); }
  .cal-log { max-height: 380px; }
}

@media (max-width: 820px) {
  .topbar { padding-top: 16px; }
  .conn-fields { gap: 12px 14px; }
  .field-connect { margin-left: 0; width: 100%; }
  .btn-primary { width: 100%; }
  .toggles-field { width: 100%; padding-bottom: 0; }
  .monitor-grid { grid-template-columns: minmax(0, 1fr); }
  .instruments-grid { grid-template-columns: minmax(0, 1fr); }
  .cal-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-toolbar { gap: 8px; }
  .group-seg { width: 100%; overflow-x: auto; }
  .group-seg button { flex: none; }
  .toolbar-spacer { display: none; }
  .rate-chip { margin-left: auto; }
}

@media (max-width: 560px) {
  .shell { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .brand-copy p { display: none; }
  .tab-btn { padding: 8px 10px; font-size: 12px; gap: 0; }
  .tab-btn svg { display: none; }
  .axes-3 { gap: 10px 8px; }
  .axis-value { font-size: 16px; }
  .sensor-card.highlight .axis-value.big { font-size: 18px; }
  .cal-tiles { grid-template-columns: minmax(0, 1fr); }
  .viewport-head .zero-badge { margin-left: 0; }
  .gauge-foot.double { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
