:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --panel: #ffffff;
  --panel-soft: #f0f4f1;
  --ink: #1c2420;
  --muted: #65716a;
  --line: #d7ddd6;
  --accent: #126d55;
  --accent-ink: #ffffff;
  --teal-soft: #dcefeb;
  --amber: #9c6217;
  --error: #a5332d;
  --error-bg: #fff1ef;
  --code-bg: #111815;
  --code-ink: #d9f4e8;
  --shadow: 0 14px 34px rgba(34, 48, 42, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body.auth-gate-open {
  overflow: hidden;
}

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

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(246, 247, 243, 0.92);
  backdrop-filter: blur(6px);
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(34, 48, 42, 0.18);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.2;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.auth-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.auth-code-row .field {
  margin-bottom: 0;
}

.auth-submit-button {
  width: 100%;
}

.auth-status {
  min-height: 22px;
}

.auth-status[data-tone="ok"] {
  color: var(--accent);
}

.auth-status[data-tone="error"] {
  color: var(--error);
}

.auth-user-pill {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #b9d8cf;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.auth-user-pill span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-user-pill button {
  height: 28px;
  padding: 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.environment-notice {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.environment-notice[data-tone="dev"] {
  border-color: #b9d8cf;
  background: var(--teal-soft);
  color: var(--accent);
}

.environment-notice[data-tone="readonly"] {
  border-color: #e7c899;
  background: #fff7e8;
  color: var(--amber);
}

.environment-notice[data-tone="prod"] {
  border-color: #f1b2ad;
  background: var(--error-bg);
  color: var(--error);
}

.section-title-row h2,
.section-title-row h3 {
  margin: 0;
  letter-spacing: 0;
}

.request-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.input-panel > .section-title-row {
  display: flex;
  align-items: center;
}

.input-panel > .section-title-row .request-actions {
  margin-left: auto;
}

.prompt-name-publish-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  margin-bottom: 13px;
}

.prompt-name-field {
  min-width: 0;
  margin-bottom: 0;
}

.prompt-publish-menu {
  position: relative;
  z-index: 8;
  justify-self: end;
  margin-top: calc(12px * 1.2 + 7px);
}

.publish-menu-button {
  min-width: 86px;
  height: 38px;
  padding: 0 16px;
  border-color: #b9d8cf;
  background: var(--teal-soft);
  color: var(--accent);
  font-weight: 800;
}

.publish-menu-button::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 7px;
  border-top: 5px solid currentColor;
  border-right: 5px solid transparent;
  border-left: 5px solid transparent;
  vertical-align: middle;
}

.publish-menu-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.publish-menu-panel {
  position: absolute;
  top: 100%;
  right: 0;
  left: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 168px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px rgba(34, 48, 42, 0.16);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(0);
  transition: opacity 140ms ease, transform 140ms ease;
}

.publish-menu-panel button {
  white-space: nowrap;
}

.prompt-publish-menu:hover .publish-menu-panel,
.prompt-publish-menu:focus-within .publish-menu-panel {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: translateY(0);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(420px, 1fr) minmax(360px, 0.9fr);
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 34px) 28px;
  align-items: start;
}

.case-panel,
.input-panel,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.case-panel,
.input-panel,
.result-panel {
  padding: 16px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  margin-bottom: 14px;
}

