:root {
  --bg: #0b0d12;
  --canvas-bg: #0f1218;
  --surface: #161a24;
  --surface-2: #1c2230;
  --surface-3: #232a3a;
  --text: #e9ecf3;
  --text-dim: #8a93a8;
  --text-faint: #5a6275;
  --accent: #7c9cff;
  --accent-hover: #93acff;
  --accent-soft: rgba(124, 156, 255, 0.12);
  --user: #2a3554;
  --assistant: #1c2230;
  --border: #232938;
  --border-strong: #2e3548;
  --ok: #4ade80;
  --error: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --transition: 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --chat-width: 420px;

  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
}

/* ============================================================
   App layout
   ============================================================ */

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ============================================================
   Main canvas (left, flex-grow)
   ============================================================ */

.canvas {
  flex: 1;
  min-width: 0;
  background: var(--canvas-bg);
  display: flex;
  flex-direction: column;
  transition: margin-right var(--transition);
}

.canvas__header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.canvas__title {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.canvas__count {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Reflow button: trails the window count in the canvas header.
   Disabled when there are 0 windows — greys out + not clickable.
   Style matches the chat collapse button + tool cards for visual
   consistency. See reflowWindows() in app.js. */
.canvas__reflow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.75rem;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition),
    background var(--transition);
}

.canvas__reflow:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
}

.canvas__reflow:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.canvas__reflow svg {
  color: var(--text-faint);
  transition: color var(--transition);
}

.canvas__reflow:hover:not(:disabled) svg {
  color: var(--accent);
}

/* Reflow animation: transient class added to every card being reflowed.
   Transitions left/top/width/height so cards glide to their new spots.
   NOT applied in the default .window styles because we don't want drag
   or user resize to interpolate — only the explicit reflow should. */
.window--reflowing {
  transition: left 400ms cubic-bezier(0.4, 0, 0.2, 1),
    top 400ms cubic-bezier(0.4, 0, 0.2, 1),
    width 400ms cubic-bezier(0.4, 0, 0.2, 1),
    height 400ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color var(--transition);
}

/* Debug + New buttons: same base as reflow, separate classes so each
   can have its own active / hover behavior. */
.canvas__debug,
.canvas__new,
.canvas__save-dashboard,
.canvas__dashboards {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.5rem;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition),
    background var(--transition);
}

.canvas__debug:hover,
.canvas__debug--active,
.canvas__new:hover,
.canvas__save-dashboard:hover:not(:disabled),
.canvas__dashboards:hover {
  border-color: var(--accent);
  color: var(--text);
}

.canvas__debug svg,
.canvas__new svg,
.canvas__save-dashboard svg,
.canvas__dashboards svg {
  color: var(--text-faint);
  transition: color var(--transition);
}

.canvas__debug:hover svg,
.canvas__debug--active svg,
.canvas__save-dashboard:hover:not(:disabled) svg,
.canvas__dashboards:hover svg,
.canvas__new:hover svg {
  color: var(--accent);
}

.canvas__save-dashboard:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   Dashboards picker dropdown
   ============================================================ */

.dashboards-picker {
  position: relative;
  display: inline-flex;
}

.dashboards-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 300px;
  max-width: 400px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.5rem;
  z-index: 100;
}

.dashboards-panel[hidden] {
  display: none;
}

.dashboards-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.4rem;
}

