/* OpenAI API Desk — styles
   Structure: 1 tokens · 2 base · 3 layout · 4 shared components · 5 panel · 6 chat · 7 inspector · 8 composer · 9 markdown · 10 responsive */

/* ---------- 1. Tokens ---------- */
:root {
  --panel-w: 380px;

  --bg: #ffffff;          /* main canvas */
  --panel: #f9f9f9;       /* sidebar */
  --surface: #f4f4f4;     /* inputs, cards, code blocks */
  --surface-2: #ececec;   /* chips, code headers, inline code (one step darker) */
  --border: #e5e5e5;
  --border-strong: #d4d4d4;

  --text: #0d0d0d;
  --muted: #676767;
  --faint: #8e8e8e;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --ok: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;

  --tk-comment: #6b7280;
  --tk-string: #15803d;
  --tk-number: #b45309;
  --tk-keyword: #2563eb;
  --tk-key: #4f46e5;

  color-scheme: light;
  --radius: 8px;
  --radius-lg: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
body.resizing { cursor: col-resize; user-select: none; }
button, input, select, textarea { font: inherit; color: inherit; }
pre { margin: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* off-screen textarea used only by the clipboard fallback */
.sr-copy { position: fixed; top: 0; left: 0; opacity: 0; pointer-events: none; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1 1 0; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 3. Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--panel-w) 7px minmax(0, 1fr);
  height: 100dvh;
}
.panel {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--panel);
}
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
}
.resizer {
  cursor: col-resize;
  background: linear-gradient(var(--border), var(--border)) center / 1px 100% no-repeat;
  touch-action: none;
}
.resizer:hover, .resizer:focus-visible, body.resizing .resizer {
  background: linear-gradient(var(--accent), var(--accent)) center / 2px 100% no-repeat;
  outline: none;
}
.scrim { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 15; }

