:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #19212d;
  --muted: #6b7585;
  --line: #e2e7ee;
  --line-strong: #cbd3df;
  --accent: #245dd7;
  --accent-strong: #1747b2;
  --accent-soft: #eaf0ff;
  --success: #138a63;
  --warn: #b66b13;
  --danger: #bd3b45;
  --shadow: 0 12px 32px rgba(33, 48, 72, 0.08);
  --radius: 13px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1218;
    --panel: #151b24;
    --panel-2: #111720;
    --ink: #e8edf5;
    --muted: #919cab;
    --line: #26303c;
    --line-strong: #364252;
    --accent: #5d8ff5;
    --accent-strong: #78a2f9;
    --accent-soft: #1d2a45;
    --success: #50c89e;
    --warn: #e6a452;
    --danger: #ef7a84;
    --shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }

button, select, input, textarea {
  color: var(--ink);
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 7px 11px;
  cursor: pointer;
  transition: border-color .14s, background .14s, transform .14s, opacity .14s;
}

button:hover:not(:disabled) { border-color: var(--line-strong); background: var(--panel-2); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .46; }

button.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 650;
}

button.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }

.app-shell {
  display: grid;
  grid-template-columns: clamp(350px, 25vw, 400px) minmax(0, 1fr);
  grid-template-rows: 54px minmax(0, 1fr);
  grid-template-areas: "top top" "side work";
  height: 100vh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 14px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 260px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(145deg, #1747b2, #3174f1);
  font-size: 15px;
  font-weight: 760;
  box-shadow: 0 6px 18px rgba(36, 93, 215, .25);
}

.brand h1 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 11.5px; }

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.model-picker { display: inline-flex; min-width: 0; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.model-picker-label { flex: none; text-transform: uppercase; letter-spacing: .04em; font-size: 10px; font-weight: 650; }
.model-picker select {
  width: auto;
  min-width: 148px;
  max-width: 210px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 650;
  text-overflow: ellipsis;
}
.model-picker select:disabled { opacity: .58; }
.connect-dymon {
  flex: none;
  padding: 5px 10px;
  border-color: color-mix(in srgb, var(--warn) 46%, var(--line));
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, var(--panel));
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.status-strip { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.refresh-research { flex: none; padding: 5px 10px; color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 24%, var(--line)); font-size: 11.5px; font-weight: 700; }
.sessions-toggle { display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 5px 10px; color: var(--ink); font-size: 11.5px; font-weight: 700; }
.sessions-toggle span { display: grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; color: #fff; background: var(--accent); font-size: 10px; font-variant-numeric: tabular-nums; }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-2);
  font-size: 11.5px;
  white-space: nowrap;
}

.status-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-chip.ready::before { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 16%, transparent); }
.status-chip.missing::before { background: var(--danger); }
.status-chip.pending::before { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.side-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding: 9px 12px 6px;
}

.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 720;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.side-head h2, .panel-head h2 { margin: 0; font-size: 16px; letter-spacing: -.015em; }

.selected-badge {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  text-align: center;
  font-size: 12px;
  font-weight: 720;
}

.scope-scroll {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.market-search-shell {
  position: relative;
  z-index: 20;
  flex: none;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 6px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
}

.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 12.5px; }

.market-search-results {
  position: absolute;
  top: calc(100% - 2px);
  left: 10px;
  right: 10px;
  z-index: 21;
  max-height: min(420px, calc(100vh - 150px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 98%, transparent);
  box-shadow: 0 16px 40px rgba(24, 39, 66, .2);
  backdrop-filter: blur(14px);
  scrollbar-width: thin;
}
.market-search-results[hidden] { display: none; }
.market-search-meta { padding: 2px 5px 6px; color: var(--muted); font-size: 9.5px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
.market-search-result {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.market-search-result:hover { background: var(--panel-2); }
.market-search-result.selected { background: var(--accent-soft); }
.market-search-result input { margin: 3px 0 0; accent-color: var(--accent); }
.market-search-result .index-desc { -webkit-line-clamp: 1; }
.market-search-empty { padding: 14px 8px; color: var(--muted); text-align: center; font-size: 11px; }

.templates-panel {
  flex: none;
  margin: 0 10px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  transition: border-color .14s, box-shadow .14s;
}
.templates-panel.selected { border-color: color-mix(in srgb, var(--success) 48%, var(--line)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 10%, transparent); }
.templates-panel summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 9px; cursor: pointer; list-style: none; }
.templates-panel summary::-webkit-details-marker { display: none; }
.templates-panel summary strong { font-size: 12px; }
.templates-panel summary .eyebrow { margin: 0; font-size: 8.5px; }
.template-count { display: grid; place-items: center; min-width: 21px; height: 21px; padding: 0 5px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 9.5px; font-weight: 750; }
.templates-panel-body { padding: 0 8px 8px; border-top: 1px solid var(--line); }
.templates-panel-body > label { display: block; margin: 7px 0 4px; color: var(--muted); font-size: 9.5px; font-weight: 700; }
.template-select-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px; }
.template-select-row select { min-width: 0; padding: 6px 7px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 10.5px; }
.template-select-row button { padding: 5px 8px; font-size: 10.5px; }
.templates-panel-body p { margin: 5px 1px 0; color: var(--muted); font-size: 9px; line-height: 1.35; }

.window-block { padding: 0 10px 6px; }
.field-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 650; }
.field-label code, .group-title code { letter-spacing: 0; text-transform: none; }

