*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #070c14;
  --bg-soft: #0d1627;
  --surface: #111d31;
  --surface-2: #18263f;
  --surface-3: #223451;
  --border: #2a3e5f;
  --border-soft: #324b74;
  --text: #e9f2ff;
  --text-soft: #9eb4d8;
  --text-muted: #7f95b9;
  --ok: #24d08a;
  --warn: #f3bb3d;
  --error: #ff6464;
  --nodata: #808da1;
  --accent: #65adff;
  --accent-2: #4ee0ff;
  --shadow-card: 0 8px 20px rgba(0, 0, 0, 0.35);
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 22px;
  --mono: "Consolas", "Courier New", monospace;
}

html,
body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top right, #13233d 0%, var(--bg) 48%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.system-header {
  height: 58px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(90deg, #0f1a2e, #132541 56%, #12233b);
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.4);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
  padding: 0 14px;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-right {
  justify-content: flex-end;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 8px currentColor;
  }
  50% {
    opacity: 0.5;
    box-shadow: 0 0 2px currentColor;
  }
}

.header-status-block {
  display: flex;
  align-items: center;
}

.source-indicator {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 999px;
  padding: 2px 9px;
  border: 1px solid var(--border-soft);
  white-space: nowrap;
}

.source-indicator.serial {
  color: var(--ok);
  border-color: rgba(36, 208, 138, 0.55);
  background: rgba(36, 208, 138, 0.12);
}

.source-indicator.ingest {
  color: var(--accent-2);
  border-color: rgba(90, 169, 255, 0.55);
  background: rgba(90, 169, 255, 0.12);
}

.source-indicator.csv {
  color: var(--warn);
  border-color: rgba(243, 187, 61, 0.55);
  background: rgba(243, 187, 61, 0.12);
}

.source-row {
  display: grid;
  grid-template-columns: 62px 1fr 1fr;
  gap: var(--space-1);
  min-width: 0;
}

.source-row .btn {
  padding: 8px 4px;
  white-space: nowrap;
}

.source-interval {
  width: 100%;
  min-width: 0;
  padding: 7px 4px;
}

.header-status {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.header-center {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.header-center h1 {
  font-size: 14px;
  line-height: 1.1;
  letter-spacing: 0.04em;
}

.admin-view-link {
  color: var(--accent);
  font-size: 11px;
  text-decoration: none;
  letter-spacing: 0.03em;
}

.admin-view-link:hover {
  color: var(--accent-2);
  text-decoration: underline;
}

.page-tabs {
  display: inline-flex;
  gap: 4px;
}

.page-tab {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-soft);
  border: 1px solid var(--border-soft);
  background: rgba(127, 149, 185, 0.12);
  border-radius: 999px;
  padding: 3px 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.page-tab:hover {
  color: var(--text);
}

.page-tab.active {
  color: #061224;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.header-meta-row {
  display: grid;
  gap: 1px;
  text-align: right;
}

.header-meta-row span {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.header-meta-row strong {
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

.header-meta-row strong.warn {
  color: var(--warn);
}

.system-header.ok {
  border-bottom-color: var(--ok);
}
.system-header.ok .status-dot,
.system-header.ok .header-status {
  color: var(--ok);
}

.system-header.warn {
  border-bottom-color: var(--warn);
}
.system-header.warn .status-dot,
.system-header.warn .header-status {
  color: var(--warn);
}

.system-header.error {
  border-bottom-color: var(--error);
}
.system-header.error .status-dot,
.system-header.error .header-status {
  color: var(--error);
}

.system-header.nodata {
  border-bottom-color: var(--nodata);
}
.system-header.nodata .status-dot,
.system-header.nodata .header-status {
  color: var(--nodata);
}

.app-shell {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--space-2);
  overflow: hidden;
}

.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.page[hidden] {
  display: none;
}

.dashboard-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 332px 1fr;
  gap: var(--space-2);
  overflow: hidden;
}

.control-column {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

/* カードを潰さず、入り切らない場合は列をスクロールさせる */
.control-column > .card {
  flex-shrink: 0;
}

.main-column {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--space-2);
  overflow: hidden;
}

.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-card);
  padding: var(--space-3);
}