.dashboards-panel__title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.dashboards-panel__create {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.dashboards-panel__create:hover {
  background: var(--accent);
  color: var(--bg);
}

.dashboards-panel__empty {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: center;
  padding: 1.5rem 0.5rem;
}

.dashboards-panel__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.dashboards-panel__item:hover {
  background: var(--surface-3);
}

.dashboards-panel__item-info {
  flex: 1;
  min-width: 0;
}

.dashboards-panel__item-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboards-panel__item-meta {
  font-size: 0.65rem;
  color: var(--text-faint);
}

.dashboards-panel__item-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.dashboards-panel__item:hover .dashboards-panel__item-actions {
  opacity: 1;
}

.dashboards-panel__action {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}

.dashboards-panel__action:hover {
  color: var(--text);
  background: var(--surface-2);
}

.dashboards-panel__action--delete:hover {
  color: var(--error);
}

/* The New button is destructive — subtle red tint on hover to nudge
   the user toward the confirm dialog. */
.canvas__new:hover {
  border-color: var(--error);
  color: var(--error);
}

.canvas__new:hover svg {
  color: var(--error);
}

.canvas__body {
  flex: 1;
  position: relative;
  overflow: auto;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 460px;
  margin: auto;
  padding: 2rem;
  text-align: center;
  color: var(--text-dim);
  pointer-events: none;
}

.empty-state__title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.empty-state__hint {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
}

.empty-state__hint em {
  color: var(--text);
  font-style: normal;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* ============================================================
   Windows: agent-built dashboard cards
   ============================================================ */

.windows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  align-content: start;
  /* Short cards keep their natural height instead of stretching to the
     tallest sibling in the row. Without this, a short chart next to a
     tall rich/text card would visually balloon to match. See
     memory/task_log/2026-04-09-flow-mode-align-items-start.md. */
  align-items: start;
}

.window {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Cap flow-mode card height so very long content scrolls inside the
     body rather than growing the card unboundedly. Positioned-mode
     windows override this back to `none` since they have explicit
     pixel heights from drag/resize geometry. */
  max-height: 65vh;
  /* position: relative so the absolutely-positioned .window__resize
     handle anchors to the card itself in both flow and positioned
     modes. In positioned mode, .windows--positioned .window overrides
     this to `absolute`, which is itself a containing block. */
  position: relative;
  transition: border-color var(--transition), transform var(--transition);
  animation: windowIn var(--transition);
}

.window:hover {
  border-color: var(--win-accent, var(--accent));
}

@keyframes windowIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.window__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--win-accent-bg, var(--surface-2));
  flex-shrink: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}

.window__title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.window__type {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.window__body {
  padding: 1rem;
  overflow-y: auto;
  /* Fill the space the header leaves behind so the 65vh cap on the
     parent .window turns into a scrollable body rather than clipped
     content. min-height: 0 is required so the flex child can shrink
     below its intrinsic content height and actually scroll. */
  flex: 1;
  min-height: 0;
}

/* In positioned mode the card has an explicit height, so the body
   needs to fill whatever the header leaves behind. Flex column so
   that a single map/table child can use flex:1 to fill it. */
.windows--positioned .window__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}


/* form window */
.window__form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.window__field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.window__label {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.window__input {
  background: var(--canvas-bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition);
  resize: vertical;
  font-family: inherit;
}

.window__input:focus {
  border-color: var(--accent);
}

.window__input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.window__submit {
  align-self: flex-start;
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition);
}

.window__submit:hover:not(:disabled) {
  background: var(--accent-hover);
}

.window__submit:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.window__form--submitted .window__submit {
  background: var(--ok);
}

/* regenerate button (window header, right side) */
.window__regen {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 0.4rem;
  flex-shrink: 0;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition),
    transform var(--transition);
}

.window__regen:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.window__regen:hover:not(:disabled) svg {
  transform: rotate(-60deg);
  transition: transform var(--transition);
}

.window__regen:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* minimize + close buttons in window header — same shape family
   as the regenerate button so they read as a toolset */
.window__minimize,
.window__close {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 0.4rem;
  flex-shrink: 0;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition);
}

.window__minimize:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.window__close:hover {
  background: rgba(248, 113, 113, 0.15);
  color: var(--error);
  border-color: var(--error);
}

/* ---- Per-window color accent ---- */

/* Color picker trigger button: same shape as minimize/close */
.window__color-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 0.4rem;
  flex-shrink: 0;
  position: relative; /* anchors the picker popover */
  transition:
    background var(--transition),
    border-color var(--transition);
}

.window__color-btn:hover {
  background: var(--surface-3);
  border-color: var(--win-accent, var(--accent));
}

/* Colored dot inside the button — reflects current accent */
.window__color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background var(--transition);
}

