:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1c2024;
  --muted: #6b7280;
  --accent: #2563eb;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --ng: #b91c1c;
  --ng-bg: #fee2e2;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --log-bg: #12161c;
  --log-fg: #d8dee9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --border: #2b3038;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --accent: #60a5fa;
    --ok: #86efac;
    --ok-bg: #14351f;
    --ng: #fca5a5;
    --ng-bg: #3b1416;
    --warn: #fcd34d;
    --warn-bg: #3a2c0a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user { color: var(--muted); font-size: 13px; word-break: break-all; }

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 120px; }

section { margin-bottom: 32px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h2 { font-size: 14px; margin: 0; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }

.head-actions { display: flex; align-items: center; gap: 8px; }

/* ---- タブ ---- */

.tabs { border-top: 1px solid var(--border); }

.tabs-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 4px;
}

.tab {
  font: inherit;
  font-size: 14px;
  padding: 10px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab-on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---- 右上メニュー ---- */

.menu { position: relative; }

.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 30;
  display: grid;
  gap: 2px;
}

.menu-item {
  font: inherit;
  font-size: 14px;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu-item:hover { background: var(--bg); color: var(--accent); }

/* ---- 表示モード切替 ---- */

.modes {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.mode {
  font: inherit;
  font-size: 13px;
  padding: 4px 14px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mode-on { background: var(--accent); color: #fff; font-weight: 600; }

/* ---- 未取り込みのコミット一覧 ---- */

.commits { margin-top: 8px; font-size: 13px; }

.commits > summary {
  cursor: pointer;
  color: var(--muted);
  padding: 4px 0;
}
.commits > summary:hover { color: var(--accent); }

.commit-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0 0 0 12px;
  border-left: 2px solid var(--border);
  display: grid;
  gap: 10px;
}

.commit-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.commit-hash {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: var(--accent);
  flex: none;
}

.commit-subject { word-break: break-word; }
.commit-meta { font-size: 12px; }

.commit-body {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- 最終ビルド ---- */

.last-build {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  font-size: 13px;
  flex-wrap: wrap;
}

.cards { display: grid; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-name { font-weight: 600; font-size: 16px; }
.card-desc { color: var(--muted); font-size: 13px; }

.card-meta {
  margin-top: 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-size: 13px;
}
.card-meta dt { color: var(--muted); }
.card-meta dd { margin: 0; word-break: break-all; }

.card-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  font: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; font-size: 13px; padding: 5px 10px; color: var(--muted); }
/* 停止だけを選んだときのボタン。押す前に「いつもと違う」と気づけるようにする。 */
.btn-danger { background: var(--ng); border-color: var(--ng); color: #fff; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-ng { background: var(--ng-bg); color: var(--ng); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-run { background: var(--warn-bg); color: var(--warn); }

/* 認証が無効(RIG_DEV_USER)なことを常に見せる。
   通知欄と違って消えないよう、本文の先頭に固定で置く。 */
.dev-banner {
  background: var(--ng);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  padding: 6px 12px;
}

/* ---- デプロイ内容の選択 ---- */

.picker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.picker-label {
  color: var(--muted);
  font-size: 13px;
  min-width: 66px;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ブランチだけは排他選択なので select を使う。
   ただしブラウザ既定の見た目のままだと、隣に並ぶチップから浮く。
   矢印は appearance:none で消して三角を自前で描く(currentColor が使えるので
   ダークテーマでも色が追従する。画像を持ち込む必要もない)。 */
.branch-select {
  font: inherit;
  font-size: 13px;
  padding: 3px 28px 3px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background-color: transparent;
  color: var(--muted);
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 11px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.branch-select:hover { border-color: var(--accent); }
.branch-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* 一覧のほうは OS 側が描くので、色だけ読める値にしておく */
.branch-select option { color: var(--text); background: var(--surface); }

/* 既定以外を選んでいるときは色でも分かるようにする。
   注記は別に出しているが、**選択欄そのものが変わって見える**ほうが早い。 */
.branch-select-alt {
  border-color: var(--warn);
  background-color: var(--warn-bg);
  color: var(--warn);
  font-weight: 600;
}

.chip {
  font: inherit;
  font-size: 13px;
  padding: 3px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip-on {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.preview {
  margin: 10px 0 0;
  padding: 8px 12px;
  background: var(--log-bg);
  color: var(--log-fg);
  border-radius: 8px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

.alert {
  background: var(--ng-bg);
  color: var(--ng);
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  white-space: pre-wrap;
}

.history { display: grid; gap: 6px; }

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  flex-wrap: wrap;
}
.history-row:hover { border-color: var(--accent); }
.history-row .grow { flex: 1; }

.log-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: min(60vh, 520px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.18);
  z-index: 20;
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.log-body {
  flex: 1;
  margin: 0;
  padding: 12px 16px;
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-fg);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.hidden { display: none !important; }

.site-name { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 6px; }

.notice {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- フォーム ---- */

.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.field input,
.field select {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  width: 100%;
}
.field input:focus,
.field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.form-grid { display: grid; gap: 12px; }

/* ---- 現在／新規の取り違えを防ぐ ---- */
/* 欄が並んでいるだけだと「新しいものを2回」と読まれる。帯と色で分ける。 */

.field-group {
  display: grid;
  gap: 12px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border);
}

.field-group-new { border-left-color: var(--accent); }

.key { font-weight: 700; }
.key-now { color: var(--text); }
.key-new { color: var(--accent); }

.field small { font-size: 12px; line-height: 1.5; }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.btn-block { width: 100%; padding: 10px 14px; }

/* ---- 発行されたパスワードの表示 ---- */

.credential {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  flex-wrap: wrap;
}

.credential-value {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid currentColor;
  user-select: all;
  word-break: break-all;
}

.credential .btn { background: var(--surface); color: inherit; }

/* ---- ロゴ ---- */

.topbar h1 picture,
.login-card h1 picture { display: block; line-height: 0; }

.brand { display: block; height: 26px; width: auto; }

.login-logo { display: block; margin: 0 auto; width: auto; max-width: 220px; height: auto; }

/* ---- ダイアログ(ユーザー管理) ---- */

.dialog {
  width: min(840px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}
.dialog::backdrop { background: rgba(0,0,0,0.45); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.dialog-body {
  padding: 16px;
  overflow: auto;
  max-height: calc(86vh - 56px);
  display: grid;
  gap: 12px;
}

/* ---- ログイン画面 ---- */

.login-main {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
}
.login-card h1 { font-size: 18px; margin: 0; }
.login-card .alert { margin-bottom: 0; }

@media (max-width: 600px) {
  .card-actions { width: 100%; }
  .card-actions .btn { flex: 1; }
  .log-panel { height: 70vh; }
  .topbar-inner { flex-wrap: wrap; }
}
