:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-alt: #f2f5f8;
  --text: #1a1a1a;
  --muted: #666666;
  --line: #cccccc;
  --line-soft: #e6e6e6;
  --primary: #006a5b;
  --primary-dark: #004c41;
  --link: #0031d8;
  --success: #197a4b;
  --danger: #ce0000;
  --warning: #927200;
  --info: #0031d8;
  --focus: #f9c642;
  --radius: 8px;
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Yu Gothic UI", sans-serif;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  letter-spacing: 0;
}

a { color: var(--link); text-decoration: underline; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

button, input, select, textarea { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
}

.global-nav {
  display: flex;
  gap: 4px;
  align-items: center;
  overflow-x: auto;
  flex: 1;
}

.global-nav a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

.global-nav a.active {
  border-bottom-color: var(--primary);
  font-weight: 700;
  color: var(--primary-dark);
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.logout-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
}

.logout-form button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

.status-dot.busy { background: var(--warning); }

.page {
  width: min(1440px, calc(100vw - 48px));
  margin: 24px auto 64px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 2rem;
  line-height: 1.3;
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-weight: 700;
}

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

.button {
  min-height: 44px;
  min-width: 96px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  line-height: 1;
}

.button.primary { background: var(--primary); color: #fff; }
.button.secondary { background: #fff; color: var(--primary-dark); }
.button.small { min-height: 36px; min-width: 72px; padding: 0 12px; }
.button[aria-busy="true"] { cursor: progress; opacity: .75; }

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.2rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric, .panel, .side-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.metric span { color: var(--muted); }
.metric strong { font-size: 2rem; line-height: 1.2; }
.metric.warning strong { color: var(--danger); }

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.layout-two {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
}

.panel { padding: 16px; margin-bottom: 24px; min-width: 0; }
.panel.narrow { max-width: 780px; }
.panel h2, .side-list h2 { margin: 0 0 16px; font-size: 1.25rem; line-height: 1.4; }

.section-title, .toolbar, .drawer-header, .form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-title { margin-bottom: 16px; }
.section-title h2 { margin: 0; }

.toolbar { margin-bottom: 16px; }
.search { display: grid; gap: 4px; max-width: 360px; width: 100%; }
.search span, .form-grid label span, .support, .muted { color: var(--muted); }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
}

textarea { min-height: 120px; resize: vertical; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); }
table { width: 100%; min-width: 720px; border-collapse: collapse; background: #fff; }
th, td { padding: 12px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
th { background: var(--surface-alt); font-weight: 700; color: var(--text); }
tbody tr:nth-child(even) { background: #fbfcfd; }
tbody tr:hover { background: #eef7f5; }
td form { margin: 0; }

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.status-passed { color: var(--success); border-color: #86c9a7; background: #edf8f2; }
.status-failed, .status-error { color: var(--danger); border-color: #f0a0a0; background: #fff1f1; }
.status-running, .status-queued { color: var(--warning); border-color: #d9bf65; background: #fff8df; }
.status-untested, .status-canceled { color: var(--muted); background: #f4f4f4; }
.priority-high, .priority-critical { color: var(--danger); background: #fff1f1; border-color: #f0a0a0; }
.priority-normal { color: var(--info); background: #eef3ff; border-color: #9cb6ff; }

.breadcrumbs {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
}
.breadcrumbs > * + *::before { content: "/"; color: var(--muted); margin-right: 8px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  overflow-x: auto;
}

.tabs a, .segmented a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
}

.tabs a.active {
  color: var(--primary-dark);
  border: 1px solid var(--line);
  border-bottom-color: #fff;
  background: #fff;
  font-weight: 700;
}

.tabs span {
  min-width: 28px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--line-soft);
}

.side-list { padding: 16px; align-self: start; }
.side-list { min-width: 0; width: 100%; }
.folder {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
}
.folder span:first-child { min-width: 0; overflow-wrap: anywhere; }
.folder.active, .folder:hover { background: #eef7f5; font-weight: 700; }

.definition {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px 16px;
  margin: 0;
}
.definition dt { font-weight: 700; color: var(--muted); }
.definition dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.steps, .logs { margin: 0; padding-left: 24px; }
.steps li { margin-bottom: 12px; }
.steps code { margin-right: 8px; }
.steps small { display: block; color: var(--muted); }
.executable-steps { display: grid; gap: 10px; padding-left: 0; list-style: none; }
.executable-steps li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.step-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.step-actions form { margin: 0; }

.logs { list-style: none; padding-left: 0; }
.logs li {
  display: grid;
  grid-template-columns: 160px 88px 1fr;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.logs p { margin: 0; }
.log-error span { color: var(--danger); font-weight: 700; }

.step-result-list {
  display: grid;
  gap: 10px;
}
.step-result {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.step-result.failed {
  border-color: #f0a0a0;
  background: #fffafa;
}
.step-result-head {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 88px 80px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-alt);
}
.step-result-index {
  display: inline-grid;
  place-items: center;
  min-height: 30px;
  border-radius: 6px;
  background: #eef7f5;
  color: var(--primary-dark);
  font-weight: 700;
}
.step-result-body {
  display: grid;
  gap: 8px;
  padding: 12px;
}
.step-result-body code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.step-result-body p { margin: 0; overflow-wrap: anywhere; }
.step-error { color: var(--danger); font-weight: 700; }

.artifact-list { margin: 0; padding-left: 20px; }
.artifact-list li { margin-bottom: 14px; }
.artifact-preview {
  display: block;
  margin-top: 8px;
  max-width: 420px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.artifact-preview img {
  display: block;
  width: 100%;
  height: auto;
}

.segmented {
  display: flex;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.segmented a { border-right: 1px solid var(--line); }
.segmented a:last-child { border-right: 0; }
.segmented a.active { background: var(--primary); color: #fff; font-weight: 700; }

.form-grid { display: grid; gap: 16px; }
.form-grid label { display: grid; gap: 6px; font-weight: 700; }
.form-grid label input, .form-grid label textarea, .form-grid label select { font-weight: 400; }
.form-actions { justify-content: end; margin-top: 8px; }

.builder-layout { display: grid; gap: 24px; }
.case-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.case-form-grid label { display: grid; gap: 6px; font-weight: 700; }
.case-form-grid label.wide { grid-column: 1 / -1; }
.case-form-grid input, .case-form-grid select, .case-form-grid textarea { font-weight: 400; }

.step-builder {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow-x: auto;
  background: #fff;
}
.step-row {
  display: grid;
  grid-template-columns: 54px minmax(160px, 190px) minmax(280px, 1.2fr) minmax(240px, 1fr) 56px;
  gap: 8px;
  align-items: center;
  min-width: 900px;
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
}
.step-row:last-child { border-bottom: 0; }
.step-row.step-head {
  min-height: 44px;
  color: var(--muted);
  background: var(--surface-alt);
  font-weight: 700;
}
.step-index {
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #eef7f5;
  color: var(--primary-dark);
  font-weight: 700;
}
.step-row input,
.step-row select {
  min-height: 40px;
  border-radius: 6px;
}
.builder-actions { margin-top: 16px; }

.recorder-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 24px;
}
.recorder-bookmark {
  display: grid;
  gap: 12px;
}
.recorder-bookmark .button {
  width: fit-content;
}
.recorder-bookmark textarea,
.recording-json {
  min-height: 220px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.875rem;
}
.check-line {
  display: flex !important;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px !important;
  min-height: 44px;
}
.check-line input {
  width: 20px;
  min-height: 20px;
}
.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.notice.error {
  border-color: #f0a0a0;
  background: #fff1f1;
  color: var(--danger);
}

.env-variable-list {
  display: grid;
  gap: 8px;
}
.env-variable-row {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(260px, 1.2fr) 100px 56px;
  gap: 8px;
  align-items: center;
}
.env-variable-head {
  min-height: 40px;
  padding: 0 8px;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  font-weight: 700;
}
.env-secret {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.env-secret input {
  width: 20px;
  min-height: 20px;
}
.env-card-list {
  display: grid;
  gap: 12px;
}
.env-card {
  display: grid;
  grid-template-columns: minmax(240px, .7fr) minmax(0, 1fr);
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fff;
}
.env-card h3 { margin: 0 0 4px; font-size: 1rem; }
.env-card p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.env-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.env-tags span {
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface-alt);
  overflow-wrap: anywhere;
}

.drawer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.28);
  z-index: 40;
}
.drawer[aria-hidden="false"] { display: block; }
.drawer-panel {
  width: min(520px, calc(100vw - 32px));
  height: 100%;
  margin-left: auto;
  background: #fff;
  border-left: 1px solid var(--line);
  padding: 24px;
  overflow-y: auto;
}
.drawer-header { margin-bottom: 24px; }
.drawer-header h2 { margin: 0; }

.footer {
  width: min(1440px, calc(100vw - 48px));
  margin: 0 auto 24px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #fbfcfa 0%, var(--bg) 100%);
}

.login-box {
  width: min(100%, 440px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.login-box h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  line-height: 1.4;
}

.login-lead {
  margin: 0 0 24px;
  color: var(--muted);
}

.login-error {
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid #f0a0a0;
  border-radius: var(--radius);
  background: #fff1f1;
  color: var(--danger);
}

@media (max-width: 900px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 8px; padding: 8px 16px; }
  .topbar-status { min-height: 32px; }
  .logout-form { width: 100%; justify-content: space-between; }
  .page, .footer { width: calc(100vw - 32px); }
  .page-header, .section-title, .toolbar { align-items: stretch; flex-direction: column; }
  .metrics, .split, .layout-two { grid-template-columns: minmax(0, 1fr); }
  .recorder-layout { grid-template-columns: minmax(0, 1fr); }
  .env-variable-row {
    grid-template-columns: minmax(0, 1fr) 44px;
    grid-template-areas:
      "key remove"
      "value value"
      "secret secret";
  }
  .env-variable-head { display: none; }
  .env-variable-row input[name="variable_key"] { grid-area: key; }
  .env-variable-row input[name="variable_value"] { grid-area: value; }
  .env-variable-row .env-secret { grid-area: secret; }
  .env-variable-row [data-remove-env-variable] { grid-area: remove; }
  .env-card { grid-template-columns: minmax(0, 1fr); }
  .case-form-grid { grid-template-columns: minmax(0, 1fr); }
  .step-builder { overflow-x: visible; }
  .step-row {
    min-width: 0;
    grid-template-columns: 42px minmax(0, 1fr) 44px;
    grid-template-areas:
      "index command remove"
      "target target target"
      "value value value";
  }
  .step-row.step-head { display: none; }
  .step-index { grid-area: index; }
  .step-row select[name="step_command"] { grid-area: command; }
  .step-row input[name="step_target"] { grid-area: target; }
  .step-row input[name="step_value"] { grid-area: value; }
  .step-row [data-remove-step] { grid-area: remove; }
  .definition { grid-template-columns: 1fr; }
  .executable-steps li { grid-template-columns: minmax(0, 1fr); }
  .step-actions { align-items: stretch; flex-direction: column; }
  .step-actions .button { width: 100%; }
  .step-result-head {
    grid-template-columns: 48px minmax(0, 1fr);
  }
  .global-nav, .tabs { max-width: 100%; }
  .side-list { overflow: hidden; }
  .logs li { grid-template-columns: 1fr; gap: 4px; }
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .button { width: 100%; }
  .table-wrap table { min-width: 760px; }
}

@media (prefers-reduced-motion: no-preference) {
  .drawer-panel { animation: drawer-in .18s ease-out; }
  @keyframes drawer-in { from { transform: translateX(24px); opacity: .8; } to { transform: translateX(0); opacity: 1; } }
}