.segmented { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.segmented button { flex: 1; border: 0; padding: 5px 6px; background: transparent; font-size: 11.5px; }
.segmented button.on { color: var(--accent); background: var(--panel); box-shadow: 0 1px 5px rgba(24, 37, 55, .1); font-weight: 700; }

.selection-tools { display: flex; gap: 6px; padding: 0 10px 6px; }
.selection-tools button { flex: 1; padding: 5px 8px; font-size: 11.5px; }

.scope-dimensions { flex: none; padding: 0 6px 2px; }
.scope-dimensions .index-group { min-width: 0; margin: 2px 0 5px; padding: 4px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.scope-dimensions .group-description { display: none; }
.template-exclusion-note { display: none; margin: 1px 5px 5px; color: var(--warn); font-size: 9px; line-height: 1.3; }
.scope-dimension.template-excluded .template-exclusion-note { display: block; }
.template-excluded { opacity: .46; }
.template-excluded .index-row, .template-excluded button { cursor: not-allowed; }
.index-groups { min-height: 0; padding: 0 6px 8px; }
.index-group { margin: 4px 0 12px; }
.group-title { display: flex; align-items: center; justify-content: space-between; padding: 4px 5px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .075em; text-transform: uppercase; }
.group-title span:last-child { font-variant-numeric: tabular-nums; }
.group-description { margin: -1px 5px 5px; color: var(--muted); font-size: 9.5px; line-height: 1.3; }
.dimension-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; }
.scope-dimensions .index-group[data-group="perspectives"] .dimension-options { grid-template-columns: .72fr .86fr .9fr 1.32fr .9fr; }
.scope-dimensions .index-group[data-group="types"] .dimension-options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dimension-options .index-row { align-items: center; gap: 3px; min-height: 29px; padding: 4px 3px; border: 1px solid transparent; background: var(--panel); }
.dimension-options .index-row.selected { border-color: rgba(43, 99, 215, .25); background: var(--accent-soft); }
.dimension-options .index-row input { margin: 0; }
.dimension-options .index-label { min-width: 0; font-size: 10px; line-height: 1.2; letter-spacing: -.015em; }
.dimension-options .index-desc { display: none; }

.index-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 7px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.index-row:hover { background: var(--panel-2); }
.index-row.selected { background: var(--accent-soft); }
.index-row.filtered-out { display: none; }
.index-row input { margin: 3px 0 0; accent-color: var(--accent); }
.index-copy { min-width: 0; flex: 1; }
.index-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 650; }
.index-desc { margin-top: 1px; color: var(--muted); font-size: 10.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.side-footer { flex: none; border-top: 1px solid var(--line); background: var(--panel); }
.custom-research { padding: 5px 10px 4px; border-bottom: 1px solid var(--line); transition: background .14s; }
.custom-research.active { background: var(--accent-soft); }
.custom-research-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.custom-research-head label { color: var(--ink); font-size: 11.5px; font-weight: 700; }
.custom-research-head span { padding: 2px 6px; border-radius: 999px; color: var(--accent); background: var(--panel); font-size: 9.5px; font-weight: 700; }
.custom-research textarea { width: 100%; min-height: 38px; max-height: 76px; resize: vertical; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: var(--panel-2); color: var(--ink); font-size: 11px; line-height: 1.35; }
.custom-research textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.custom-research p { display: none; }
.custom-research.active p { display: block; margin: 4px 1px 0; color: var(--muted); font-size: 9px; line-height: 1.35; }
.prompt-preview { border-bottom: 1px solid var(--line); }
.report-prompt { flex: none; background: var(--panel); }
.report-prompt summary { padding-inline: 15px; }
.report-prompt .prompt-preview-body { max-height: 160px; padding-inline: 15px; }
.prompt-preview summary { display: flex; justify-content: space-between; gap: 8px; padding: 7px 11px; cursor: pointer; color: var(--muted); font-size: 11.5px; }
.prompt-preview summary span:first-child { color: var(--ink); font-weight: 650; }
.prompt-preview-body { max-height: 120px; overflow: auto; margin: 0; padding: 8px 11px 10px; background: var(--panel-2); color: var(--muted); white-space: pre-wrap; font: 10.5px/1.45 "Cascadia Mono", Consolas, monospace; }

.report-controls { display: grid; grid-template-columns: 108px minmax(0, 1fr); align-items: end; gap: 4px 6px; padding: 5px 10px; background: var(--panel); }
.report-controls > .field-label { grid-column: 1 / -1; margin: 0; }
#reportEngineLabel { min-width: 0; overflow-wrap: anywhere; }
.report-controls select { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 12px; }
.effort-picker { display: grid; grid-template-columns: 1fr; align-items: end; gap: 2px; margin: 0; color: var(--muted); font-size: 10px; }
.effort-picker select { width: 100%; padding: 5px 7px; }
.generate-btn { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 35px; margin: 0; padding: 7px 10px; }
.privacy-note { grid-column: 1 / -1; margin: 0; color: var(--muted); text-align: center; font-size: 9px; }
.scope-validation { grid-column: 1 / -1; margin: 0; padding: 4px 7px; border-radius: 6px; color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, var(--panel)); text-align: center; font-size: 9.5px; }

