/* Chat workspace panels: the resizable terminal (bottom) and the read-only
   file viewer (right). Quiet, utilitarian surfaces built from the app's
   existing tokens. The chat root carries .workspace-panels-host; the panels
   themselves are mounted inside it by partials/_workspace_panels.html and are
   driven entirely client-side by workspace-panels.js. */

.workspace-panels { display: contents; }
.workspace-panels [hidden] { display: none !important; }
.workspace-panels-host { position: relative; min-width: 0; }

/* -- Header toggles ------------------------------------------------------- */

.workspace-panel-toggles { display: inline-flex; align-items: center; gap: .15rem; }
.workspace-panel-toggle { position: relative; }
.workspace-panel-toggle svg { width: 1rem; height: 1rem; }
.workspace-panel-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--text); }
.workspace-panel-toggle[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -.3rem;
  width: 36%;
  height: 2px;
  transform: translateX(-50%);
  border-radius: 1px;
  background: currentColor;
  opacity: .7;
}

/* -- Shared panel chrome --------------------------------------------------- */

.workspace-panel-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
  min-height: 2.05rem;
  padding: .3rem .5rem;
  border-bottom: 1px solid var(--stroke);
  background: var(--surface-header);
}
.workspace-panel-title {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--text-soft);
}
.workspace-panel-title svg { width: .95rem; height: .95rem; flex-shrink: 0; color: var(--text-faint); }
.workspace-panel-context {
  max-width: 16rem;
  font-size: .68rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.workspace-panel-status {
  flex: 1;
  min-width: 0;
  font-size: .68rem;
  color: var(--text-faint);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.workspace-panel-status[data-tone="error"] { color: var(--danger); }
.workspace-panel-status[data-tone="ok"] { color: var(--success); }
.workspace-panel-actions { display: inline-flex; align-items: center; gap: .1rem; flex-shrink: 0; }

/* -- Resize handles ------------------------------------------------------- */

.workspace-panel-resize {
  flex-shrink: 0;
  background: transparent;
  transition: background-color 140ms ease;
}
.workspace-panel-resize:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -2px; }
.workspace-terminal > .workspace-panel-resize { height: .45rem; cursor: ns-resize; }
.workspace-terminal > .workspace-panel-resize:hover { background: var(--accent-soft); }
.workspace-files > .workspace-panel-resize {
  position: absolute;
  left: -.25rem;
  top: 0;
  bottom: 0;
  width: .5rem;
  cursor: ew-resize;
  z-index: 2;
}
.workspace-files > .workspace-panel-resize:hover { background: var(--accent-soft); }

/* -- Terminal panel ------------------------------------------------------- */

.workspace-terminal {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  height: var(--ws-terminal-h, 264px);
  min-height: 6rem;
  max-height: 70vh;
  border-top: 1px solid var(--stroke);
  background: var(--chat-bg);
  overflow: hidden;
}
.workspace-terminal-body { position: relative; flex: 1; min-height: 0; padding: .3rem .4rem .45rem; }
.workspace-terminal-host { height: 100%; width: 100%; }
.workspace-terminal-host .xterm { height: 100%; padding: 0; }
.workspace-terminal-host .xterm-viewport { scrollbar-width: thin; }
.workspace-terminal-note {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .65rem;
  margin: 0;
  padding: .9rem;
  font-size: .74rem;
  line-height: 1.55;
  color: var(--text-faint);
  background: var(--chat-bg);
}
.workspace-terminal-note[data-tone="error"] { color: var(--danger); }

/* -- Files panel (right) -------------------------------------------------- */

.workspace-files {
  position: absolute;
  /* --ws-files-top is the chat header's measured height, so the header and its
     panel toggles stay visible and clickable while this panel is open. */
  top: var(--ws-files-top, 0px);
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: var(--ws-files-w, 360px);
  max-width: 100%;
  background: var(--overlay-bg);
  border-left: 1px solid var(--stroke-strong);
  box-shadow: -14px 0 34px rgba(0, 0, 0, .34);
}
.workspace-files-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.workspace-mode-switch {
  display: inline-flex;
  align-items: center;
  gap: .1rem;
  padding: .1rem;
  border: 1px solid var(--chip-border);
  border-radius: .4rem;
  background: var(--chip-bg);
}
.workspace-mode {
  padding: .18rem .5rem;
  border-radius: .3rem;
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-faint);
  transition: background-color 140ms ease, color 140ms ease;
}
.workspace-mode:hover { color: var(--text); }
.workspace-mode[aria-selected="true"] { background: var(--surface-highlight); color: var(--text); }