/* Popover with preset swatches */
.window__color-picker {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1100;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  width: 148px; /* 5 swatches × 22px + 4 × 0.3rem gap + 2 × 0.45rem padding */
}

.window__color-picker[hidden] {
  display: none;
}

/* Individual swatch button */
.window__color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  outline: none;
  transition:
    transform var(--transition),
    border-color var(--transition);
}

.window__color-swatch:hover {
  transform: scale(1.18);
}

/* Active/selected swatch gets a white ring */
.window__color-swatch[aria-pressed="true"] {
  border-color: rgba(255, 255, 255, 0.75);
}

/* Default swatch uses the surface color to signal "no accent" */
.window__color-swatch--default {
  background: var(--surface-3);
  border: 2px solid var(--border-strong);
}

.window__color-swatch--default[aria-pressed="true"] {
  border-color: var(--text-dim);
}

/* Resize handle: bottom-right corner. Always visible so the user can
   grab it from a fresh session. On pointerdown, attachResize() in
   app.js calls flipToPositionedMode() if we're still in flow mode,
   which captures the current flow rects into geometry so nothing
   jumps — then the resize proceeds as normal. */
.window__resize {
  display: block;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background:
    linear-gradient(
      135deg,
      transparent 0%,
      transparent 50%,
      var(--border-strong) 50%,
      var(--border-strong) 60%,
      transparent 60%,
      transparent 70%,
      var(--border-strong) 70%,
      var(--border-strong) 80%,
      transparent 80%
    );
  opacity: 0.7;
  transition: opacity var(--transition);
}

.window:hover .window__resize {
  opacity: 1;
}

/* Positioned mode: container becomes a relative parent, children go
   absolute. Existing flow windows have their measured rects written
   into geometry on the flip so they don't visually jump. */
.windows--positioned {
  display: block;
  position: relative;
  min-height: 100%;
  /* Padding kept so flow-flipped initial coords have breathing room */
  padding: 1.5rem;
  overflow: visible;
}

.windows--positioned .window {
  position: absolute;
  /* Positioned windows carry explicit pixel heights from drag/resize
     geometry, so the flow-mode 65vh cap must not clamp them. */
  max-height: none;
}

.window--positioned {
  /* Marker class on individual windows once they have explicit
     geometry. The container also flips, but this lets us style
     individual cards (e.g. for the resize handle). */
  position: absolute;
  /* CRITICAL: creates a stacking context without needing an
     explicit z-index. Required so that map widgets (Leaflet,
     Google Maps) with their own internal z-index: 400+ panes
     don't leak out of the window box and stack above other
     windows. See system_map/technical.md invariant about
     map z-index containment. */
  isolation: isolate;
}

/* Drag/resize cursor feedback. Translucent during drag so the user
   can see what's underneath the moving window — this is the "see
   before you drop" affordance for the non-overlap snap behavior. */
.window--dragging {
  cursor: grabbing;
  user-select: none;
  transition: none;
  opacity: 0.7;
}

.window--dragging .window__header {
  cursor: grabbing;
}

.window--resizing {
  user-select: none;
  transition: none;
  opacity: 0.85;
}

.windows--positioned .window__header {
  cursor: grab;
}

.windows--positioned .window__header:active {
  cursor: grabbing;
}

/* Minimized: hide visually but keep in the DOM so restore is fast.
   Also keeps any in-flight rendering (e.g. Leaflet maps) alive. */
.window--minimized {
  display: none;
}

/* Focus ring for keyboard a11y. Only visible on keyboard focus,
   not click. */
.window:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   Taskbar: strip at bottom of canvas with one tile per
   minimized window. Hidden when nothing is minimized.
   ============================================================ */

.taskbar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  z-index: 999;
  flex-wrap: wrap;
  /* Pull above the windows container slightly so the resize handles
     in positioned mode don't overlap. */
  margin-top: auto;
}

.taskbar[hidden] {
  display: none;
}

.taskbar__tile {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  max-width: 200px;
  transition:
    background var(--transition),
    border-color var(--transition);
}

.taskbar__tile:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}

.taskbar__tile-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.taskbar__tile-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* table window */
.window__table-wrap {
  overflow-x: auto;
  margin: -0.25rem;
  padding: 0.25rem;
}