.workspace {
  grid-area: work;
  display: grid;
  grid-template-rows: minmax(0, 66fr) minmax(210px, 34fr);
  gap: 8px;
  min-width: 0;
  min-height: 0;
  padding: 8px;
}

.workspace.report-focus { grid-template-rows: minmax(0, 1fr) 55px; }
.workspace.report-focus .chat-panel .conversation,
.workspace.report-focus .chat-panel .composer { display: none; }

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.report-panel { position: relative; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact { min-height: 50px; }
.panel-actions, .chat-controls { display: flex; align-items: center; gap: 7px; }
.panel-actions button, .chat-controls > button { padding: 5px 9px; font-size: 11.5px; }
.compact-effort { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.compact-effort select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); color: var(--ink); font-size: 11px; }

.job-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-2);
  font-size: 11px;
}

.job-state.running { color: var(--accent); background: var(--accent-soft); }
.job-state.done { color: var(--success); }
.job-state.failed { color: var(--danger); }
.job-state.running::before { content: ""; width: 8px; height: 8px; border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

.report-toc,
.prompt-popover {
  position: absolute;
  top: 64px;
  right: 12px;
  z-index: 8;
  width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 82px);
  overflow: auto;
  padding: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: 0 14px 40px rgba(25, 42, 73, .18);
  backdrop-filter: blur(12px);
}
.report-toc-head, .prompt-popover-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 2px 7px; border-bottom: 1px solid var(--line); }
.report-toc-head strong, .prompt-popover-head strong { font-size: 12px; }
.report-toc-head button, .prompt-popover-head button { padding: 3px 7px; font-size: 10.5px; }
.prompt-popover { width: min(660px, calc(100% - 24px)); }
.prompt-popover-body {
  max-height: min(58vh, 500px);
  margin: 7px 0 0;
  padding: 10px;
  border-radius: 8px;
  overflow: auto;
  background: var(--panel-2);
  color: var(--muted);
  white-space: pre-wrap;
  scrollbar-width: thin;
  font: 11px/1.55 "Cascadia Mono", Consolas, monospace;
}
.run-timer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 49px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-2);
  font: 650 11px/1 "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
.run-timer.running { color: var(--accent); background: var(--accent-soft); }
.run-timer.done { color: var(--success); }
.report-toc-links { display: grid; gap: 2px; padding-top: 6px; }
.report-toc-link { width: 100%; padding: 6px 7px; border: 0; text-align: left; color: var(--muted); background: transparent; font-size: 11px; line-height: 1.35; }
.report-toc-link:hover { color: var(--accent); background: var(--accent-soft); }
.report-toc-link.depth-1, .report-toc-link.depth-2, .report-toc-top { color: var(--ink); font-weight: 700; }
.report-toc-link.depth-3 { padding-left: 16px; }
.report-toc-link.depth-4 { padding-left: 26px; font-size: 10.5px; }