.section-title-row h2,
.section-title-row h3 {
  font-size: 15px;
  line-height: 1.2;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.request-form {
  display: contents;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 20px;
}

.field span,
.field-title-row > label:first-child,
.range-field span,
.number-field span,
.check-row span,
.thinking-field > span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 16px,
    calc(100% - 12px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

textarea {
  min-height: 120px;
  resize: vertical;
  padding: 10px;
  line-height: 1.5;
}

.markdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  user-select: none;
}

.markdown-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.markdown-preview {
  min-height: 120px;
  overflow: visible;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 14px;
  cursor: default;
  font-size: 14px;
  line-height: 1.6;
}

.markdown-preview > :first-child {
  margin-top: 0;
}

.markdown-preview > :last-child {
  margin-bottom: 0;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 {
  margin: 1em 0 0.45em;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.25;
}

.markdown-preview h1 {
  font-size: 22px;
}

.markdown-preview h2 {
  font-size: 18px;
}

.markdown-preview h3 {
  font-size: 16px;
}

.markdown-preview h4,
.markdown-preview p,
.markdown-preview li,
.markdown-preview table {
  font-size: 14px;
}

.markdown-preview p {
  margin: 0.65em 0;
}

.markdown-preview ul,
.markdown-preview ol {
  margin: 0.65em 0;
  padding-left: 1.35em;
}

.markdown-preview blockquote {
  margin: 0.8em 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--panel-soft);
  color: var(--muted);
}

.markdown-preview code {
  border-radius: 4px;
  background: #eef3ef;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.markdown-preview pre {
  overflow: auto;
  margin: 0.8em 0;
  border-radius: 7px;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 12px;
}

.markdown-preview pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.markdown-preview table {
  display: block;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
}

.markdown-preview th,
.markdown-preview td {
  border: 1px solid var(--line);
  padding: 7px 9px;
  text-align: left;
}

.markdown-preview th {
  background: var(--panel-soft);
  font-weight: 800;
}

.markdown-empty {
  color: var(--muted);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 109, 85, 0.13);
}

.control-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  margin-top: 4px;
}

.check-row,
.thinking-field,
.range-field,
.number-field {
  display: grid;
  gap: 7px;
  min-height: 62px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.thinking-field {
  min-width: 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  min-height: 34px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
}

.segmented-control label {
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.segmented-control input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(18, 109, 85, 0.16);
}

.segmented-control input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
}

.range-field {
  grid-template-columns: 1fr 42px;
}

.range-field span,
.range-field input {
  grid-column: 1 / 2;
}

.range-field output {
  grid-row: 1 / 3;
  grid-column: 2 / 3;
  align-self: center;
  justify-self: end;
  color: var(--accent);
  font-weight: 700;
}

.range-field input {
  padding: 0;
  height: 24px;
  accent-color: var(--accent);
}

.number-field input {
  height: 32px;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.primary-button,
.compact-button,
.icon-button,
.case-item button,
.wide-button,
.library-tab,
.prompt-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
}

.primary-button {
  min-width: 92px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.compact-button {
  min-width: 82px;
}

.wide-button {
  width: 100%;
  margin-bottom: 10px;
}

.icon-button {
  width: 38px;
  padding: 0;
}

button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.primary-button svg path {
  fill: currentColor;
  stroke: none;
}

.case-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 230px);
  overflow: auto;
  padding-right: 2px;
}

.library-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
}

.library-tab {
  min-width: 0;
  font-size: 13px;
}

.library-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--teal-soft);
  font-weight: 700;
}

.library-status {
  min-height: 34px;
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfa;
  font-size: 12px;
  line-height: 1.4;
}

.library-status[data-tone="ok"] {
  color: var(--accent);
  border-color: #b9d8cf;
  background: var(--teal-soft);
}

.library-status[data-tone="error"] {
  color: var(--error);
  border-color: #f0b2ad;
  background: var(--error-bg);
}

.case-item {
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 7px;
}

.case-item button {
  min-width: 0;
  height: 36px;
}

.case-load {
  justify-content: flex-start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-delete {
  padding: 0;
}

.prompt-item {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.prompt-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 109, 85, 0.1);
}

.prompt-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.prompt-meta strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-meta span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.prompt-action-button {
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.prompt-action-button.danger {
  color: var(--error);
}

.empty-cases {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.badge {
  min-width: 74px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.badge.dirty {
  background: #fff8ea;
  color: var(--amber);
}

.badge.archived {
  background: var(--error-bg);
  color: var(--error);
}

.error-box {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #f0b2ad;
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error);
  line-height: 1.45;
  font-size: 13px;
}

.current-run-anchor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.current-run-anchor > div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px;
  border: 1px solid #b9d8cf;
  border-radius: 8px;
  background: var(--teal-soft);
}

.current-run-anchor span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.current-run-anchor strong {
  overflow: hidden;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.right-panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}

.right-panel-tab {
  height: 36px;
  font-size: 13px;
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.right-panel-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--teal-soft);
  font-weight: 800;
}