.card-title {
  color: var(--accent-2);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 11px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.health-summary {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--nodata);
}

.health-summary.ok {
  color: var(--ok);
}

.health-summary.warn {
  color: var(--warn);
}

.health-summary.error {
  color: var(--error);
}

.health-summary.nodata {
  color: var(--nodata);
}

.telem-group {
  margin-bottom: var(--space-2);
}

.telem-group:last-child {
  margin-bottom: 0;
}

.telem-group-title {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 3px;
  margin-bottom: 5px;
}

.telem-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-family: var(--mono);
}

.telem-list dt {
  color: var(--text-soft);
  white-space: nowrap;
}

.telem-list dd {
  text-align: right;
  font-weight: 600;
}

.telem-list dd.key-val {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 14px;
}

/* valid_flags-gated channel with its owning bit not set: suppress as N/A */
.telem-list dd.na {
  color: var(--text-muted);
  font-weight: 500;
  font-style: italic;
}

/* e.g. imu_calib_mag <= 1 -> yaw/heading confidence low (telemetry_gui_spec.md §3.1) */
.telem-list dd.warn-text {
  color: var(--warn);
}

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

.badge {
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.05em;
  padding: 5px 3px;
}

.badge.ok {
  background: rgba(36, 208, 138, 0.16);
  border-color: var(--ok);
  color: var(--ok);
}

.badge.warn {
  background: rgba(243, 187, 61, 0.16);
  border-color: var(--warn);
  color: var(--warn);
}

.badge.error {
  background: rgba(255, 100, 100, 0.16);
  border-color: var(--error);
  color: var(--error);
}

.badge.unknown {
  background: rgba(128, 141, 161, 0.12);
  border-color: #60708d;
  color: var(--nodata);
}

.btn-group {
  display: grid;
  gap: var(--space-2);
}