.report-stage { position: relative; min-height: 0; flex: 1; overflow-y: auto; scrollbar-width: thin; }
.run-progress {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 10px 12px 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: 0 6px 18px rgba(25, 42, 73, .08);
  backdrop-filter: blur(10px);
}
.progress-title { display: flex; align-items: center; gap: 8px; color: var(--accent); font-size: 12px; }
.progress-spinner { width: 12px; height: 12px; border: 2px solid color-mix(in srgb, var(--accent) 24%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.progress-activity { display: grid; gap: 4px; max-height: 176px; margin-top: 8px; padding-right: 4px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.activity-row { display: flex; align-items: baseline; gap: 7px; color: var(--muted); font-size: 10.5px; }
.activity-time { flex: none; color: var(--muted); opacity: .72; font: 9.5px/1.6 "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.activity-text { min-width: 0; }
.activity-row:last-child { color: var(--ink); }
.activity-dot { width: 6px; height: 6px; flex: none; align-self: center; border-radius: 50%; background: var(--line-strong); }
.activity-row.tool .activity-dot { background: var(--warn); }
.activity-row.thinking .activity-dot { background: var(--accent); }
.activity-row.writing .activity-dot { background: var(--success); }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100%; padding: 34px; text-align: center; }
.empty-state h3 { margin: 14px 0 5px; font-size: 17px; }
.empty-state p { max-width: 590px; margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.65; }

.empty-orbit { position: relative; width: 58px; height: 58px; border: 1px solid var(--line-strong); border-radius: 50%; }
.empty-orbit::before, .empty-orbit::after { content: ""; position: absolute; inset: 10px; border: 1px solid var(--line); border-radius: 50%; }
.empty-orbit::after { inset: 22px; background: var(--accent); border: 0; box-shadow: 0 0 0 6px var(--accent-soft); }
.empty-orbit span { position: absolute; top: 4px; left: 27px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); transform-origin: 2px 25px; animation: orbit 4s linear infinite; }

.markdown-body { max-width: 1060px; margin: 0 auto; padding: 23px 30px 70px; font-size: 13px; line-height: 1.62; }
.markdown-body h1 { margin: 2px 0 18px; padding-bottom: 11px; border-bottom: 1px solid var(--line); font-size: 22px; letter-spacing: -.025em; }
.markdown-body h2 { margin: 26px 0 10px; color: var(--accent); font-size: 17px; }
.markdown-body h3 { margin: 20px 0 8px; font-size: 14px; }
.markdown-body h4 { margin: 16px 0 7px; font-size: 13px; }
.markdown-body p { margin: 7px 0; }
.markdown-body ul, .markdown-body ol { margin: 6px 0 10px; padding-left: 22px; }
.markdown-body li { margin: 4px 0; }
.markdown-body code { padding: 1px 4px; border-radius: 4px; background: var(--panel-2); font: 11.5px "Cascadia Mono", Consolas, monospace; }
.markdown-body blockquote { margin: 10px 0; padding: 8px 13px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--muted); }
.markdown-body .md-table { overflow-x: auto; margin: 10px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); white-space: pre; font: 11px/1.5 "Cascadia Mono", Consolas, monospace; }
.report-table-scroll { max-width: 100%; margin: 14px 0 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.report-table-scroll:focus { outline: 2px solid color-mix(in srgb, var(--accent) 54%, transparent); outline-offset: 2px; }
.markdown-body table { width: 100%; margin: 0; border-collapse: separate; border-spacing: 0; font-size: 11.5px; }
.markdown-body caption { padding: 7px 9px; color: var(--muted); text-align: left; font-weight: 650; }
.markdown-body th, .markdown-body td { padding: 7px 9px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.markdown-body th { background: var(--panel-2); font-weight: 700; }
.markdown-body tr:last-child > * { border-bottom: 0; }
.markdown-body tr > *:last-child { border-right: 0; }
.markdown-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.markdown-body figure { margin: 16px 0 20px; }
.markdown-body figcaption { margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.markdown-body svg { display: block; width: 100%; max-height: 420px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }

.claude-only,
.model-context-label { display: inline-flex; align-items: center; min-width: 0; padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 11px; font-weight: 700; white-space: nowrap; }
.model-badge { display: inline-flex; align-items: center; max-width: 180px; overflow: hidden; padding: 4px 8px; border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line)); border-radius: 999px; color: var(--accent); background: var(--accent-soft); text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; font-weight: 700; }
.activity-row.fallback .activity-dot { background: var(--warn); }
.activity-row.fallback .activity-text { color: var(--warn); }
.conversation { min-height: 0; flex: 1; overflow-y: auto; padding: 12px 14px; background: var(--panel-2); scrollbar-width: thin; }
.chat-empty { display: grid; place-items: center; min-height: 100%; max-width: 650px; margin: auto; color: var(--muted); text-align: center; font-size: 12px; line-height: 1.65; }
.message { max-width: min(820px, 86%); margin: 0 0 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); white-space: pre-wrap; word-break: break-word; font-size: 12.5px; line-height: 1.55; }
.message.user { margin-left: auto; color: #fff; background: var(--accent); border-color: var(--accent); border-bottom-right-radius: 3px; }
.message.assistant { border-bottom-left-radius: 3px; }
.message.pending { color: var(--muted); font-style: italic; }
.message .message-meta { display: block; margin-bottom: 4px; color: inherit; opacity: .66; font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }

.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.composer textarea { width: 100%; min-height: 44px; max-height: 130px; resize: vertical; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; outline: 0; background: var(--panel-2); line-height: 1.45; }
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.composer button { height: 42px; padding: 0 17px; }

.loading-copy { padding: 30px 8px; color: var(--muted); text-align: center; font-size: 12px; }
.sessions-scrim {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(19, 28, 42, .2);
  backdrop-filter: blur(1px);
}

.sessions-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: min(500px, calc(100vw - 24px));
  min-width: 360px;
  overflow: hidden;
  border-left: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--panel) 98%, transparent);
  box-shadow: -18px 0 52px rgba(20, 34, 58, .18);
  backdrop-filter: blur(18px);
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
  transition: transform .2s ease, visibility 0s linear .2s;
}

