/* =========================================================================
   ロボット状態モニタ — ユニバーサルデザイン
   ・状態は「色」だけで表さない。必ず 記号＋状態名の文字＋枠線の形 を併せる
   ・凡例は常に画面内に出す
   ・文字は大きく、行間を広く。投影しても離れて読める
   ・見た目の設定変更は設けない（誰が開いても同じ1種類の見え方）
   ・OSの明暗設定にだけ追従する
   ========================================================================= */

:root {
  color-scheme: light dark;

  --bg:            #eef1f6;
  --surface:       #ffffff;
  --surface-2:     #f4f6fa;
  --border:        #c8d0de;
  --border-strong: #7c879c;
  --text:          #10161f;      /* 白地で 16:1 以上 */
  --text-2:        #414c5e;      /* 白地で 8:1 以上 */
  --muted:         #55617a;      /* 白地で 5.6:1 */
  --accent:        #1450c8;
  --accent-ink:    #ffffff;
  --accent-weak:   #e7edfb;
  --focus:         #0b57d0;

  /* 状態色。明度に差をつけてあるので、色が見分けにくくても濃淡で区別できる */
  --st-running:      #0a7a4a;
  --st-running-bg:   #e2f5ec;
  --st-paused:       #a45700;
  --st-paused-bg:    #fdf0dc;
  --st-abnormal:     #c22219;
  --st-abnormal-bg:  #fde8e6;
  --st-stopped:      #3f4a5e;
  --st-stopped-bg:   #e9edf4;
  --st-unknown:      #5a6478;
  --st-unknown-bg:   #f0f2f6;

  --r: 12px;
  --shadow: 0 1px 2px rgba(16,22,31,.08), 0 4px 14px rgba(16,22,31,.06);
  --font: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --mono: ui-monospace, Consolas, "Yu Gothic UI", monospace;

  /* タイルの大きさ。掲示モードで上書きする */
  --tile-min: 190px;
  --tile-name: 1.5rem;
  --tile-status: 1.35rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0b1017;
    --surface:       #151c26;
    --surface-2:     #1c2431;
    --border:        #2f3a4b;
    --border-strong: #7d8ba1;
    --text:          #f2f5fa;
    --text-2:        #c3ccdb;
    --muted:         #9aa5b8;
    --accent:        #7ba4ff;
    --accent-ink:    #0b1017;
    --accent-weak:   #16233d;
    --focus:         #9cc0ff;

    --st-running:      #4ed69b;
    --st-running-bg:   #0e3327;
    --st-paused:       #f0b357;
    --st-paused-bg:    #382709;
    --st-abnormal:     #ff8177;
    --st-abnormal-bg:  #3d1614;
    --st-stopped:      #b7c2d4;
    --st-stopped-bg:   #202836;
    --st-unknown:      #98a2b5;
    --st-unknown-bg:   #1a212c;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;           /* 既定より大きめ。小さい文字を作らないための土台 */
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* 動きに弱い人のために、アニメーションはOS設定に従って止める */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* キーボード操作の現在位置を必ず見せる */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* 読み上げ専用（画面には出さないが、支援技術には伝える） */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* 「本文へ飛ぶ」リンク。キーボードで最初に当たる位置に置く */
.skip {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border-strong); border-radius: 8px; padding: 10px 14px;
}
.skip:focus { top: 8px; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- 部品 */

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;                    /* 指で押せる大きさを確保 */
  padding: 10px 18px;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger  { color: var(--st-abnormal); border-color: var(--st-abnormal); }
.btn.small   { min-height: 40px; padding: 6px 12px; font-size: .95rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

input[type=text], input[type=search], input[type=number], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
}
textarea { min-height: 110px; line-height: 1.6; font-family: var(--mono); }
label { display: block; font-weight: 700; margin: 14px 0 6px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: .92rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 6px; font-size: 1.25rem; }
.card > p.lead { margin: 0 0 14px; color: var(--text-2); }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grow { flex: 1 1 200px; }
.muted { color: var(--muted); }
.mono  { font-family: var(--mono); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-size: .95rem; }
.table-wrap { overflow-x: auto; }

/* ---------------------------------------------------------------- 入口（参加前） */

/* 画面の高さが足りない時（小さなスマホ・文字を大きく拡大した時）に上下中央へ寄せると、
   カードの上端が画面の外へ出て触れなくなる。高さに余裕がある時だけ中央へ寄せる。 */
.gate {
  min-height: 100dvh;
  display: grid; place-items: start center;
  padding: 24px;
}
@media (min-height: 720px) {
  .gate { place-items: center; }
}
.gate .card { max-width: 520px; width: 100%; }
.gate h1 { font-size: 1.5rem; margin: 0 0 4px; }

.msg {
  border: 2px solid var(--st-abnormal);
  background: var(--st-abnormal-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 14px 0;
}
.msg.ok { border-color: var(--st-running); background: var(--st-running-bg); }
/* 手順の案内。赤い枠だと「失敗した」と読めてしまうので、落ち着いた色にする */
.msg.info { border-color: var(--accent); background: var(--accent-weak, var(--surface-2)); }
.msg ol, .msg ul { line-height: 1.9; }
.msg li { margin-bottom: 4px; }

/* ---------------------------------------------------------------- 全体の枠 */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.topbar nav { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.topbar nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 4px 12px;
  border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 600;
  border: 2px solid transparent;
}
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a[aria-current="page"] { border-color: var(--accent); color: var(--accent); }

main { padding: 18px 16px 60px; max-width: 1500px; margin: 0 auto; }

/* ---------------------------------------------------------------- 集計バー */

.summary {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 16px;
}
.sum {
  display: inline-flex; align-items: baseline; gap: 8px;
  padding: 8px 14px; border-radius: 10px;
  border: 2px solid currentColor;
  font-weight: 700;
}
.sum .n { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.sum .mark { font-size: 1rem; }

.received {
  margin-left: auto;
  font-weight: 700;
  padding: 8px 14px;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
}
.received.stale { border-color: var(--st-paused); background: var(--st-paused-bg); color: var(--st-paused); }

/* ---------------------------------------------------------------- 号機タイル */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: 14px;
  list-style: none; padding: 0; margin: 0;
}

.tile {
  position: relative;
  display: flex; flex-direction: column; gap: 4px;
  width: 100%;
  min-height: 150px;
  padding: 14px 14px 12px;
  text-align: left;
  border: 3px solid var(--border-strong);
  border-left-width: 14px;                 /* 左の太帯。色が分からなくても状態ごとに柄が違う */
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.tile .name {
  font-size: var(--tile-name); font-weight: 800; line-height: 1.25;
}
.tile .state {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--tile-status); font-weight: 800;
}
.tile .state .mark { font-size: 1.1em; line-height: 1; }
.tile .elapsed { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-2); }
.tile .sub { font-size: .92rem; color: var(--muted); margin-top: auto; }
.tile .alarm {
  font-family: var(--mono); font-weight: 700;
  overflow-wrap: anywhere;
}

/* 状態ごとの見た目。色・地の明るさ・左帯の柄の3つで区別する */
.tile.st-running  { border-color: var(--st-running);  background: var(--st-running-bg); }
.tile.st-paused   { border-color: var(--st-paused);   background: var(--st-paused-bg); }
.tile.st-abnormal { border-color: var(--st-abnormal); background: var(--st-abnormal-bg); border-width: 4px; border-left-width: 16px; }
.tile.st-stopped  { border-color: var(--st-stopped);  background: var(--st-stopped-bg); }
.tile.st-unknown  { border-color: var(--st-unknown);  background: var(--st-unknown-bg); border-style: dashed; }

.tile.st-running  .state, .tile.st-running  .name { color: var(--st-running); }
.tile.st-paused   .state, .tile.st-paused   .name { color: var(--st-paused); }
.tile.st-abnormal .state, .tile.st-abnormal .name { color: var(--st-abnormal); }
.tile.st-stopped  .state, .tile.st-stopped  .name { color: var(--st-stopped); }
.tile.st-unknown  .state, .tile.st-unknown  .name { color: var(--st-unknown); }
.tile .name { color: var(--text) !important; }

/* 異常停止だけは左帯を斜線にする。白黒印刷や色覚特性に関係なく一目で違う */
.tile.st-abnormal::before {
  content: ""; position: absolute; top: -4px; bottom: -4px; left: -16px; width: 16px;
  /* 透明にすると下の赤い枠が透けて縞に見えないので、薄い側も色を置く */
  background: repeating-linear-gradient(135deg, var(--st-abnormal) 0 5px, var(--st-abnormal-bg) 5px 10px);
  border-radius: 8px 0 0 8px;
}

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  border: 2px solid var(--st-paused); color: var(--st-paused);
  background: var(--surface);
  font-size: .85rem; font-weight: 700;
}
.badge.manual { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- 凡例（常時表示） */

.legend {
  position: sticky; bottom: 0;
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
  margin-top: 22px; padding: 12px 16px;
  background: var(--surface);
  border-top: 2px solid var(--border);
}
.legend .title { font-weight: 700; }
.legend .item { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.legend .swatch {
  width: 26px; height: 20px; border-radius: 5px;
  border: 3px solid currentColor;
}
/* 見本はタイルと同じ色・同じ形にする。凡例と実物が違うと役に立たない。 */
.legend .item.st-running  { color: var(--st-running); }
.legend .item.st-paused   { color: var(--st-paused); }
.legend .item.st-abnormal { color: var(--st-abnormal); }
.legend .item.st-stopped  { color: var(--st-stopped); }
.legend .item.st-unknown  { color: var(--st-unknown); }
.legend .item.st-unknown .swatch { border-style: dashed; }
.legend .item.st-abnormal .swatch {
  background: repeating-linear-gradient(135deg, currentColor 0 4px, transparent 4px 8px);
}

/* ---------------------------------------------------------------- 絞り込み */

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: flex-end; }
.filters .f { flex: 0 1 190px; }
.filters label { margin: 0 0 4px; font-size: .95rem; }

/* ---------------------------------------------------------------- 掲示モード */

body.display-mode {
  --tile-min: 260px;
  --tile-name: 2.1rem;
  --tile-status: 1.9rem;
  font-size: 20px;
}
body.display-mode .topbar nav,
body.display-mode .filters,
body.display-mode .only-interactive { display: none !important; }
body.display-mode .tile { cursor: default; min-height: 190px; }
body.display-mode main { max-width: none; padding: 16px 20px 40px; }
body.display-mode .sum .n { font-size: 2.2rem; }

/* ---------------------------------------------------------------- 詳細・一覧 */

.back { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-weight: 700; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { font-weight: 700; color: var(--muted); }
.kv dd { margin: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; border: 2px solid currentColor; font-weight: 700; font-size: .9rem;
}
.chip.st-running  { color: var(--st-running); }
.chip.st-paused   { color: var(--st-paused); }
.chip.st-abnormal { color: var(--st-abnormal); }
.chip.st-stopped  { color: var(--st-stopped); }
.chip.st-unknown  { color: var(--st-unknown); }

.pill-ng { color: var(--st-abnormal); font-weight: 700; }
.pill-ok { color: var(--st-running); font-weight: 700; }

/* ---------------------------------------------------------------- 知らせ */

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
#toast .t {
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: 10px; font-weight: 700;
  box-shadow: var(--shadow); max-width: 90vw;
}
#toast .t.ng { background: var(--st-abnormal); color: #fff; }

/* ---------------------------------------------------------------- 狭い画面 */

@media (max-width: 640px) {
  :root { --tile-min: 150px; --tile-name: 1.3rem; --tile-status: 1.15rem; }
  main { padding: 14px 12px 60px; }
  .topbar { padding: 8px 12px; }
  .topbar h1 { font-size: 1.05rem; }
  .received { margin-left: 0; width: 100%; }

  /* メニューを折り返すと画面の上半分を占領してしまう。横に流して指でなぞれるようにする。 */
  .topbar nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: 0;
    width: 100%;
  }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a { flex: 0 0 auto; }

  /* 絞り込みは2列に。1列だと号機のタイルが画面の外へ押し出される。 */
  .filters .f { flex: 1 1 44%; }
  .filters .f:last-child { flex: 1 1 100%; }

  /* 凡例は必ず出しておきたいので、消さずに詰める */
  .legend { gap: 4px 12px; padding: 8px 12px; font-size: .95rem; }
  .legend .swatch { width: 22px; height: 16px; }
}
/* 34号機を見渡すため、スマートフォンでも2列を保つ。よほど狭い時だけ1列に落とす。 */
@media (max-width: 330px) {
  .tiles { grid-template-columns: 1fr; }
}