.right-workspace-panel {
  display: none;
}

.right-workspace-panel.active {
  display: block;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}

.tab-button {
  height: 34px;
  font-size: 13px;
}

.tab-button.active {
  border-color: #b99459;
  color: var(--amber);
  background: #fff8ea;
  font-weight: 700;
}

.output-block {
  display: none;
  min-height: 560px;
  max-height: calc(100vh - 230px);
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-ink);
  overflow: auto;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
}

.output-block.active {
  display: block;
}

.follow-up-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.compact-row {
  min-height: 24px;
  margin-bottom: 0;
}

.follow-up-panel textarea {
  min-height: 92px;
  margin: 0;
}

.follow-up-actions {
  display: flex;
  justify-content: flex-end;
}

.run-history-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.history-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-align: right;
}

.history-status[data-tone="ok"] {
  color: var(--accent);
}

.history-status[data-tone="error"] {
  color: var(--error);
}

.run-history-list {
  display: grid;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.history-group {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
}

.history-group-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfa;
  font-size: 13px;
  line-height: 1.45;
}

.run-history-item {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 86px;
  padding: 10px;
  text-align: left;
  background: #fbfcfa;
  border-radius: 8px;
}

.run-history-item:hover,
.run-history-item:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 109, 85, 0.1);
  outline: none;
}

.run-history-item[data-tone="error"] {
  border-color: #f0b2ad;
}

.history-item-top,
.history-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.history-item-top strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-pill {
  flex: 0 0 auto;
  min-width: 48px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.run-history-item[data-tone="error"] .history-pill {
  background: var(--error-bg);
  color: var(--error);
}

.history-item-meta,
.history-item-preview {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.history-item-preview {
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-item-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(28, 36, 32, 0.36);
}

.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 41;
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(640px, 44vw);
  min-width: 360px;
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 34px rgba(34, 48, 42, 0.16);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.agent-version-guide-button {
  min-width: 196px;
  border-color: #b9d8cf;
  background: var(--teal-soft);
  color: var(--accent);
  font-weight: 800;
}

.drawer-header h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.drawer-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.drawer-content {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.history-detail-section {
  display: grid;
  gap: 8px;
}

.history-share-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #b9d8cf;
  border-radius: 8px;
  background: var(--teal-soft);
}

.history-share-card h3 {
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
}

.history-share-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.history-share-card p[data-tone="ok"] {
  color: var(--accent);
}

.history-share-card p[data-tone="error"] {
  color: var(--error);
}

.history-share-card > a {
  overflow-wrap: anywhere;
  color: var(--accent);
  font-size: 12px;
  line-height: 1.4;
}

.history-share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.detail-section-title h3 {
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
}

.copy-button {
  height: 30px;
  padding: 0 10px;
  color: var(--accent);
  font-size: 12px;
}

.history-detail-block {
  min-height: 96px;
  max-height: 260px;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-ink);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.version-prompt-details-toggle {
  width: 100%;
  height: 36px;
  margin-bottom: 14px;
  border-color: var(--line);
  background: #fbfcfa;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.version-prompt-details {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.version-prompt-details[hidden] {
  display: none;
}

.use-cases-panel {
  display: grid;
  gap: 10px;
}

.use-cases-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 190px);
  overflow: auto;
  padding-right: 2px;
}

.use-case-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.use-case-item:hover {
  border-color: #b9d8cf;
}

.use-case-item-header,
.use-case-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.use-case-item-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.use-case-type-pill {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}