.btn {
  border: none;
  border-radius: var(--radius-s);
  padding: 8px 10px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:disabled,
.cmd-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: none;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.btn:disabled:hover {
  transform: none;
  filter: none;
}

.btn:active {
  transform: translateY(0);
}

.btn-green {
  background: linear-gradient(140deg, #0d9f61, #24d08a);
}
.btn-red {
  background: linear-gradient(140deg, #bf3636, #ff6464);
}
.btn-blue {
  background: linear-gradient(140deg, #2a76d2, #65adff);
}
.btn-gray {
  background: linear-gradient(140deg, #4d607d, #687a96);
  flex-shrink: 0;
}

.send-row {
  display: flex;
  gap: var(--space-1);
}

.cmd-input {
  width: 100%;
  min-width: 0;
  background: #0f1b2e;
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: var(--radius-s);
  padding: 7px 9px;
  font-size: 12px;
}

.cmd-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(101, 173, 255, 0.4);
}

.command-feedback {
  min-height: 16px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.command-feedback.ok {
  color: var(--ok);
}
.command-feedback.error {
  color: var(--error);
}

.card-map {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.map-header {
  margin-bottom: var(--space-2);
}

.map-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.map-follow-label {
  color: var(--text-soft);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.map-legend {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #65adff;
  box-shadow: 0 0 6px #65adff;
}

#map {
  min-height: 0;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.leaflet-container {
  background: #0d1627;
}

.glider-label {
  pointer-events: none;
}

.glider-label-box {
  min-width: 86px;
  border-radius: var(--radius-s);
  border: 1px solid rgba(78, 224, 255, 0.5);
  background: rgba(7, 12, 20, 0.84);
  padding: 3px 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  font-family: var(--mono);
}

.glider-label-title {
  color: var(--ok);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.glider-label-row {
  color: var(--text-soft);
  font-size: 9px;
}

.glider-label-row strong {
  color: var(--accent);
  font-weight: 700;
}

.top-row {
  min-height: 0;
  display: grid;
  grid-template-columns: 1.2fr minmax(260px, 0.9fr) minmax(280px, 0.75fr);
  gap: var(--space-1);
}

.side-trends {
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
}

.card-attitude {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.card-attitude .card-header {
  margin-bottom: 6px;
}

.attitude-body {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
}

.attitude-body canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: var(--radius-s);
  background:
    radial-gradient(ellipse at 50% 42%, rgba(78, 224, 255, 0.08) 0%, transparent 55%),
    linear-gradient(180deg, rgba(8, 16, 30, 0.95) 0%, rgba(6, 12, 22, 0.98) 100%);
  border: 1px solid var(--border-soft);
}

.attitude-body canvas.att-invalid {
  opacity: 0.45;
  filter: grayscale(0.55);
}

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

.att-val {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-soft);
  background: rgba(6, 14, 26, 0.72);
}

.att-label {
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.att-num {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-2);
  letter-spacing: 0.02em;
}

.att-num.na {
  color: var(--nodata);
  font-weight: 600;
}

.att-num.warn-text {
  color: var(--warn);
}

.aux-charts {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.single-chart {
  min-height: 0;
}

.card-chart {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.card-chart .card-header {
  margin-bottom: 6px;
}

.chart-hint {
  color: var(--text-muted);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.card-chart canvas {
  min-height: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.top-row .card-chart,
.aux-charts .card-chart,
.side-trends .card-chart {
  min-height: 0;
}

.card-map {
  height: 100%;
}

.card-log {
  min-height: 140px;
  flex: 1 1 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.log-filter {
  display: inline-flex;
  gap: 5px;
}

.log-filter-btn {
  font-size: 10px;
  color: var(--text-soft);
  border: 1px solid var(--border-soft);
  background: rgba(127, 149, 185, 0.12);
  border-radius: 999px;
  padding: 3px 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.log-filter-btn.active {
  color: #061224;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.event-log {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-s);
  background: rgba(6, 14, 26, 0.72);
  padding: var(--space-1) var(--space-2);
  font-family: var(--mono);
  font-size: 12px;
}

.log-entry {
  padding: 4px 0;
  border-bottom: 1px solid rgba(98, 118, 150, 0.24);
  line-height: 1.4;
}

.log-entry:last-child {
  border-bottom: none;
}

.log-ts {
  color: var(--text-muted);
}

.log-entry.level-info .log-body {
  color: var(--text);
}

.log-entry.level-warn .log-body {
  color: var(--warn);
}

.log-entry.level-error .log-body {
  color: var(--error);
}

.state-ok {
  border-color: rgba(36, 208, 138, 0.58);
  box-shadow: inset 0 0 0 1px rgba(36, 208, 138, 0.28), var(--shadow-card);
}

.state-warn {
  border-color: rgba(243, 187, 61, 0.58);
  box-shadow: inset 0 0 0 1px rgba(243, 187, 61, 0.28), var(--shadow-card);
}

.state-error {
  border-color: rgba(255, 100, 100, 0.62);
  box-shadow: inset 0 0 0 1px rgba(255, 100, 100, 0.3), var(--shadow-card);
}

.state-nodata {
  border-color: rgba(128, 141, 161, 0.5);
  box-shadow: inset 0 0 0 1px rgba(128, 141, 161, 0.25), var(--shadow-card);
}

/* ===== コックピット（PFD）ページ ===== */
.cockpit-shell {
  flex: 1;
  min-height: 0;
  display: grid;
}

.card-pfd {
  min-height: 0;
  display: grid;
  padding: var(--space-2);
  overflow: hidden;
}

#pfd-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
}

/* ===== 再生（Replay）ページ ===== */
.replay-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 332px 1fr;
  gap: var(--space-2);
}

.replay-side {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.replay-main {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 2fr) auto minmax(0, 1fr);
  gap: var(--space-2);
}

#replay-map {
  min-height: 0;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.replay-file-row {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}

.replay-file-row select {
  flex: 1;
  min-width: 0;
}

.replay-controls-card {
  padding: var(--space-2) var(--space-3);
}

.replay-controls {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.replay-controls .btn {
  min-width: 64px;
}

.speed-select {
  width: 78px;
  flex: none;
}

.replay-seek-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-2);
}

.replay-seek-row input[type='range'] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.replay-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-soft);
  min-width: 64px;
  text-align: center;
}

@media (max-width: 1400px) {
  .dashboard-grid {
    grid-template-columns: 300px 1fr;
  }

  .main-column {
    grid-template-rows: minmax(0, 1.8fr) minmax(0, 1fr);
  }

  .top-row {
    grid-template-columns: 1.1fr minmax(220px, 0.85fr) minmax(240px, 0.7fr);
  }
}

@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .control-column {
    max-height: 42vh;
  }

  .main-column {
    grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
  }

  .top-row {
    grid-template-columns: 1fr;
  }

  .aux-charts {
    grid-template-columns: 1fr;
  }

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

  .replay-side {
    max-height: 36vh;
  }
}

/* 高さの低い画面（ノートPC）では左列を2列グリッドに組み替えて見切れを防ぐ */
@media (max-height: 840px) and (min-width: 1201px) {
  .dashboard-grid {
    grid-template-columns: 470px 1fr;
  }

  .control-column {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    grid-template-rows: auto auto auto minmax(120px, 1fr);
    grid-template-areas:
      'serial telem'
      'publish telem'
      'recording telem'
      'log telem';
    align-items: start;
  }

  .card-serial { grid-area: serial; }
  .card-publish { grid-area: publish; }
  .card-recording { grid-area: recording; }
  .card-telem { grid-area: telem; }

  .control-column:not(:has(.card-serial)) {
    grid-template-rows: auto auto minmax(120px, 1fr);
    grid-template-areas:
      'publish telem'
      'recording telem'
      'log telem';
  }

  .card-log {
    grid-area: log;
    min-height: 120px;
    height: 100%;
  }

  .control-column .card {
    padding: var(--space-2);
  }

  .telem-list {
    font-size: 11px;
    gap: 3px 8px;
  }
}

.publish-label {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.publish-flight-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 160px;
  overflow: auto;
}

.publish-flight-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-s);
  background: var(--surface-2);
}

.publish-flight-name {
  font-size: 11px;
  word-break: break-all;
  color: var(--text);
}

.publish-remove-btn {
  flex: 0 0 auto;
  padding: 4px 8px;
  font-size: 11px;
  box-shadow: none;
}

/* Session / login (VPS mode, issue #8) */
.session-meta {
  gap: 8px;
  margin-left: 8px;
}

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--accent-2);
  font-size: 11px;
  letter-spacing: 0.04em;
}

a.header-logout {
  text-decoration: none;
  padding: 4px 10px;
  font-size: 12px;
}

.login-body {
  display: grid;
  place-items: center;
  overflow: auto;
}

.login-shell {
  width: min(360px, calc(100% - 32px));
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  background: linear-gradient(160deg, var(--surface) 0%, var(--bg-soft) 100%);
  box-shadow: var(--shadow-card);
}

.login-title {
  font-size: 1.35rem;
  font-weight: 650;
  margin-bottom: 6px;
}

.login-sub {
  color: var(--text-soft);
  margin-bottom: 18px;
  line-height: 1.4;
}

.login-error {
  color: var(--error);
  margin-bottom: 12px;
  font-size: 12px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-soft);
  font-size: 12px;
}

.login-submit {
  margin-top: 6px;
  width: 100%;
}