.sessions-drawer.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform .2s ease;
}

.sessions-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.sessions-drawer-head h2 { margin: 0; font-size: 18px; }
.sessions-drawer-actions { display: flex; align-items: center; gap: 6px; }
.sessions-drawer-actions button { padding: 6px 9px; font-size: 11.5px; }

.sessions-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 10px 12px 7px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.sessions-tabs button { border: 0; padding: 6px 9px; background: transparent; font-size: 11.5px; }
.sessions-tabs button.on { color: var(--accent); background: var(--panel); box-shadow: 0 1px 5px rgba(24, 37, 55, .1); font-weight: 720; }
.sessions-tabs span { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 4px; padding: 0 4px; border-radius: 999px; background: var(--accent-soft); font-size: 9.5px; }

.archive-settings {
  margin: 0 12px 8px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.archive-settings summary { cursor: pointer; color: var(--ink); font-size: 11.5px; font-weight: 720; }
.archive-settings > label { display: block; margin: 8px 0 5px; color: var(--muted); font-size: 10.5px; line-height: 1.4; }
.archive-directory-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 5px; }
.archive-directory-row input { min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: var(--panel); font-size: 10.5px; }
.archive-directory-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.archive-directory-row button { padding: 5px 8px; font-size: 10.5px; }
.archive-settings p { margin: 6px 1px 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 9.5px; }

.session-search {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 12px 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
}
.session-search input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 11.5px; }
.sessions-list { min-height: 0; flex: 1; overflow-y: auto; padding: 2px 12px 12px; scrollbar-width: thin; }
.sessions-empty { display: grid; place-items: center; min-height: 150px; padding: 20px; color: var(--muted); text-align: center; font-size: 11.5px; }

.session-card {
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  box-shadow: 0 3px 11px rgba(25, 42, 73, .045);
}
.session-card.active { border-color: color-mix(in srgb, var(--accent) 52%, var(--line)); box-shadow: 0 0 0 2px var(--accent-soft); }
.session-card.running { border-left: 3px solid var(--accent); }
.session-card.deleting { opacity: .58; border-style: dashed; }
.session-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.session-card-top > div { min-width: 0; }
.session-card h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.session-card time { display: block; margin-top: 2px; color: var(--muted); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.session-card-status { flex: none; max-width: 165px; overflow: hidden; padding: 3px 7px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); text-overflow: ellipsis; white-space: nowrap; font-size: 9.5px; font-weight: 700; }
.session-card.running .session-card-status::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border: 1.5px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.session-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.session-card-tags span { max-width: 118px; overflow: hidden; padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--panel-2); text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
.session-card-actions { display: flex; gap: 6px; }
.session-card-actions button { flex: 1; min-width: 0; padding: 5px 7px; font-size: 10px; }
.session-card-actions button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, var(--line)); }
.session-card-actions .delete-session { flex: 0 0 auto; }
.session-archive-path { margin: 7px 0 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font: 9px/1.3 "Cascadia Mono", Consolas, monospace; }
.sessions-help { flex: none; margin: 0; padding: 8px 13px 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9.5px; line-height: 1.4; }

