:root {
  --bg: #0f141b;
  --panel: #18202b;
  --panel-2: #1f2937;
  --line: #2c3947;
  --ink: #eef4fb;
  --muted: #9fb1c4;
  --accent: #2e90fa;
  --ok: #2bd07a;
  --warn: #ffb020;
  --bad: #ff5d5d;
  --touch: 52px;            /* 最小タッチターゲット */
  --radius: 12px;
}

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

body {
  background: #0a0e13;
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 16px;
}

/* 屋外を想定したハイコントラスト（既定ON） */
body.is-highcontrast {
  --bg: #0b0f14;
  --panel: #161d27;
  --ink: #ffffff;
  --muted: #b9c8d8;
}

.app {
  display: grid;
  grid-template-columns: 188px 1fr;
  height: min(78vh, 760px);
  min-height: 520px;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 80px -40px rgba(0, 0, 0, .9);
}

/* ---------- 左レール ---------- */
.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 6px;
}
.rail__brand { display: flex; align-items: center; gap: 8px; padding: 6px 8px 14px; }
.rail__logo { color: var(--accent); font-size: 1.4rem; }
.rail__name { font-weight: 800; letter-spacing: .04em; }
.rail__menu { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rail__item {
  width: 100%;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.rail__item .ico { font-size: 1.2rem; width: 1.4em; text-align: center; }
.rail__item:hover { background: var(--panel-2); color: var(--ink); }
.rail__item.is-active { background: linear-gradient(100deg, var(--accent), #1f6fd6); color: #fff; }
.rail__item--foot { margin-top: auto; }

/* ---------- 本体 ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar__crumb { color: var(--muted); font-size: .78rem; letter-spacing: .04em; }
.topbar__title h1 { font-size: 1.2rem; }
.topbar__status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip--ok { color: var(--ok); border-color: rgba(43, 208, 122, .4); }
.chip--ok .dot { animation: pulse 1.6s ease-in-out infinite; }
.chip--warn { color: var(--warn); border-color: rgba(255, 176, 32, .4); }
.chip--idle { color: var(--muted); }
.chip--quality { color: var(--ink); }
.chip--sat { color: var(--accent); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.btn-touch {
  min-height: 44px;
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: transform .15s ease, background .18s ease, box-shadow .18s ease;
}
.btn-touch:hover { background: #26303d; }
.btn-touch:active { transform: scale(.97); }
.btn-touch--primary {
  background: linear-gradient(100deg, var(--accent), #1f6fd6);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px -10px rgba(46, 144, 250, .9);
}
.btn-touch--block { width: 100%; margin: 12px 0; min-height: var(--touch); }
.btn-touch--lg { min-height: 60px; padding: 0 30px; font-size: 1.1rem; }

/* ---------- 画面切替 ---------- */
.screen { display: none; flex: 1; min-height: 0; }
.screen.is-active { display: flex; }
.screen[data-screen="map"] { gap: 0; }

/* 地図/DXF */
.canvas {
  position: relative;
  flex: 1;
  background: radial-gradient(120% 120% at 50% 20%, #14202c, #0c1118);
  overflow: hidden;
}
.canvas__grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(120, 160, 200, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 160, 200, .08) 1px, transparent 1px);
  background-size: 32px 32px;
}
.canvas__svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.canvas__svg polyline { fill: none; stroke: #4a6a88; stroke-width: 3; stroke-linejoin: round; }
.canvas__svg text { fill: var(--muted); font-size: 13px; font-weight: 700; text-anchor: middle; }
.pt { stroke: #0c1118; stroke-width: 2; }
.pt--base { fill: var(--accent); }
.pt--live { fill: var(--ok); }
.pt--live { animation: ping 1.8s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes ping { 0% { opacity: 1; } 50% { opacity: .5; r: 13px; } 100% { opacity: 1; } }
.canvas__hud {
  position: absolute; left: 14px; bottom: 14px;
  display: flex; gap: 14px;
  padding: 8px 14px;
  background: rgba(10, 14, 19, .8);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: .9rem;
  backdrop-filter: blur(4px);
}
.canvas__tools {
  position: absolute; right: 14px; bottom: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.tool {
  width: var(--touch); height: var(--touch);
  font-size: 1.5rem; line-height: 1;
  color: var(--ink);
  background: rgba(10, 14, 19, .82);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: background .18s ease, transform .15s ease;
}
.tool:hover { background: var(--accent); color: #fff; }
.tool:active { transform: scale(.94); }

/* 右サイド情報 */
.side {
  width: 320px;
  max-width: 42%;
  padding: 18px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
}
.side h2 { font-size: 1rem; margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin-bottom: 6px; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.quality { margin-top: 16px; display: grid; gap: 10px; }
.quality__row { display: grid; grid-template-columns: 3.2em 1fr 2.4em; align-items: center; gap: 10px; font-size: .85rem; }
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: var(--w); background: linear-gradient(90deg, var(--accent), var(--ok)); border-radius: 99px; }
.quality__row b { text-align: right; font-size: .8rem; }

/* パネル系（一覧/評価/設定） */
.panel { flex: 1; padding: 20px; overflow: auto; }
.panel--center { display: grid; place-items: center; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel__head h2 { font-size: 1.1rem; }

.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.grid th, .grid td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid th { color: var(--muted); font-size: .8rem; font-weight: 700; }
.grid tbody tr { transition: background .15s ease; }
.grid tbody tr:hover { background: var(--panel); }
.grid tr.is-current { background: rgba(46, 144, 250, .12); }
.grid td { font-variant-numeric: tabular-nums; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.qcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.qcard p { color: var(--muted); font-size: .85rem; }
.qcard b { display: block; font-size: 1.7rem; margin: 4px 0; font-variant-numeric: tabular-nums; }
.qcard span { color: var(--muted); font-size: .78rem; }

.observe { text-align: center; max-width: 360px; }
.observe__label { color: var(--muted); letter-spacing: .1em; font-weight: 700; }
.observe__gauge {
  width: 160px; height: 160px;
  margin: 18px auto;
  border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p, 5) * 10%), var(--panel-2) 0);
  position: relative;
}
.observe__gauge::after { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--bg); }
.observe__gauge span { position: relative; font-size: 2.6rem; font-weight: 800; }
.observe__gauge small { position: relative; display: block; color: var(--muted); font-size: .8rem; }
.observe__hint { color: var(--muted); margin-bottom: 18px; }

.setlist { display: grid; gap: 10px; max-width: 520px; }
.setrow {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: var(--touch);
  padding: 0 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.setrow select { font: inherit; padding: 8px 10px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
.setrow input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); }

.note {
  max-width: 1200px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.7;
  text-align: center;
}
.note strong { color: var(--ink); }
.note a { color: var(--accent); }

/* ---------- レスポンシブ（小さいタブレット縦・スマホ） ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .rail { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail__brand { display: none; }
  .rail__menu { flex-direction: row; }
  .rail__item--foot { margin: 0; }
  .rail__item { white-space: nowrap; }
  .screen[data-screen="map"] { flex-direction: column; }
  .canvas { min-height: 300px; }
  .side { width: 100%; max-width: none; border-left: 0; border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