/* 印刷（掲示物として貼る場合） */
@media print {
  .topbar nav, .filters, .btn { display: none !important; }
  body { background: #fff; font-size: 12pt; }
  .tile { break-inside: avoid; box-shadow: none; }
}

/* ---------------------------------------------------------------- 工場ごとのまとまり */

.factory { margin-bottom: 26px; }

.factory-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 14px;
  margin: 0 0 10px;
  padding: 6px 0 8px;
  border-bottom: 3px solid var(--border-strong);
  font-size: 1.15rem;
}
.factory-name { font-weight: 800; font-size: 1.3rem; }
.factory-count { color: var(--muted); font-weight: 700; }
/* 見出しの内訳は右端へ。工場名と台数が先に目に入るようにする */
.factory-sum { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; }
.factory-sum .chip { font-size: .85rem; }

body.display-mode .factory-name { font-size: 1.7rem; }
body.display-mode .factory-head { border-bottom-width: 4px; }

@media (max-width: 640px) {
  .factory-name { font-size: 1.15rem; }
  .factory-sum { margin-left: 0; width: 100%; }
}

/* ---------------------------------------------------------------- 通知設定のチェック欄 */

.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 6px; }
.check {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; margin: 0; font-weight: 600; cursor: pointer;
}
.check input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
select[multiple] { min-height: 200px; padding: 6px; }
input[type=time] {
  min-height: 48px; padding: 8px 12px;
  border: 2px solid var(--border-strong); border-radius: 10px; background: var(--surface);
}

/* ---------------------------------------------------------------- 使用状況のバー */

.usage { margin: 0 0 18px; }
.usage-head { display: flex; align-items: baseline; gap: 10px; }
.usage-head span { margin-left: auto; font-weight: 700; }
.bar {
  height: 16px; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 2px solid var(--border-strong);
}
/* 帯の色だけに頼らないよう、数字（％）を必ず横に出している */
.bar i { display: block; height: 100%; background: var(--st-running); }
.bar i.over { background: var(--st-abnormal); }

/* ---------------------------------------------------------------- 親機・子機 */

.family {
  display: block;
  font-size: .88rem; font-weight: 700;
  padding: 2px 0;
}
.family .muted { font-weight: 400; }
/* 立場が一目で分かるよう、記号を前に置く（色だけに頼らない） */
.family.parent::before { content: "◤ "; }
.family.child::before  { content: "└ "; }

/* 子機は左に少し寄せて、親機とひと組に見えるようにする */
.tile.is-child { margin-left: 12px; }
@media (max-width: 640px) { .tile.is-child { margin-left: 6px; } }