.template-token {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border-radius: 5px;
  border: 0;
  font: 700 10px/1.5 "Cascadia Mono", Consolas, monospace;
  white-space: nowrap;
}
.token-ccy { color: #1f63a8; background: color-mix(in srgb, #50a4e8 18%, var(--panel)); }
.token-ast { color: #7a49a5; background: color-mix(in srgb, #ad78d6 18%, var(--panel)); }
.token-win { color: #9a6117; background: color-mix(in srgb, #e5a64d 20%, var(--panel)); }
.tokenized-prompt mark { margin: 0 1px; vertical-align: baseline; }

.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 59;
  background: rgba(18, 27, 42, .38);
  backdrop-filter: blur(2px);
}
.template-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: min(940px, calc(100vw - 48px));
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 26px 72px rgba(17, 29, 47, .28);
}
.template-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 15px; border-bottom: 1px solid var(--line); }
.template-modal-head h2 { margin: 0; font-size: 17px; }
.template-modal-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 0; flex: 1; }
.template-library { display: flex; flex-direction: column; min-height: 0; padding: 12px; border-right: 1px solid var(--line); background: var(--panel-2); }
.template-library > button { flex: none; }
.template-list { min-height: 0; margin-top: 9px; overflow-y: auto; scrollbar-width: thin; }
.template-list-empty { color: var(--muted); text-align: center; font-size: 11px; }
.template-list-item { display: block; width: 100%; margin-bottom: 5px; padding: 8px 9px; text-align: left; }
.template-list-item strong, .template-list-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-list-item strong { font-size: 11.5px; }
.template-list-item span { margin-top: 2px; color: var(--muted); font-size: 9.5px; }
.template-list-item.selected { border-color: color-mix(in srgb, var(--success) 40%, var(--line)); box-shadow: inset 3px 0 0 var(--success); }
.template-list-item.editing { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 36%, var(--line)); }
.template-editor { display: flex; flex-direction: column; min-height: 0; padding: 14px 16px; }
.template-editor > label, .template-editor-label label { margin-bottom: 5px; color: var(--muted); font-size: 10.5px; font-weight: 700; }
.template-editor > input, .template-editor textarea { width: 100%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: var(--panel-2); color: var(--ink); }
.template-editor > input:focus, .template-editor textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.template-editor-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.template-editor textarea { min-height: 190px; flex: 1; resize: vertical; font: 11px/1.5 "Cascadia Mono", Consolas, monospace; }
.editor-state { padding: 2px 7px; border-radius: 999px; color: var(--muted); background: var(--panel-2); font-size: 9px; font-weight: 750; }
.editor-state.saved { color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--panel)); }
.editor-state.unsaved { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--panel)); }
.editor-state.new { color: var(--accent); background: var(--accent-soft); }
.template-token-legend { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 0; }
.template-editor-preview { max-height: 108px; padding: 8px 9px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.template-editor-preview > strong { display: block; margin-bottom: 4px; font-size: 10px; }
.template-editor-preview .tokenized-prompt { max-height: 68px; overflow-y: auto; color: var(--muted); white-space: pre-wrap; font: 10px/1.45 "Cascadia Mono", Consolas, monospace; }
.template-form-error { min-height: 16px; margin: 5px 0 0; color: var(--danger); font-size: 10px; }
.template-form-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.template-form-actions .danger { color: var(--danger); }
.template-save-note { min-width: 0; flex: 1; color: var(--muted); font-size: 9.5px; line-height: 1.3; }

.toast { position: fixed; left: 50%; bottom: 20px; z-index: 50; max-width: min(620px, 90vw); transform: translate(-50%, 16px); padding: 9px 14px; border-radius: 9px; background: #172033; color: #fff; box-shadow: 0 10px 28px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: opacity .16s, transform .16s; font-size: 12px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes orbit { to { transform: rotate(360deg); } }

@media (max-width: 1360px) {
  .app-shell { grid-template-columns: 340px minmax(0, 1fr); }
  .brand { min-width: 220px; }
  .brand p { display: none; }
  .status-chip span { display: none; }
  .model-picker select { min-width: 132px; max-width: 166px; }
  .model-picker-label { display: none; }
  .panel-actions, .chat-controls { gap: 4px; }
  .panel-actions button, .chat-controls > button { padding-inline: 6px; }
  .scope-dimensions .index-group[data-group="types"] .dimension-options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .status-strip { display: none; }
}

@media (max-width: 960px) {
  body { overflow: hidden; }
  .app-shell { grid-template-columns: 320px minmax(0, 1fr); min-width: 0; }
  .panel-actions { gap: 4px; }
  .panel-actions button { padding-inline: 6px; }
}

@media (max-width: 700px) {
  .sessions-drawer { width: 100vw; min-width: 0; }
  .status-strip { display: none; }
  .sessions-toggle { padding-inline: 7px; }
  .archive-directory-row { grid-template-columns: minmax(0, 1fr) auto; }
  .archive-directory-row #saveArchiveDirectoryBtn { grid-column: 1 / -1; }
}

@media (max-height: 800px) {
  .workspace { grid-template-rows: minmax(330px, 1fr) minmax(205px, .52fr); }
  .side-head { padding-top: 7px; }
  .market-search-results { max-height: min(360px, calc(100vh - 132px)); }
  .window-block { padding-bottom: 4px; }
  .scope-dimensions .index-group { margin-bottom: 3px; }
  .selection-tools { padding-bottom: 4px; }
  .panel-head.compact { min-height: 46px; padding-block: 6px; }
  .composer { padding: 6px 8px; }
  .composer textarea { min-height: 38px; max-height: 90px; padding: 7px 9px; }
  .composer button { height: 36px; }
  .report-prompt .prompt-preview-body { max-height: 110px; }
  .progress-activity { max-height: 120px; }
  .markdown-body { padding-top: 18px; }
}

/* iPhone portrait and short coarse-pointer landscape. iPad and desktop stay unchanged. */
@media (max-width: 700px),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-text-size-adjust: 100%;
  }

  button,
  .index-row,
  .market-search-result,
  .templates-panel summary,
  .prompt-preview summary,
  .archive-settings summary {
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  input[type="search"],
  input[type="text"],
  select,
  textarea {
    font-size: 16px;
  }

  input[type="search"],
  input[type="text"],
  select {
    min-height: 44px;
  }

  .index-row input[type="checkbox"],
  .market-search-result input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "top" "side" "work";
    width: 100%;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 35;
    min-width: 0;
    gap: 6px;
    padding: calc(6px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) 6px calc(10px + env(safe-area-inset-left, 0px));
  }

  .topbar { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; }
  .brand { min-width: 0; width: 100%; flex: none; gap: 0; }
  .brand > div:last-child { min-width: 0; }
  .brand-mark,
  .brand p,
  .status-strip { display: none; }
  .brand h1 { overflow: hidden; margin: 0; font-size: 13.5px; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { display: grid; width: 100%; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 5px; }
  .model-picker { width: 100%; min-width: 0; }
  .model-picker-label { display: none; }
  .model-picker select { width: 100%; min-width: 0; max-width: none; min-height: 44px; font-size: 16px; }
  .connect-dymon { grid-column: 1 / -1; min-height: 44px; }
  .sessions-toggle,
  .refresh-research { min-height: 44px; padding: 0 8px; font-size: 11px; }

  .sidebar {
    min-width: 0;
    min-height: 0;
    overflow: visible;
    padding-right: env(safe-area-inset-right, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-head { padding: 10px 12px 7px; }
  .market-search-shell { z-index: 30; }
  .search-box { min-height: 44px; margin: 0 10px 8px; padding: 7px 9px; }
  .search-box input { font-size: 16px; }
  .market-search-results {
    left: 8px;
    right: 8px;
    z-index: 32;
    max-height: min(50vh, 360px);
    max-height: min(50dvh, 360px);
    padding: 7px;
    -webkit-overflow-scrolling: touch;
  }
  .market-search-result { align-items: center; min-height: 48px; padding: 8px; }
  .scope-scroll {
    min-height: 0;
    max-height: min(62vh, 560px);
    max-height: min(62dvh, 560px);
    flex: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .templates-panel summary { align-items: center; padding: 9px 10px; }
  .template-select-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .template-select-row select { min-width: 0; font-size: 16px; }
  .template-select-row button { min-width: 56px; }
  .segmented button { min-width: 0; min-height: 44px; padding: 6px 3px; }
  .dimension-options,
  .scope-dimensions .index-group[data-group="perspectives"] .dimension-options,
  .scope-dimensions .index-group[data-group="types"] .dimension-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .dimension-options .index-row,
  .index-row { min-height: 44px; padding: 8px 7px; }
  .dimension-options .index-label { font-size: 11.5px; line-height: 1.3; }
  .selection-tools { gap: 8px; }
  .selection-tools button { min-height: 44px; }

  .custom-research { padding: 8px 10px; }
  .custom-research textarea { min-height: 72px; max-height: 180px; font-size: 16px; }
  .report-controls { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 9px 10px; }
  .report-controls > * { grid-column: 1; }
  .report-controls select { min-height: 44px; font-size: 16px; }
  .generate-btn { min-height: 48px; padding: 10px 12px; }
  .side-footer { padding-bottom: env(safe-area-inset-bottom, 0px); }

  .workspace {
    width: 100%;
    min-width: 0;
    overflow: visible;
    grid-template-rows: 620px 520px;
    grid-template-rows: max(520px, calc(100dvh - 84px)) max(480px, 72dvh);
    gap: 8px;
    padding: 8px calc(8px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
  }
  .workspace.report-focus {
    grid-template-rows: 620px 55px;
    grid-template-rows: max(520px, calc(100dvh - 84px)) 55px;
  }

  .panel-head,
  .panel-head.compact { min-height: auto; align-items: flex-start; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .panel-actions,
  .chat-controls { width: 100%; min-width: 0; flex-wrap: wrap; gap: 6px; }
  .model-context-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .model-badge { max-width: min(100%, 180px); }
  .panel-actions button,
  .chat-controls > button,
  .compact-effort select { min-height: 44px; }
  .job-state,
  .run-timer,
  .claude-only,
  .model-context-label,
  .compact-effort { min-height: 44px; align-items: center; }
  .workspace.report-focus .chat-panel .panel-head { min-height: 55px; align-items: center; flex-wrap: nowrap; }
  .workspace.report-focus .chat-panel .chat-controls { display: none; }
  .report-prompt .prompt-preview-body { max-height: 96px; }

  .report-toc,
  .prompt-popover {
    position: fixed;
    inset: calc(8px + env(safe-area-inset-top, 0px)) calc(8px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
    z-index: 58;
    display: flex;
    width: auto;
    max-height: none;
    flex-direction: column;
    overflow: hidden;
    padding: 12px;
    border-radius: 14px;
    background: var(--panel);
    overscroll-behavior: contain;
  }
  .report-toc[hidden],
  .prompt-popover[hidden] { display: none; }
  .report-toc-links,
  .prompt-popover-body { min-height: 0; max-height: none; flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
  .report-toc-link { min-height: 44px; }

  .markdown-body {
    max-width: none;
    padding: 18px 14px calc(38px + env(safe-area-inset-bottom, 0px));
    overflow-wrap: anywhere;
    font-size: 15px;
    line-height: 1.65;
  }
  .markdown-body h1 { font-size: 21px; }
  .markdown-body pre,
  .markdown-body .md-table,
  .report-table-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .report-table-scroll > table { width: max-content; min-width: 100%; }
  .markdown-body code,
  .markdown-body a { overflow-wrap: anywhere; word-break: break-word; }
  .markdown-body svg { width: 100%; height: auto; }

  .conversation { padding: 10px; -webkit-overflow-scrolling: touch; }
  .message { max-width: 94%; padding: 10px 11px; font-size: 14px; }
  .composer { grid-template-columns: minmax(0, 1fr) auto; gap: 7px; padding: 9px 10px calc(9px + env(safe-area-inset-bottom, 0px)); }
  .composer textarea { min-height: 48px; max-height: 160px; font-size: 16px; }
  .composer button { min-width: 56px; height: 48px; padding: 0 12px; }

  .sessions-drawer {
    inset: 0;
    width: auto;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  }
  .sessions-drawer-head { min-height: 64px; gap: 8px; padding: 10px 12px; }
  .sessions-drawer-actions { gap: 5px; }
  .sessions-drawer-actions button { min-height: 44px; padding: 6px 8px; }
  .archive-directory-row { grid-template-columns: minmax(0, 1fr); }
  .archive-directory-row #saveArchiveDirectoryBtn { grid-column: auto; }
  .sessions-list { -webkit-overflow-scrolling: touch; }
  .session-card-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .session-card-actions button { min-height: 44px; }
  .session-card-actions .delete-session { grid-column: 1 / -1; }

  .template-modal {
    inset: 0;
    width: auto;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    transform: none;
    border: 0;
    border-radius: 0;
  }
  .template-modal-head { padding: calc(12px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 12px calc(12px + env(safe-area-inset-left, 0px)); }
  .template-modal-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .template-library { min-height: auto; padding: 12px calc(12px + env(safe-area-inset-right, 0px)) 12px calc(12px + env(safe-area-inset-left, 0px)); border-right: 0; border-bottom: 1px solid var(--line); }
  .template-list { display: flex; gap: 8px; margin-top: 9px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
  .template-list-item { width: auto; flex: 0 0 240px; flex-basis: min(76vw, 260px); margin-bottom: 0; }
  .template-editor { min-height: auto; overflow: visible; padding: 14px calc(14px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px)); }
  .template-editor textarea { min-height: 240px; flex: none; font-size: 16px; }
  .template-editor-preview { max-height: 140px; }
  .template-form-actions { flex-wrap: wrap; }
  .template-form-actions button { min-height: 44px; }
  .template-save-note { order: 3; flex: 1 0 100%; }

  .toast {
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    max-width: none;
    transform: translateY(16px);
  }
  .toast.show { transform: translateY(0); }
}
