:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --line: #d7dce3;
  --accent: #0b63ce;
  --accent-soft: #e8f1ff;
  --danger: #b42318;
  --success: #14753f;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", sans-serif;
  line-height: 1.55;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--text);
  color: #ffffff;
  font-family: "JetBrains Mono", monospace;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

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

.nav-item {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
}

.nav-item.active {
  border-color: #b9d3ff;
  background: var(--accent-soft);
  color: #063f86;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-family: "Bricolage Grotesque", "Noto Sans JP", sans-serif;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
}

.file-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.api-input,
.token-input,
.file-button,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.api-input,
.token-input {
  width: min(320px, 42vw);
  justify-content: flex-start;
  padding: 0 12px;
}

.token-input {
  width: min(180px, 28vw);
}

.file-button,
.action-button {
  padding: 0 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.action-button {
  border-color: #9dc4ff;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

.metric {
  min-height: 104px;
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 30px;
  line-height: 1.1;
}

#metricReadiness {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

#metricOpsStage,
#metricOpsReady {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 180px 1fr 128px;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  font-size: 14px;
}

.bar-label {
  color: var(--text);
}

.bar-track {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #edf0f4;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.bar-value {
  text-align: right;
  font-family: "JetBrains Mono", monospace;
}

.table-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search,
.select,
.text-input,
.textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.textarea {
  min-height: 88px;
  padding: 10px 12px;
  resize: vertical;
}

.search {
  flex: 1;
  min-width: 220px;
}

.review-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) minmax(160px, 1fr);
  gap: 8px;
}

.review-form .textarea {
  grid-column: span 3;
}

.hidden {
  display: none;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #fafbfc;
  color: var(--muted);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #063f86;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.badge.guard {
  background: #edf8f2;
  color: var(--success);
}

.badge.human {
  background: #fff0ee;
  color: var(--danger);
}

.badge.sent {
  background: var(--accent-soft);
  color: #063f86;
}

.small-button {
  min-height: 32px;
  border: 1px solid #9dc4ff;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #063f86;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.mono {
  font-family: "JetBrains Mono", monospace;
}

.clip {
  max-width: 440px;
  white-space: pre-wrap;
}

.failure-list {
  display: grid;
  gap: 8px;
}

.failure-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.ops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 16px;
}

.ops-next {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  padding: 14px;
  overflow-wrap: anywhere;
}

.mode-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.45fr) minmax(0, 1fr);
  gap: 12px;
}

.mode-control,
.mode-command {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  padding: 12px;
}

.mode-control {
  display: grid;
  gap: 8px;
}

.mode-control span,
.mode-command strong {
  color: var(--muted);
  font-size: 13px;
}

.mode-command code {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.check-list,
.kv-list {
  display: grid;
  gap: 8px;
}

.check-item,
.kv-item {
  display: grid;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.check-item {
  grid-template-columns: 88px minmax(0, 1fr) minmax(120px, 0.6fr);
}

.check-item strong,
.check-item em,
.kv-item span {
  overflow-wrap: anywhere;
}

.check-item em {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-style: normal;
}

.kv-item {
  grid-template-columns: 120px minmax(0, 1fr);
}

.kv-item strong {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar,
  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .file-controls {
    justify-content: stretch;
  }

  .api-input,
  .token-input,
  .file-button,
  .action-button,
  .text-input,
  .select {
    width: 100%;
  }

  .review-form {
    grid-template-columns: 1fr;
  }

  .review-form .textarea {
    grid-column: auto;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .check-item,
  .kv-item {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 12px;
  }

  .bar-value {
    text-align: left;
  }
}