.window__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.window__table-th {
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition);
}

.window__table-th:hover {
  color: var(--text);
  background: var(--surface-3);
}

.window__table-arrow {
  display: inline-block;
  margin-left: 0.35rem;
  color: var(--accent);
  font-size: 0.85rem;
  width: 0.8em;
  text-align: center;
}

.window__table tbody tr {
  transition: background var(--transition);
}

.window__table tbody tr:hover {
  background: var(--surface-2);
}

.window__table tbody td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.window__table tbody tr:last-child td {
  border-bottom: none;
}

.window__table-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* list window */
.window__list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
}

.window__list--none {
  list-style: none;
  padding-left: 0;
}

.window__list li {
  padding: 0.1rem 0;
}

.window__list-empty {
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.85rem;
}

/* rich window — vertical stack of text/image/video blocks */
.window__rich {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.window__rich-block {
  display: block;
}

.window__rich-block--text {
  /* the inner .window__text picks up the markdown typography rules
     defined below; nothing extra needed here. */
}

.window__rich-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.window__rich-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}

.window__rich-video {
  display: block;
  width: 100%;
  max-height: 360px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #000;
}

/* Aspect-ratio wrapper for iframe-embedded YouTube/Vimeo videos. The
   iframe absolutely fills the wrapper so the 16:9 box stays correct
   regardless of container width. */
.window__rich-video-frame {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.window__rich-video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.window__rich-caption {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-style: italic;
  text-align: center;
}

.window__rich-empty {
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.85rem;
}

/* webpage window — iframe of a URL with graceful fallback when the
   target refuses embedding. In flow mode the iframe gets a fixed
   height; in positioned mode the window body is a flex column so
   the iframe can fill available height. */
.window__webpage {
  position: relative;
  width: 100%;
  height: 420px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}

.windows--positioned .window__body > .window__webpage {
  flex: 1;
  height: auto;
  min-height: 0;
}

.window__webpage-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff; /* most pages assume white; flip for dark-only content */
}

.window__webpage-blocked {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  background: var(--surface);
  text-align: center;
}

/* The explicit `display: flex` above beats the browser's default
   `[hidden] { display: none }` rule because of higher specificity.
   Re-assert the display:none for the hidden state so JS toggling
   .hidden actually hides the fallback card. */
.window__webpage-blocked[hidden] {
  display: none;
}

.window__webpage-blocked-title {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.window__webpage-blocked-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  max-width: 36ch;
}

.window__webpage-blocked-link {
  color: var(--accent);
  font-size: 0.82rem;
  word-break: break-all;
  max-width: 90%;
  border-bottom: 1px solid rgba(124, 156, 255, 0.3);
  text-decoration: none;
}

.window__webpage-blocked-link:hover {
  border-bottom-color: var(--accent);
}

.window__webpage-empty {
  padding: 1rem;
  color: var(--text-faint);
  font-style: italic;
}

/* external_form window — mostly reuses .window__form / .window__field
   styles. Adds an inline status row for success/error messages
   after submission. */
