:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #18202a;
  --muted: #667281;
  --line: #d8dee7;
  --accent: #1466d8;
  --accent-2: #0f8b74;
  --danger: #b42318;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, .button { border: 0; background: var(--accent); color: white; padding: 9px 13px; border-radius: 7px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.secondary, .button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.summary-card { color: var(--text); text-align: left; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--text); padding: 9px 10px; }
textarea { resize: vertical; line-height: 1.45; }
label span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
pre { white-space: pre-wrap; overflow: auto; margin: 0; }
.hidden { display: none !important; }
.view { min-width: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 20px; }
.block { display: block; margin-top: 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }
.ok-text { color: #067647; }
.err-text { color: var(--danger); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; display: grid; gap: 16px; box-shadow: 0 18px 50px rgba(22, 34, 51, .08); }
.eyebrow { color: var(--accent-2); margin: 0 0 4px; font-size: 13px; font-weight: 700; }
.login h1 { margin: 0; font-size: 30px; letter-spacing: 0; }

.app { min-height: 100vh; min-width: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { min-width: 0; background: #101820; color: white; padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; }
.brand { display: grid; gap: 4px; padding: 0 8px; }
.brand span { color: #aeb8c5; font-size: 13px; }
.brand strong { font-size: 21px; }
nav { display: grid; gap: 6px; }
.nav { text-align: left; background: transparent; color: #d8dee7; border-radius: 7px; }
.nav { white-space: nowrap; }
.nav.active, .nav:hover { background: #25313f; color: white; }
.workspace { min-width: 0; padding: 22px; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
.topbar > div:first-child { min-width: 0; }
.topbar h2 { margin: 0 0 4px; }
.topbar p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.userbar { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.board { margin-bottom: 14px; }
.board-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 10px; }
.board-head h3 { margin: 0; font-size: 16px; }
.board-head p { margin: 3px 0 0; font-size: 12px; }
.board.collapsed .summary-grid { display: none; }
.board.collapsed .metric-grid { display: none; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.metric-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; display: grid; gap: 3px; min-width: 0; }
.metric-card span, .metric-card small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.metric-card strong { font-size: 20px; line-height: 1.15; overflow-wrap: anywhere; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 14px; }
.summary-card, .panel, .trace-panel, .table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.summary-card { padding: 12px; display: grid; gap: 7px; min-height: 112px; }
.summary-card strong { display: block; font-size: 22px; margin-top: 4px; }
.summary-title { font-weight: 700; overflow-wrap: anywhere; }
.summary-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.alias-pill { display: inline-flex; width: fit-content; max-width: 100%; align-items: center; border: 1px solid #e4c876; background: #fff8df; color: #806000; border-radius: 999px; padding: 2px 7px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filters { display: grid; grid-template-columns: 180px 150px 180px minmax(180px, 1fr) 150px 90px; gap: 10px; align-items: center; margin-bottom: 14px; }
.checkbox { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.checkbox input { width: auto; }
.table-wrap { min-width: 0; max-width: 100%; overflow: auto; max-height: calc(100vh - 230px); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; background: #fbfcfe; position: sticky; top: 0; }
tr { cursor: pointer; }
tr:hover, tr.selected { background: #f5f8fc; }
.badge { display: inline-block; padding: 3px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.badge.ok { color: #067647; background: #ecfdf3; }
.badge.err { color: #b42318; background: #fef3f2; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 18, 28, .24); z-index: 20; }
.trace-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, calc(100vw - 32px)); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -18px 0 46px rgba(16, 24, 40, .18); z-index: 21; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0 0 4px; }
.drawer-head p { margin: 0; overflow-wrap: anywhere; }
.drawer-body { min-height: 0; overflow: auto; padding: 16px; }
.trace-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.trace-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.trace-kpis div { border: 1px solid var(--line); border-radius: 7px; padding: 10px; background: #fbfcfe; min-width: 0; }
.trace-kpis span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.trace-kpis strong { font-size: 16px; overflow-wrap: anywhere; }
.trace-timeline { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.timeline-step { border: 1px solid var(--line); border-radius: 7px; padding: 10px; display: grid; gap: 4px; background: #fbfcfe; min-width: 0; }
.timeline-step span { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.timeline-step strong, .timeline-step small { overflow-wrap: anywhere; }
.timeline-step small { color: var(--muted); }
.timeline-step.done span { background: #e6f4ef; color: #067647; }
.timeline-step.failed span { background: #fef3f2; color: var(--danger); }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.trace-panel { padding: 14px; max-height: calc(100vh - 230px); overflow: auto; }
.trace-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.trace-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kv { background: var(--surface-2); border-radius: 7px; padding: 8px; font-size: 12px; }
.kv span { display: block; color: var(--muted); margin-bottom: 3px; }
.payload-section { margin-top: 14px; }
.payload-section h4 { margin: 0 0 8px; }
.payload-section summary, details summary { cursor: pointer; font-weight: 700; margin-bottom: 8px; }
.message { border: 1px solid var(--line); border-radius: 7px; padding: 10px; margin-bottom: 10px; background: #fbfcfe; }
.message-role { color: var(--accent); font-weight: 700; margin-bottom: 6px; }
.ai-image { max-width: 100%; border: 1px solid var(--line); border-radius: 7px; margin: 8px 0; display: block; }
.drawer-body .ai-image { width: min(100%, 240px); max-height: 170px; object-fit: contain; background: white; }
.users-head { margin-bottom: 12px; }
.users-toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) 170px; gap: 10px; }
#usersSummary.metric-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.users-table-wrap { max-height: calc(100vh - 300px); }
.users-table { min-width: 1180px; }
.users-table td:first-child, .users-table th:first-child { min-width: 240px; }
.user-drawer { width: min(920px, calc(100vw - 32px)); }
.user-section { display: grid; gap: 10px; margin-top: 18px; }
.user-section h4 { margin: 0; font-size: 14px; }
.membership-form { display: grid; gap: 12px; }
.compact-table-wrap { max-height: 320px; border-radius: 7px; }
.compact-table { min-width: 680px; }
.compact-table tr { cursor: default; }
.compact-table tr[data-request-id] { cursor: pointer; }
.timeline-list { display: grid; gap: 8px; }
.timeline-item { border: 1px solid var(--line); border-radius: 7px; background: #fbfcfe; padding: 10px; display: grid; gap: 5px; }
.timeline-item > div { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.timeline-item p { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.timeline-item small { color: var(--muted); }
.two-col { display: grid; grid-template-columns: minmax(360px, 460px) minmax(0, 1fr); gap: 14px; align-items: start; }
.playground-shell { display: grid; grid-template-columns: minmax(520px, 1fr) minmax(340px, 430px); grid-template-areas: "source source" "editor params" "editor result"; gap: 14px; align-items: start; }
.playground-studio { display: grid; grid-template-columns: minmax(260px, 320px) minmax(420px, 1.1fr) minmax(340px, .9fr); grid-template-areas: "command command command" "left editor params" "left compare params" "left preview result"; gap: 14px; align-items: start; }
.pg-command-panel { grid-area: command; }
.pg-left-rail { grid-area: left; position: sticky; top: 12px; max-height: calc(100vh - 110px); overflow: auto; }
.pg-source-panel { grid-area: source; }
.pg-editor-panel { grid-area: editor; }
.pg-params-panel { grid-area: params; }
.pg-compare-panel { grid-area: compare; }
.pg-preview-panel { grid-area: preview; min-height: 280px; }
.pg-result-panel { grid-area: result; min-height: 320px; }
.message-editor-list { display: grid; gap: 12px; }
.message-editor-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfe; padding: 12px; display: grid; gap: 10px; }
.message-editor-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.message-editor-head select { width: 150px; }
.message-editor-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.message-editor-actions button { padding: 6px 8px; font-size: 12px; }
.message-image-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.variable-list { display: grid; gap: 10px; }
.run-history { display: grid; gap: 8px; }
.run-history-item { color: var(--text); text-align: left; background: #fbfcfe; border: 1px solid var(--line); border-radius: 7px; padding: 9px; display: grid; gap: 3px; }
.run-history-item small { color: var(--muted); overflow-wrap: anywhere; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.result-grid article { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfe; padding: 12px; min-width: 0; }
.result-grid h4 { margin: 0 0 8px; }
.panel { min-width: 0; padding: 16px; display: grid; gap: 13px; }
.panel h3 { margin: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; min-width: 0; }
.panel-head > div { min-width: 0; }
.panel-head p { margin: 4px 0 0; overflow-wrap: anywhere; word-break: break-all; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.narrow { max-width: 520px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.inline-head { display: grid; gap: 8px; }
.inline-head > span { color: var(--muted); font-size: 12px; }
.inline-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 8px; }
.image-chip { border: 1px solid var(--line); border-radius: 7px; padding: 8px; background: #fbfcfe; display: grid; gap: 8px; }
.image-chip img { width: 100%; max-height: 160px; object-fit: contain; background: white; border: 1px solid var(--line); border-radius: 6px; }
.image-chip.compact img { max-height: 96px; }
.prompt-workspace { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 14px; align-items: start; }
.prompt-list-screen { display: grid; gap: 14px; }
.prompt-library-head { display: grid; gap: 12px; }
.prompt-search-row { max-width: 560px; }
.prompt-table-wrap { max-height: calc(100vh - 260px); }
.prompt-table { min-width: 980px; }
.prompt-table th, .prompt-table td { vertical-align: middle; }
.prompt-key-cell { font-weight: 700; white-space: nowrap; }
.prompt-description-cell { min-width: 220px; color: var(--muted); }
.empty-state { padding: 14px; }
.prompt-list { display: grid; gap: 10px; }
.prompt-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.prompt-detail { min-height: calc(100vh - 150px); }
.prompt-detail h3, #promptDetailSubtitle { overflow-wrap: anywhere; }
.prompt-studio-screen { display: grid; gap: 12px; }
.prompt-studio-screen > button { width: fit-content; }
.prompt-studio-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(270px, 360px); gap: 14px; align-items: start; }
.release-state { border: 1px solid var(--line); border-radius: 7px; background: #fbfcfe; padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.version-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.version-strip.vertical { display: grid; gap: 8px; }
.version-btn { display: inline-grid; gap: 2px; }
.version-btn span { font-size: 11px; color: var(--muted); }
.version-strip.vertical .version-btn { justify-content: stretch; text-align: left; }
.version-btn.active { border-color: var(--accent); color: var(--accent); background: #eef5ff; }
.prompt-editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); gap: 14px; align-items: start; }
.prompt-editor-main { display: grid; gap: 13px; }
.prompt-version-panel { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfe; padding: 12px; display: grid; gap: 8px; }
.prompt-version-panel h4 { margin: 0; font-size: 14px; }
.version-meta { display: grid; gap: 8px; }
.prompt-side-panel { position: sticky; top: 12px; max-height: calc(100vh - 110px); overflow: auto; }
.docs-head { margin-bottom: 12px; }
.docs-frame { width: 100%; height: calc(100vh - 184px); min-height: 620px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 18, 28, .36); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal-panel { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 22px 70px rgba(16, 24, 40, .24); padding: 18px; display: grid; gap: 13px; }
.membership-modal-panel { width: min(680px, 100%); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title-row h4 { margin: 0; }

@media (max-width: 1280px) {
  .filters { grid-template-columns: 1fr 1fr 1fr; }
  .playground-studio {
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
    grid-template-areas:
      "command command"
      "left editor"
      "left params"
      "left compare"
      "preview result";
  }
  .pg-preview-panel, .pg-result-panel { min-height: 240px; }
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .app { width: 100vw; max-width: 100vw; overflow-x: hidden; }
  .workspace { width: 100vw; max-width: 100vw; overflow-x: hidden; }
  .sidebar { position: sticky; top: 0; z-index: 2; width: 100%; max-width: 100vw; flex-direction: row; align-items: center; overflow-x: auto; }
  nav { min-width: 0; display: flex; }
  .two-col, .prompt-workspace, .prompt-editor-grid, .prompt-studio-shell { grid-template-columns: 1fr; }
  .playground-shell { grid-template-columns: 1fr; grid-template-areas: "source" "editor" "params" "result"; }
  .playground-studio { grid-template-columns: 1fr; grid-template-areas: "command" "left" "editor" "params" "compare" "preview" "result"; }
  .pg-left-rail, .prompt-side-panel { position: static; max-height: none; }
  .metric-grid, .metric-grid.compact, .trace-kpis, .trace-timeline { grid-template-columns: 1fr 1fr; }
  #usersSummary.metric-grid.compact { grid-template-columns: 1fr 1fr; }
  .users-toolbar { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .form-grid, .form-grid.four { grid-template-columns: 1fr; }
  .form-grid.two { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: 1fr; }
  .trace-drawer { width: min(100vw, 720px); }
  .user-drawer { width: min(100vw, 920px); }
  .topbar { align-items: flex-start; flex-direction: column; }
  .panel-head { flex-direction: column; }
  .panel-actions { justify-content: flex-start; }
  .message-editor-head { align-items: stretch; flex-direction: column; }
}

@media (max-width: 520px) {
  .workspace { padding: 18px 14px; }
  .sidebar { gap: 12px; }
  .brand { flex: 0 0 auto; }
  #usersSummary.metric-grid.compact, .metric-grid, .metric-grid.compact, .trace-kpis, .trace-timeline { grid-template-columns: 1fr; }
  .userbar { flex-wrap: wrap; }
}