.workspace-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .05rem;
  flex-shrink: 0;
  padding: .3rem .4rem;
  border-bottom: 1px solid var(--stroke);
  font-size: .68rem;
}
.workspace-crumb { padding: .12rem .3rem; border-radius: .25rem; color: var(--text-soft); }
.workspace-crumb:hover { background: rgba(255, 255, 255, .06); color: var(--text); }
.workspace-crumb-sep { color: var(--text-faint); }

.workspace-file-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: .25rem;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.workspace-file-row {
  display: flex;
  align-items: center;
  gap: .45rem;
  width: 100%;
  padding: .35rem .45rem;
  border-radius: .35rem;
  text-align: left;
  font-size: .78rem;
  color: var(--text-soft);
  transition: background-color 140ms ease, color 140ms ease;
}
.workspace-file-row:hover { background: rgba(255, 255, 255, .06); color: var(--text); }
.workspace-file-row:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -2px; }
.workspace-file-row svg { width: .95rem; height: .95rem; flex-shrink: 0; color: var(--text-faint); }
.workspace-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-file-size { flex-shrink: 0; font-size: .66rem; color: var(--text-faint); }
.workspace-file-more { margin: .15rem .5rem .6rem; }
.workspace-panel-note { margin: 0; padding: .9rem .8rem; font-size: .74rem; line-height: 1.55; color: var(--text-faint); }

/* -- File preview --------------------------------------------------------- */

.workspace-preview {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--overlay-bg);
}
.workspace-preview-name {
  flex: 1;
  min-width: 0;
  font-size: .74rem;
  font-weight: 600;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.workspace-preview-body { flex: 1; min-height: 0; overflow: auto; padding: .5rem; display: flex; flex-direction: column; }
.workspace-preview-text {
  margin: 0;
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .74rem;
  line-height: 1.5;
  color: var(--text-soft);
  white-space: pre;
  tab-size: 4;
}
.workspace-preview-media { margin: auto; max-width: 100%; max-height: 100%; border-radius: .4rem; background-color: #000; }
.workspace-preview-frame { width: 100%; height: 100%; min-height: 18rem; border: 0; background-color: #fff; }
.workspace-preview-doc { margin: auto; display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 1.25rem; text-align: center; color: var(--text-soft); font-size: .78rem; }
.workspace-preview-doc svg { width: 1.6rem; height: 1.6rem; color: var(--text-faint); }
.workspace-preview-truncated { padding: .35rem .5rem; border-top: 1px solid var(--stroke); font-size: .68rem; color: var(--text-faint); }

/* -- Open-in-viewer affordance on generated files ------------------------- */

.workspace-open-file { display: none; }
.workspace-panels-host .workspace-open-file { display: inline-flex; }

/* -- Desktop reserve: the file viewer keeps its own column ----------------- */

/* The panel is absolute so it can sit below a wrapping header, which means it
   would otherwise float over the chat. While it is open the host is marked
   .is-files-open and the chat flow (scroll area plus composer) is inset by the
   same width, so model selectors and Send stay clear of the viewer. The value
   tracks --ws-files-w, which the resize handle rewrites, so the reserve follows
   the panel as it is dragged. Below the drawer breakpoint the class is inert
   and the panel covers the whole surface instead. */
@media (min-width: 641px) {
  .workspace-panels-host.is-files-open [data-workspace-chat-flow] {
    padding-right: var(--ws-files-w, 360px);
  }
}

/* -- Narrow screens: the file viewer takes the whole surface -------------- */

@media (max-width: 640px) {
  .workspace-files { width: 100%; border-left: 0; box-shadow: none; }
  .workspace-files > .workspace-panel-resize { display: none; }
  .workspace-panel-context { display: none; }
  .workspace-terminal { max-height: 62vh; height: var(--ws-terminal-h, 224px); }
}

@media (prefers-reduced-motion: reduce) {
  .workspace-panel-toggle, .workspace-mode, .workspace-file-row, .workspace-panel-resize { transition: none; }
}