/* ---------- 4. Shared components ---------- */
.row { display: flex; gap: 8px; align-items: flex-end; }
.row.between { justify-content: space-between; align-items: center; }
.field { margin-bottom: 14px; }
.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin: 0 0 4px; }
.label.small { font-weight: 500; color: var(--muted); margin-top: 8px; }
.hint { margin: 4px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.hint.warn { color: var(--warn); }

.input, .select, .textarea {
  width: 100%; min-width: 0;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.textarea { resize: vertical; line-height: 1.45; }
.input.num { width: 72px; flex: none; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus, .prompt:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:disabled, .select:disabled, .textarea:disabled, .range:disabled { opacity: 0.45; cursor: not-allowed; }
.range { flex: 1 1 0; min-width: 0; accent-color: var(--accent); }
.file { width: 100%; font-size: 12.5px; color: var(--muted); }
.file::file-selector-button {
  margin-right: 8px; padding: 5px 10px;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius);
  cursor: pointer;
}

.btn {
  flex: none;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn { padding: 4px 8px; background: transparent; border: 0; border-radius: var(--radius); color: var(--muted); cursor: pointer; }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.link { padding: 0; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.link:hover { color: var(--accent); }

.check { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.check.strong { font-weight: 600; margin-top: 0; }

.status { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--faint); }
.status.ok::before { background: var(--ok); }
.status.err::before { background: var(--danger); }
.status.busy::before { background: var(--warn); }
.status.err { color: var(--danger); }

.pre {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: 12.5px/1.5 var(--mono);
  white-space: pre-wrap; word-break: break-word;
  overflow: auto;
}
.pre.example { margin: 4px 0 12px; font-size: 12px; }
.tk-c { color: var(--tk-comment); font-style: italic; }
.tk-s { color: var(--tk-string); }
.tk-n { color: var(--tk-number); }
.tk-k { color: var(--tk-keyword); }
.tk-key { color: var(--tk-key); }

.notice { margin: 8px 0; padding: 8px 12px; border: 1px solid var(--border-strong); border-left-width: 3px; border-radius: var(--radius); background: var(--surface); font-size: 13px; }
.notice.err { border-left-color: var(--danger); }
.notice.warn { border-left-color: var(--warn); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

.badge { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 4px 3px 8px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 999px; font-size: 12px; }
.chip.err { border-color: var(--danger); }
.chip-thumb { width: 18px; height: 18px; object-fit: cover; border-radius: 4px; }
.chip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { padding: 0 6px; background: none; border: 0; color: var(--muted); cursor: pointer; }
.chip button:hover { color: var(--danger); }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 3px 16px; margin: 0 0 10px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-word; }
ul.plain { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
ul.plain li { margin-bottom: 6px; }

/* ---------- 5. Control panel ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.brand { font-weight: 650; font-size: 15px; }
.brand-mark { color: var(--accent); }
.panel-scroll { flex: 1; overflow-y: auto; }
.workspace { margin: 0; padding: 0; border: 0; min-width: 0; }
.workspace:disabled { opacity: 0.5; }
.section { border-bottom: 1px solid var(--border); }
.section > summary { padding: 10px 16px; font-weight: 600; font-size: 13px; cursor: pointer; list-style: none; user-select: none; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: "▸"; display: inline-block; width: 16px; color: var(--faint); }
.section[open] > summary::before { content: "▾"; }
.section-body { padding: 2px 16px 12px; }
.tool { padding: 8px 0; border-top: 1px solid var(--border); }
.tool:first-child { border-top: 0; padding-top: 0; }
.tool-opts { margin-top: 8px; padding-left: 4px; }
.tool-opts .label.small:first-child { margin-top: 0; }
.vs-files { max-height: 160px; overflow: auto; font-size: 12.5px; }
.vs-file { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.vs-file:last-child { border-bottom: 0; }
.vs-file .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log { max-height: 140px; min-height: 40px; overflow: auto; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font: 11.5px/1.5 var(--mono); white-space: pre-wrap; color: var(--muted); }

/* ---------- 6. Chat ---------- */
.statusbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); min-height: 44px; }
.stats { display: flex; flex: 1; flex-wrap: wrap; gap: 4px 18px; align-items: baseline; font-size: 13px; color: var(--muted); min-width: 0; }
.stats b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-model { color: var(--text); }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.chat-inner { max-width: 820px; margin: 0 auto; padding: 24px 20px 12px; }
.empty { margin: 14vh 0 0; text-align: center; color: var(--muted); }
.empty-title { margin: 0 0 6px; font-size: 18px; font-weight: 650; color: var(--text); }
.turn { margin-bottom: 28px; }
.msg.user { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.bubble { max-width: 85%; padding: 8px 14px; background: var(--surface); border-radius: var(--radius-lg); white-space: pre-wrap; word-break: break-word; }
.bubble .chips { margin-top: 6px; }
.assistant-body > * + * { margin-top: 10px; }
.turn-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 10px; font-size: 12px; color: var(--faint); }
.pending { color: var(--muted); }
.tool-call { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 12.5px; }
.tool-call > summary { padding: 6px 10px; cursor: pointer; color: var(--muted); }
.tool-call > .pre { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); max-height: 260px; }
.gen-img { display: block; max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.sources { margin: 0; padding-left: 20px; font-size: 12.5px; color: var(--muted); }

/* ---------- 7. Inspector ---------- */
.inspector { border-top: 1px solid var(--border); background: var(--panel); }
.inspector-bar { display: flex; align-items: center; gap: 12px; padding: 0 12px 0 8px; }
.tabs { display: flex; }
.tab { padding: 8px 12px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.inspector-body { max-height: 42vh; overflow: auto; padding: 12px 16px; border-top: 1px solid var(--border); }
.pane-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.pane > .pre + .pre { margin-top: 8px; }
.pane > .hint { margin-top: 8px; }
.err-title { margin: 0 0 8px; font-weight: 600; color: var(--danger); }

/* ---------- 8. Composer ---------- */
.composer-inner { max-width: 820px; margin: 0 auto; padding: 8px 20px 12px; }
.composer-box { padding: 10px 10px 8px 14px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); }
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-box .chips { margin-bottom: 6px; }
.composer-box .chips:empty { display: none; }
.prompt { display: block; width: 100%; max-height: 220px; padding: 2px 0; background: none; border: 0; resize: none; line-height: 1.5; }
.prompt:focus { outline: none; box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.composer-hint { margin: 6px 0 0; text-align: center; font-size: 11.5px; color: var(--faint); }

/* ---------- 9. Markdown ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.3em 0 0.5em; line-height: 1.3; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.12em; } .md h4, .md h5, .md h6 { font-size: 1em; }
.md p { margin: 0 0 0.9em; }
.md ul, .md ol { margin: 0 0 0.9em; padding-left: 1.5em; }
.md li > p { margin-bottom: 0.4em; }
.md li > ul, .md li > ol { margin: 0.3em 0 0; }
.md blockquote { margin: 0 0 0.9em; padding: 2px 14px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md hr { margin: 1.4em 0; border: 0; border-top: 1px solid var(--border-strong); }
.md code { padding: 1px 5px; background: var(--surface-2); border-radius: 5px; font: 0.88em var(--mono); }
.md .code { margin: 0 0 0.9em; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.md .code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 4px 12px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.md .code pre { padding: 10px 12px; overflow-x: auto; font: 12.5px/1.55 var(--mono); }
.md .code code { padding: 0; background: none; font: inherit; }
.md .table-wrap { margin: 0 0 0.9em; overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 13px; }
.md th, .md td { padding: 6px 12px; border: 1px solid var(--border-strong); text-align: left; }
.md th { background: var(--surface); }
.md .ta-c { text-align: center; } .md .ta-r { text-align: right; }

/* ---------- 10. Responsive ---------- */
.only-narrow { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .resizer { display: none; }
  .only-narrow { display: inline-block; }
  .panel {
    position: fixed; inset: 0 auto 0 0; z-index: 20;
    width: min(88vw, 400px);
    border-right: 1px solid var(--border-strong);
    transform: translateX(-100%);
    transition: transform 0.15s ease-out;
  }
  body.panel-open .panel { transform: none; }
  body.panel-open .scrim { display: block; }
  .chat-inner, .composer-inner { padding-left: 12px; padding-right: 12px; }
  .bubble { max-width: 95%; }
}
@media (max-width: 600px) {
  .composer-bar { flex-wrap: wrap; }
  .composer-bar #run { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}

/* ASP Lab integration theme: keep the Desk isolated while using the site palette. */
:root {
  --bg: #F1F5FD;
  --panel: #F7F9FC;
  --surface: #EEF2F7;
  --surface-2: #EAF3FF;
  --border: #DCE3EA;
  --border-strong: #C3CDD8;
  --text: #17202A;
  --muted: #5B6875;
  --faint: #667381;
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --ok: #1D4ED8;
  --warn: #8A520D;
  --danger: #B83C35;
  --tk-comment: #667381;
  --tk-string: #1D4ED8;
  --tk-number: #8A520D;
  --tk-keyword: #2563EB;
  --tk-key: #1E40AF;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

/* Compact developer workspace controls. */
.panel-head { display: none; }
.section > summary { padding: 7px 12px; }
.section-body { padding: 0 12px 8px; }
.field { margin-bottom: 9px; }
.input, .select, .textarea { padding: 5px 8px; }
.statusbar { gap: 8px; min-height: 36px; padding: 5px 10px; }
.chat-inner { padding: 14px 16px 8px; }
.empty { margin-top: 8vh; }
.empty-title { margin: 0; font-size: 14px; font-weight: 500; }
.tab { padding: 6px 9px; }
.inspector-body { padding: 8px 10px; }
.composer-inner { padding: 6px 12px 8px; }
.composer-box { padding: 8px 8px 6px 10px; }
.key-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.key-label-row .label { margin: 0; }
.key-safety { position: relative; flex: none; }
.key-safety > summary { display: grid; width: 18px; height: 18px; place-items: center; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent); font-size: 12px; font-weight: 600; cursor: help; list-style: none; }
.key-safety > summary::-webkit-details-marker { display: none; }
.key-safety__tooltip { position: absolute; z-index: 40; top: calc(100% + 6px); right: 0; width: min(280px, 76vw); padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--panel); box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14); color: var(--text); font-size: 12px; font-weight: 400; line-height: 1.45; }
.key-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 6px; font-size: 12px; line-height: 1.4; }
.key-links a { color: var(--accent-hover); text-decoration: none; }
.key-links a:hover { text-decoration: underline; }
.key-warning { margin: 6px 0 0; color: var(--danger); font-size: 11px; line-height: 1.4; }
@media (max-width: 900px) {
  .panel-head { display: flex; min-height: 34px; justify-content: flex-end; padding: 4px 8px; }
}