.window__external-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.window__external-form .window__field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.window__external-form-status {
  font-size: 0.82rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

.window__external-form-status--success {
  color: var(--ok, #6bd88c);
  border-color: rgba(107, 216, 140, 0.35);
  background: rgba(107, 216, 140, 0.08);
}

.window__external-form-status--error {
  color: #ff7a7a;
  border-color: rgba(255, 122, 122, 0.35);
  background: rgba(255, 122, 122, 0.08);
}

/* video_stream window — iframe for YouTube/Twitch/Live, HTML5 video
   for HLS and plain URLs. 16:9 aspect-ratio wrapper for iframes. */
.window__video-stream {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.window__video-stream-frame {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.window__video-stream-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.window__video-stream-video {
  display: block;
  width: 100%;
  max-height: 480px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #000;
}

.window__video-stream-caption {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-style: italic;
  text-align: center;
}

.window__video-stream-empty {
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.85rem;
  padding: 1rem;
}

/* chart window — Chart.js canvas in a resizable container. Chart.js
   handles its own drawing inside <canvas>; our job is to size the
   wrapper so responsive + maintainAspectRatio:false fills it. */
.window__chart {
  position: relative;
  width: 100%;
  height: 280px;
  min-height: 200px;
}

.windows--positioned .window__body > .window__chart {
  flex: 1;
  height: auto;
  min-height: 0;
}

.window__chart-canvas {
  /* Chart.js sets inline style width/height in pixels on the canvas
     to match devicePixelRatio; the !important overrides keep the
     visual box filling the wrapper so responsive layouts work. */
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.window__chart-empty,
.window__chart-error {
  padding: 1rem;
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.85rem;
}

.window__chart-error {
  color: #ff7a7a;
  font-style: normal;
}

/* ---------- voice agent window ----------
   Browser-direct Gemini Live session in a window. Three regions stacked
   vertically: a scrolling transcript area, a status row, and a controls
   row with the start/stop button. The wrap element gets a
   data-voice-phase attribute (idle / connecting / listening / speaking /
   stopping / error) so the status dot can color-code by phase. */

.window__voice-agent {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  min-height: 220px;
  height: 100%;
}

.window__voice-transcript {
  flex: 1;
  min-height: 120px;
  max-height: 360px;
  overflow-y: auto;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border, #2a2f3e);
  border-radius: 6px;
  background: var(--surface, rgba(255, 255, 255, 0.02));
  font-size: 0.85rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.window__voice-transcript-empty {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.8rem;
  text-align: center;
  padding: 0.6rem 0.4rem;
}

.window__voice-turn {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.window__voice-turn-role {
  flex: 0 0 auto;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  min-width: 38px;
}

.window__voice-turn--user .window__voice-turn-role {
  color: var(--accent);
}

.window__voice-turn-text {
  flex: 1;
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.window__voice-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.1rem 0.2rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.window__voice-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
  transition: background 0.18s ease;
}

.window__voice-agent[data-voice-phase="connecting"] .window__voice-status-dot {
  background: #f0c060;
  animation: voice-status-pulse 1.2s ease-in-out infinite;
}

.window__voice-agent[data-voice-phase="listening"] .window__voice-status-dot {
  background: #5fd07a;
  animation: voice-status-pulse 1.4s ease-in-out infinite;
}

.window__voice-agent[data-voice-phase="speaking"] .window__voice-status-dot {
  background: var(--accent);
  animation: voice-status-pulse 0.9s ease-in-out infinite;
}

.window__voice-agent[data-voice-phase="stopping"] .window__voice-status-dot {
  background: #f0c060;
}

.window__voice-agent[data-voice-phase="error"] .window__voice-status-dot {
  background: #ff7a7a;
}

@keyframes voice-status-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

.window__voice-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.window__voice-start {
  appearance: none;
  border: 1px solid var(--border, #2a2f3e);
  background: var(--accent-soft);
  color: var(--text);
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.window__voice-start:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.window__voice-start:active:not(:disabled) {
  transform: translateY(1px);
}

.window__voice-start:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.window__voice-agent[data-voice-phase="listening"] .window__voice-start,
.window__voice-agent[data-voice-phase="speaking"] .window__voice-start {
  background: #ff7a7a;
  border-color: #ff7a7a;
  color: #fff;
}

/* Markdown rendering — shared by text windows (.window__text) and
   assistant chat bubbles (.message--md). Both use marked.parse via the
   renderMarkdownInto() helper in app.js. Keep the two selectors in sync. */
.window__text,
.message--md {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
}

.window__text > *:first-child,
.message--md > *:first-child {
  margin-top: 0;
}

.window__text > *:last-child,
.message--md > *:last-child {
  margin-bottom: 0;
}

.window__text h1,
.window__text h2,
.window__text h3,
.window__text h4,
.message--md h1,
.message--md h2,
.message--md h3,
.message--md h4 {
  margin: 1rem 0 0.5rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.window__text h1,
.message--md h1 {
  font-size: 1.15rem;
}
.window__text h2,
.message--md h2 {
  font-size: 1.05rem;
}
.window__text h3,
.message--md h3 {
  font-size: 0.95rem;
}
.window__text h4,
.message--md h4 {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.window__text p,
.message--md p {
  margin: 0.5rem 0;
}

.window__text ul,
.window__text ol,
.message--md ul,
.message--md ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.window__text li,
.message--md li {
  padding: 0.1rem 0;
}

.window__text a,
.message--md a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(124, 156, 255, 0.3);
}

.window__text a:hover,
.message--md a:hover {
  border-bottom-color: var(--accent);
}

.window__text strong,
.message--md strong {
  color: var(--text);
  font-weight: 600;
}

.window__text em,
.message--md em {
  color: var(--text);
  font-style: italic;
}

.window__text code,
.message--md code {
  background: var(--bg);
  color: var(--text);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82em;
  border: 1px solid var(--border);
}

.window__text pre,
.message--md pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}

.window__text pre code,
.message--md pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text);
}

.window__text blockquote,
.message--md blockquote {
  border-left: 3px solid var(--border-strong);
  margin: 0.6rem 0;
  padding: 0.2rem 0 0.2rem 0.85rem;
  color: var(--text-dim);
}

.window__text hr,
.message--md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8rem 0;
}

/* map window */
.window__map {
  width: 100%;
  height: 280px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--canvas-bg);
}

/* In positioned mode the body is a flex column — let the map fill it
   instead of staying locked at the 280px default. refreshMapsInCard()
   on resize pointerup nudges the map library to redraw tiles. */
.windows--positioned .window__body > .window__map {
  flex: 1;
  height: auto;
  min-height: 0;
}

/* Leaflet's default tile attribution and controls inherit white bg —
   blend them into our dark theme. */
.window__map .leaflet-control-attribution {
  background: rgba(11, 13, 18, 0.75);
  color: var(--text-faint);
  font-size: 0.65rem;
}
.window__map .leaflet-control-attribution a {
  color: var(--text-dim);
}
.window__map .leaflet-bar a {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.window__map .leaflet-bar a:hover {
  background: var(--surface-3);
}

/* ============================================================
   Chat widget (right, fixed width, collapsible)
   ============================================================ */

.chat {
  width: var(--chat-width);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition:
    transform var(--transition),
    width var(--transition),
    border-color var(--transition);
}

.app.is-collapsed .chat {
  /* Slide off the right edge so the canvas takes the full width. */
  transform: translateX(100%);
  width: 0;
  border-left-color: transparent;
}

.chat__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.chat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.18);
}

.chat__meta {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: right;
  line-height: 1.35;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   Model picker dropdown
   ============================================================ */

.model-picker {
  margin-left: auto;
  position: relative;
}

.model-picker__button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font-size: 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition);
  max-width: 220px;
}

.model-picker__button:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.model-picker__button[aria-expanded="true"] {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.model-picker__current {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker__chevron {
  flex-shrink: 0;
  transition: transform var(--transition);
}

.model-picker__button[aria-expanded="true"] .model-picker__chevron {
  transform: rotate(180deg);
}

.model-picker__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  max-width: 360px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.4rem;
  z-index: 100;
}

.model-picker__panel[hidden] {
  display: none;
}

.model-picker__group {
  padding: 0.5rem 0.6rem 0.25rem;
}

.model-picker__group + .model-picker__group {
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}

.model-picker__group-name {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.model-picker__group--unavailable .model-picker__group-name {
  color: var(--text-faint);
}

.model-picker__group--unavailable .model-picker__group-name::after {
  content: "no key";
  font-size: 0.6rem;
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0;
  color: var(--text-faint);
  background: var(--surface-3);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

/* Subprocess provider badge — appears next to the group name (e.g.
   "claude_cli  local · Claude Max"). Visually distinct from the
   "no key" badge so the user can tell them apart at a glance. */
.model-picker__group-badge {
  font-size: 0.6rem;
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0;
  color: var(--accent, #6aa9ff);
  background: color-mix(in srgb, var(--accent, #6aa9ff) 14%, transparent);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent, #6aa9ff) 35%, transparent);
}

.model-picker__option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  transition: background var(--transition);
}

.model-picker__option:hover:not(:disabled) {
  background: var(--surface-3);
}

.model-picker__option:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.model-picker__option-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.model-picker__option-label {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker__option-id {
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker__option-note {
  color: var(--text-faint);
  font-size: 0.65rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.model-picker__option--active {
  background: var(--accent-soft);
}

.model-picker__check {
  flex-shrink: 0;
  width: 14px;
  color: var(--accent);
}

.model-picker__check--invisible {
  visibility: hidden;
}

.chat__collapse {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition);
}

.chat__collapse:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.chat__messages::-webkit-scrollbar {
  width: 8px;
}

.chat__messages::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 4px;
}

.chat__messages::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ============================================================
   Messages
   ============================================================ */

.message {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  max-width: 92%;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 0.9rem;
}

.message--user {
  background: var(--user);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message--assistant {
  background: var(--assistant);
  align-self: flex-start;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message--error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
  align-self: flex-start;
}

/* A "turn" groups the assistant text with any tool cards from one response. */
.turn {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
  width: 100%;
}

/* ============================================================
   Pending indicator — shown at the start of every turn until the
   first delta or tool_call arrives. Critical UX for the claude_cli
   path (subprocess spawn takes ~1-2s) and for turns that produce no
   text at all (e.g. CLI slash commands pre-fix). Without this, a
   dead-quiet turn looks identical to a frozen tab.
   ============================================================ */
.turn-pending {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.7rem;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text-faint);
}

.turn-pending__dots {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.turn-pending__dot {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: var(--accent);
  animation: turnPendingPulse 1.2s ease-in-out infinite;
}
.turn-pending__dot:nth-child(2) { animation-delay: 0.2s; }
.turn-pending__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes turnPendingPulse {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.82); }
  30%           { opacity: 1;    transform: scale(1); }
}

.turn-pending__label {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Placeholder for a turn that finished with no text and no tool
   calls. Distinct from a real assistant message so the user can tell
   "done but silent" from "still streaming". */
.message--empty {
  font-style: italic;
  opacity: 0.6;
}

/* ============================================================
   Tool cards
   ============================================================ */

.tool-card {
  align-self: flex-start;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  transition: border-color var(--transition);
}

.tool-card--running {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.tool-card--ok {
  border-color: rgba(74, 222, 128, 0.35);
}
.tool-card--error {
  border-color: rgba(248, 113, 113, 0.45);
}

.tool-card__header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-dim);
}

.tool-card__name {
  color: var(--text);
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

.tool-card__status {
  margin-left: auto;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.tool-card--ok .tool-card__status {
  color: var(--ok);
}
.tool-card--error .tool-card__status {
  color: var(--error);
}

.tool-card__spinner {
  display: inline-block;
  width: 0.95em;
  height: 0.95em;
  border: 2px solid var(--text-faint);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.tool-card__spinner--final {
  border: none;
  width: auto;
  height: auto;
  animation: none;
  font-weight: 700;
  font-size: 0.9rem;
}

.tool-card--ok .tool-card__spinner--final {
  color: var(--ok);
}
.tool-card--error .tool-card__spinner--final {
  color: var(--error);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.tool-card__args,
.tool-card__output {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text-dim);
  max-height: 240px;
  overflow-y: auto;
  line-height: 1.5;
}

/* ============================================================
   Composer
   ============================================================ */

.chat__composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat__input {
  flex: 1;
  background: var(--canvas-bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  font: inherit;
  font-size: 0.9rem;
  resize: none;
  outline: none;
  transition: border-color var(--transition);
}

.chat__input::placeholder {
  color: var(--text-faint);
}

.chat__input:focus {
  border-color: var(--accent);
}

.chat__send {
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: var(--radius);
  padding: 0 1.1rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition);
}

.chat__send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.chat__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mic / dictate button (Web Speech API). Hidden by default; shown by JS
   only in browsers that support SpeechRecognition. */
.chat__mic {
  background: var(--canvas-bg);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  border-radius: var(--radius);
  width: 38px;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition);
}

.chat__mic[hidden] {
  display: none;
}

.chat__mic:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.chat__mic:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat__mic--recording {
  color: #fecaca;
  border-color: var(--error);
  background: rgba(248, 113, 113, 0.08);
  animation: micPulse 1.4s ease-in-out infinite;
}

.chat__mic--recording:hover {
  background: rgba(248, 113, 113, 0.16);
  color: #fecaca;
  border-color: var(--error);
}

@keyframes micPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.45);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(248, 113, 113, 0);
  }
}

/* Live voice mode — green pulsing accent */
.chat__mic--live {
  color: #86efac;
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.08);
  animation: micLivePulse 1.4s ease-in-out infinite;
}

.chat__mic--live:hover {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
  border-color: #22c55e;
}

@keyframes micLivePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
}

/* Voice transcript messages in chat — marked with a mic icon */
.message--voice {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.voice-msg__icon {
  font-size: 0.7rem;
  line-height: 1.4;
  opacity: 0.6;
  flex-shrink: 0;
}

.voice-msg__text {
  flex: 1;
  min-width: 0;
}

/* System messages (voice status, etc.) */
.message--system {
  color: var(--text-faint);
  font-size: 0.78rem;
  font-style: italic;
  padding: 0.2rem 0;
  text-align: center;
}

/* ============================================================
   Floating action button (visible only when chat is collapsed)
   ============================================================ */

.chat-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  pointer-events: none;
  transition:
    opacity var(--transition),
    transform var(--transition),
    background var(--transition);
}

.chat-fab:hover {
  background: var(--accent-hover);
}

.app.is-collapsed .chat-fab {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ============================================================
   Debug drawer: live /api/logs tail
   ============================================================ */

.debug-drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45%;
  min-height: 220px;
  max-height: 70%;
  background: rgba(11, 13, 18, 0.96);
  border-top: 1px solid var(--border-strong);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  z-index: 500;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
}

.debug-drawer[hidden] {
  display: none;
}

.debug-drawer__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.debug-drawer__title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
}

.debug-drawer__hint {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-left: auto;
}

.debug-drawer__close {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.debug-drawer__close:hover {
  border-color: var(--error);
  color: var(--error);
}

.debug-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.5;
}

.debug-drawer__body:empty::before {
  content: "(no events yet)";
  display: block;
  padding: 1rem;
  color: var(--text-faint);
  font-style: italic;
}

.debug-row {
  padding: 0.25rem 1rem;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background var(--transition);
  word-break: break-word;
}

.debug-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.debug-row__head {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}

.debug-row__time {
  color: var(--text-faint);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.debug-row__name {
  color: var(--text);
  font-weight: 600;
  flex-shrink: 0;
  min-width: 11ch;
}

.debug-row__summary {
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
}

.debug-row__json {
  display: none;
  margin: 0.35rem 0 0.15rem 11.6ch;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.68rem;
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
}

.debug-row--expanded .debug-row__json {
  display: block;
}

/* Color coding by event category. The left border and the event name
   get the color so you can scan quickly for what kind of activity is
   happening. */
.debug-row--chat {
  border-left-color: var(--accent);
}
.debug-row--chat .debug-row__name {
  color: var(--accent);
}

.debug-row--llm {
  border-left-color: var(--text-faint);
}

.debug-row--tool {
  border-left-color: #eab308;
}
.debug-row--tool .debug-row__name {
  color: #eab308;
}

.debug-row--tool-result {
  border-left-color: #4ade80;
}
.debug-row--tool-result .debug-row__name {
  color: #4ade80;
}

.debug-row--window,
.debug-row--settings {
  border-left-color: var(--text-dim);
}

.debug-row--cron {
  border-left-color: #c084fc;
}
.debug-row--cron .debug-row__name {
  color: #c084fc;
}

.debug-row--error {
  border-left-color: var(--error);
  background: rgba(248, 113, 113, 0.04);
}
.debug-row--error .debug-row__name {
  color: var(--error);
}
.debug-row--error .debug-row__summary {
  color: #fecaca;
}

.debug-row--default {
  border-left-color: transparent;
}