.use-case-item-meta {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.use-case-preview {
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  min-height: 52px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.use-case-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.use-case-actions .danger {
  color: var(--error);
}

.agent-access-panel {
  display: grid;
  gap: 10px;
}

.agent-publish-actions,
.agent-version-filters,
.agent-version-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-publish-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.agent-version-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.agent-versions-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 240px);
  overflow: auto;
  padding-right: 2px;
}

.agent-version-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  cursor: pointer;
}

.agent-version-card:hover,
.agent-version-card:focus-visible {
  border-color: #b9d8cf;
  outline: none;
  box-shadow: 0 0 0 3px rgba(65, 124, 102, 0.12);
}

.agent-version-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.agent-version-card-badges {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.agent-version-run-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}

.agent-version-title,
.agent-version-prompt-name {
  overflow: hidden;
  display: block;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-version-title {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.agent-version-prompt-name,
.agent-version-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.agent-version-actions {
  display: grid;
  grid-template-columns: minmax(72px, 0.7fr) minmax(150px, 1.5fr) minmax(72px, 0.7fr);
  gap: 7px;
}

.agent-version-actions .danger {
  color: var(--error);
}

.agent-version-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.agent-version-summary > div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.agent-version-summary span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.agent-version-summary strong {
  overflow: hidden;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-version-drawer {
  width: min(700px, 48vw);
}

.agent-run-drawer {
  right: min(700px, 48vw);
  z-index: 42;
  width: min(620px, 38vw);
  box-shadow: -18px 0 34px rgba(34, 48, 42, 0.2);
}

.use-case-form {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.use-case-content-field {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  margin-bottom: 0;
}

.use-case-content-field textarea {
  height: 100%;
  min-height: 360px;
}

.use-case-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(240px, 0.8fr) minmax(520px, 1.4fr);
  }

  .result-panel {
    grid-column: 1 / -1;
  }

  .output-block {
    min-height: 360px;
  }

  .history-drawer {
    width: min(680px, 72vw);
  }

  .agent-version-drawer {
    width: min(680px, 72vw);
  }

  .agent-run-drawer {
    right: min(680px, 72vw);
    width: min(560px, 46vw);
  }
}

@media (max-width: 820px) {
  .workspace,
  .field-grid,
  .control-strip {
    grid-template-columns: 1fr;
  }

  .case-panel,
  .input-panel,
  .result-panel {
    padding: 14px;
  }

  .input-panel > .section-title-row {
    align-items: stretch;
  }

  .prompt-name-publish-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .prompt-publish-menu {
    justify-self: stretch;
    margin-top: 0;
  }

  .publish-menu-button {
    width: 100%;
  }

  .publish-menu-panel {
    left: 0;
    right: 0;
    min-width: 0;
    transform: translateY(0);
  }

  .request-actions {
    justify-content: stretch;
  }

  .request-actions > * {
    flex: 1 1 110px;
  }

  .case-list {
    max-height: 240px;
  }

  .output-block {
    min-height: 320px;
    max-height: 520px;
  }

  .history-item-top,
  .history-item-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-status {
    text-align: left;
  }

  .current-run-anchor {
    grid-template-columns: 1fr;
  }

  .current-run-anchor strong,
  .history-group-title,
  .history-item-title {
    white-space: normal;
  }

  .history-drawer {
    width: 100vw;
    min-width: 0;
  }

  .agent-version-drawer,
  .agent-run-drawer {
    right: 0;
    width: 100vw;
    min-width: 0;
  }

  .agent-run-drawer {
    z-index: 43;
  }

  .drawer-content {
    padding: 14px;
  }

  .history-detail-block {
    max-height: 220px;
  }

  .use-cases-list {
    max-height: 520px;
  }

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

  .agent-publish-actions,
  .agent-version-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .use-case-item-header,
  .use-case-item-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .use-case-item-title {
    white-space: normal;
  }

  .drawer-header-actions {
    flex-direction: column-reverse;
    align-items: flex-end;
  }
}
