/* 全体の基本色とフォントを定義する。 */
:root {
  color-scheme: light;
  font-family: Arial, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: #1f2937;
  background: #f4f6f8;
}

/* paddingとborderを幅計算に含め、テーブルやカードの幅崩れを防ぐ。 */
* {
  box-sizing: border-box;
}

/* ブラウザ既定の余白を消して、画面全体をアプリ領域として使う。 */
body {
  margin: 0;
}

/* ページ全体の余白を持つ外枠。 */
.shell {
  width: 100%;
  margin: 0 auto;
  padding: 24px 26px 48px;
}

/* タイトルと実行ボタンを横並びにする上部バー。 */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.25;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

h4 {
  font-size: 15px;
  margin: 16px 0 8px;
}

/* 実行状況の要約文は本文より控えめな色にする。 */
#summary {
  margin-top: 8px;
  color: #566171;
}

/* 通常の実行ボタン。最低サイズを固定して押しやすさを保つ。 */
button {
  min-width: 96px;
  min-height: 40px;
  border: 1px solid #1f6feb;
  border-radius: 6px;
  background: #1f6feb;
  color: white;
  font-size: 15px;
  cursor: pointer;
}

/* 実行中は押せないことが分かるようにカーソルと透明度を変える。 */
button:disabled {
  cursor: wait;
  opacity: 0.65;
}

/* サブ操作用の白背景ボタン。 */
.secondaryButton {
  min-width: auto;
  border-color: #c7d0dc;
  background: white;
  color: #1f2937;
}

.secondaryButton:hover {
  background: #f8fafc;
}

/* 閉じるボタンなど、記号だけを入れる正方形ボタン。 */
.iconButton {
  width: 40px;
  min-width: 40px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

/* 各情報ブロックの共通カード表現。 */
.panel {
  background: white;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 18px;
  margin-top: 14px;
}

/* 左に設定/ステップ、右に詳細結果を置く2カラムレイアウト。 */
.resultLayout {
  display: grid;
  grid-template-columns: 460px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

/* 実行ステップはスクロール中も見えるよう固定表示にする。 */
.sideColumn {
  position: sticky;
  top: 12px;
}

.mainColumn {
  min-width: 0;
}

/* 詳細カードを縦に並べる。 */
.detailList {
  display: grid;
  gap: 14px;
}

/* 成功した詳細カードは緑の左ボーダーで示す。 */
.detailCard.success {
  border-left: 5px solid #1a7f37;
}

/* 失敗した詳細カードは赤の左ボーダーで示す。 */
.detailCard.failed {
  border-left: 5px solid #d1242f;
}

/* 詳細タイトルと変数管理ボタンを横並びにする。 */
.detailTitleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.detailTitleRow h2 {
  margin-bottom: 0;
}

/* 変数管理ボタンはタイトル行に収まる小さめの操作にする。 */
.variableButton {
  min-height: 34px;
  padding: 0 14px;
  white-space: nowrap;
}

/* データがない状態のメッセージ色。 */
.emptyDetail {
  color: #566171;
}

/* 設定値のkey/value表示。 */
.kv {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px 18px;
  margin: 0;
}

.kv dt {
  color: #566171;
  white-space: nowrap;
}

.kv dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 実行ステップカードを縦に並べる。 */
.steps {
  display: grid;
  gap: 12px;
}

/* ステップカードの標準状態。左ボーダーは状態別に上書きする。 */
.step {
  border: 1px solid #d8dee6;
  border-left: 5px solid #8a96a8;
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.step.compact {
  padding: 12px;
}

.step.compact pre {
  max-height: 180px;
}

/* ステップ成功時の色。 */
.step.success {
  border-left-color: #1a7f37;
}

/* スキップまたは待機ステップの色。 */
.step.skipped {
  border-left-color: #bf8700;
}

/* 実行中ステップの色。 */
.step.running {
  border-left-color: #1f6feb;
}

/* 失敗ステップの色。 */
.step.failed {
  border-left-color: #d1242f;
}

/* 補足情報は主文より薄い色にする。 */
.meta {
  color: #566171;
  line-height: 1.55;
}

/* エラーJSONやレスポンス確認用のpre表示。 */
pre {
  max-height: 460px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 6px;
  background: #101828;
  color: #e5edf7;
  font-size: 13px;
  line-height: 1.5;
}

/* テーブルを縦横スクロール可能な枠に収める。 */
.tableWrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid #d8dee6;
  border-radius: 6px;
  margin-top: 8px;
}

/* 通常テーブルは最低幅を持たせ、列が潰れすぎないようにする。 */
table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: white;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #e5e9f0;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

/* ヘッダー行はスクロール時にも見えるようstickyにする。 */
th {
  position: sticky;
  top: 0;
  background: #eef2f7;
  color: #344054;
  font-weight: 700;
}

/* 通常テーブルのセルは長い値を折り返してカード外へ出さない。 */
td {
  overflow-wrap: anywhere;
}

/* 変数管理モーダルの背景オーバーレイ。 */
.modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.46);
}

/* hidden属性があるときはモーダル全体を非表示にする。 */
.modalOverlay[hidden] {
  display: none;
}

/* モーダル本体は横幅を広く取り、PLCパラメータ表を見やすくする。 */
.modalWindow {
  width: min(1680px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  background: white;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
}

/* モーダル上部のタイトル行。 */
.modalHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid #d8dee6;
}

.modalHeader h2 {
  margin-bottom: 6px;
}

/* モーダル本文はテーブルが大きくても内部スクロールできるようにする。 */
.modalBody {
  min-height: 180px;
  overflow: auto;
  padding: 18px;
}

/* 取得中や空結果の短い状態メッセージ。 */
.modalStatus {
  color: #566171;
}

/* PLCパラメータ表は画面高に合わせて縦スクロールさせる。 */
.modalTableWrap {
  max-height: calc(100vh - 220px);
  margin-top: 0;
}

/* PLCパラメータ表は列が多いため、通常テーブルより広い最低幅を持たせる。 */
.modalTableWrap table {
  min-width: 1500px;
}

/* モーダル内テーブルはユーザー要望により折り返さず横スクロールで見せる。 */
.modalTableWrap th,
.modalTableWrap td {
  white-space: nowrap;
}

/* 変数状態を表す丸アイコン。 */
.statusDot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
}

/* オンライン/正常状態は緑で表示する。 */
.statusDot.online {
  background: #1a7f37;
}

/* オフライン/異常状態は赤で表示する。 */
.statusDot.offline {
  background: #d1242f;
}

/* 狭い画面では1カラムにして、ボタンやモーダルも幅いっぱいにする。 */
@media (max-width: 640px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .detailTitleRow {
    align-items: stretch;
    flex-direction: column;
  }

  .kv {
    grid-template-columns: 1fr;
    gap: 4px;
  }

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

  .sideColumn {
    position: static;
  }

  .modalOverlay {
    padding: 10px;
  }

  .modalHeader {
    align-items: stretch;
    flex-direction: column;
  }

  .iconButton {
    width: 100%;
  }
}
