* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #0e0e0e; color: #ddd; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

#header { padding: 8px 14px; background: #1a1a1a; border-bottom: 1px solid #222; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
#header h1 { font-size: 14px; font-weight: 600; color: #eee; flex-shrink: 0; }
#file-info-bar { display: flex; align-items: center; padding: 4px 14px; background: #161616; border-bottom: 1px solid #2a2a2a; flex-shrink: 0; gap: 10px; }
#file-meta { font-size: 11px; color: #777; }
#file-select { background: #111; color: #aaa; border: 1px solid #333; border-radius: 3px; padding: 2px 6px; font-size: 11px; font-family: inherit; cursor: pointer; max-width: 260px; }
#file-select:focus { outline: none; border-color: #555; }
#file-select option { background: #1a1a1a; }
.clf-active { background: #1a2a1a !important; color: #59a14f !important; }
#status-bar { font-size: 11px; color: #f28e2b; margin-left: auto; }

#main { display: flex; flex: 1; overflow: hidden; }

#canvas-col { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

#controls {
  padding: 5px 10px; background: #161616; border-bottom: 1px solid #222;
  /* Grid: Zoom=auto | Contours=1fr | Spectrogram=2fr | Position+Playback=auto */
  display: grid; grid-template-columns: auto minmax(0,1fr) minmax(0,2fr) auto;
  gap: 0 16px; align-items: start;
  flex-shrink: 0; overflow-x: auto;
}
#btn-play:hover { background: #133a2a !important; }
#controls button { background: #2a2a2a; border: 1px solid #3a3a3a; color: #ccc; padding: 0 10px; border-radius: 3px; cursor: pointer; font-size: 12px; height: 22px; box-sizing: border-box; line-height: 22px; }
#controls button:hover { background: #383838; }
.ctrl-group { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ctrl-group-label { font-size: 9px; color: #555; text-transform: uppercase; letter-spacing: .07em; line-height: 1; }
.ctrl-group-body { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 4px; }
.ctrl-lbl { color: #aaa; font-size: 11px; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.ctrl-sep { width: 1px; height: 28px; background: #2a2a2a; flex-shrink: 0; }
/* Headerless sub-group: items stack in a column, used inside ctrl-group-body */
.ctrl-subgroup { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
/* ctrl-nowrap: subgroups inside always sit side-by-side, never stack */
.ctrl-nowrap { flex-wrap: nowrap !important; }
/* 2-column grid variant: items distribute evenly 2 per row.
   width:100% is required so 1fr columns resolve against the flex-allocated
   parent width rather than falling back to content-based sizing. */
.ctrl-2col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 4px 10px; min-width: 0; width: 100%; }
/* Inside a 2-col label: right-align left text, left-align right text, slider fills middle */
.ctrl-2col .ctrl-lbl .sl-l { width: 24px; text-align: right; flex-shrink: 0; }
.ctrl-2col .ctrl-lbl .sl-r { width: 30px; text-align: left;  flex-shrink: 0; }
.ctrl-2col .ctrl-lbl input[type=range] { flex: 1; min-width: 30px; width: auto; }
/* Asymmetric grid: col-1=auto (checkboxes, nowrap), col-2=1fr (sliders, expanding).
   width:100% + min-width:0 on labels forces them to fill their cells so flex:1
   on the range input has definite space to grow into. */
.ctrl-chk-sl { display: grid; grid-template-columns: min-content minmax(0,1fr); gap: 4px 10px; min-width: 0; width: 100%; }
.ctrl-chk-sl .ctrl-lbl { width: 100%; min-width: 0; }
.ctrl-chk-sl .ctrl-lbl input[type=range] { flex: 1; min-width: 30px; width: auto; }

/* ── Cross-browser range slider track fill ───────────────────────────── */
input[type=range] {
  -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px; outline: none; cursor: pointer;
  /* fill left of thumb; --fill and --pct are set by JS per slider */
  background: linear-gradient(to right, var(--fill,#888) var(--pct,0%), #3a3a3a var(--pct,0%));
  vertical-align: middle;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--fill, #aaa); cursor: pointer;
  box-shadow: 0 0 0 2px #161616;
}
/* Firefox track / progress / thumb */
input[type=range]::-moz-range-track   { height: 4px; background: #3a3a3a; border-radius: 2px; }
input[type=range]::-moz-range-progress{ height: 4px; background: var(--fill,#888); border-radius: 2px; }
input[type=range]::-moz-range-thumb   {
  border: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--fill,#aaa); cursor: pointer;
  box-shadow: 0 0 0 2px #161616;
}
.time-display { color: #aaa; font-size: 11px; min-width: 13em; line-height: 1.3; }

#canvas-wrap { position: relative; flex: 1; overflow: hidden; display: flex; flex-direction: row; }
#mainCanvas { display: block; flex: 1; min-width: 0; cursor: crosshair; }
/* PSD transport — replaces the old freq-scrollbar, interactive freq nav */
#psdCanvas { display: block; flex-shrink: 0; width: 80px; background: #0d0d0d;
             border-left: 1px solid #1c1c1c; cursor: ns-resize; user-select: none; }

/* Frequency range scrollbar */
#freq-scrollbar { display: none; }   /* replaced by PSD transport canvas */
#freq-sb-track  { position: absolute; left: 4px; right: 4px; top: 0; bottom: 0; }
#freq-sb-fill   { position: absolute; left: 0; right: 0; background: #2d3d2d; border-radius: 2px; cursor: grab; }
#freq-sb-fill:active { cursor: grabbing; }
#freq-sb-fill:hover  { background: #3a4e3a; }
.freq-sb-handle { position: absolute; left: -2px; right: -2px; height: 7px; background: #f28e2b; border-radius: 3px; cursor: ns-resize; transform: translateY(-50%); }
.freq-sb-handle:hover { background: #ffba5a; }
/* Tick marks */
.freq-sb-tick { position: absolute; right: 0; width: 4px; height: 1px; background: #333; pointer-events: none; }
#tooltip { position: absolute; background: rgba(10,10,10,0.92); border: 1px solid #333; border-radius: 4px; padding: 8px 10px; font-size: 11px; line-height: 1.6; pointer-events: none; display: none; max-width: 220px; z-index: 10; }
#tooltip .sp-name { font-size: 12px; font-weight: 700; margin-bottom: 3px; }
#tooltip .param { color: #aaa; }
#tooltip .param span { color: #eee; }
/* Call-ID navigator in toolbar — matches button height via same padding+font-size */
.call-id-input { width: 46px; background: #1a1a1a; border: 1px solid #333; color: #aaa;
                 font-size: 12px; padding: 0 4px; border-radius: 3px; text-align: center;
                 height: 22px; box-sizing: border-box; line-height: 22px;
                 -moz-appearance: textfield; }
.call-id-input::-webkit-outer-spin-button,
.call-id-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

#overview-wrap { flex-shrink: 0; height: 64px; background: #111; border-top: 1px solid #222; position: relative; }
#overviewCanvas { display: block; }

/* ── Right-panel accordion ── */
#detail { width: 260px; flex-shrink: 0; background: #131313; border-left: 1px solid #222; overflow: hidden; display: flex; flex-direction: column; }

/* Call accordion – top */
/* ── Accordion layout ──────────────────────────────────────── */
/* Call section — top */
#acc-call-wrap { flex: 0 0 auto; display: flex; flex-direction: column; min-height: 0; }
#acc-call-wrap.acc-open { flex: 1 1 0; }
.acc-section-header { display: flex; align-items: center; gap: 7px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #222; user-select: none; background: #141414; flex-shrink: 0; }
.acc-section-header:hover { background: #1a1a1a; }
.acc-chevron { font-size: 10px; color: #555; width: 10px; flex-shrink: 0; }
.acc-section-title { font-size: 11px; color: #666; text-transform: uppercase; letter-spacing: .08em; flex: 1; }
.acc-section-meta { font-size: 11px; color: #aaa; font-weight: 600; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Body is hidden by default; grows + scrolls when its section has .acc-open */
.acc-body { display: none; overflow-y: auto; flex: 1 1 0; min-height: 0; padding: 12px; }
#acc-call-wrap.acc-open .acc-body { display: block; }
.acc-empty { color: #555; font-size: 12px; }
.acc-sp-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.acc-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.acc-table td { padding: 3px 0; color: #aaa; }
.acc-table td:last-child { color: #ddd; text-align: right; }
.acc-sub-header { font-size: 10px; color: #555; text-transform: uppercase; letter-spacing: .07em; border-top: 1px solid #1e1e1e; margin-top: 10px; padding-top: 8px; margin-bottom: 5px; display: flex; align-items: center; justify-content: space-between; }
.acc-zoom-btn { cursor: pointer; color: #f28e2b; font-size: 11px; text-transform: none; letter-spacing: 0; }

/* Species section — always fills remaining panel space */
#acc-species { flex: 1 1 0; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid #222; }

/* Scrollable container — flex column so items stack; overflow hidden (body scrolls inside) */
#acc-sp-scroll { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; overflow: hidden; }

/* Each species item: fixed-height header by default; grows to fill remaining space when open */
.sp-acc-item { flex: 0 0 auto; border-top: 1px solid #1a1a1a; }
.sp-acc-item.acc-open { flex: 1 1 0; display: flex; flex-direction: column; min-height: 0; }
.sp-acc-header { display: flex; align-items: center; gap: 6px; padding: 7px 10px; cursor: pointer; user-select: none; flex-shrink: 0; }
.sp-acc-header:hover { background: #181818; }
.sp-acc-header.hidden-sp { opacity: 0.35; }
.sp-acc-header.acc-active { background: #1a1a1a; }
/* Body hidden by default; when item is open it fills remaining space and scrolls internally */
.sp-acc-body { display: none; padding: 12px; border-bottom: 1px solid #1c1c1c; }
.sp-acc-item.acc-open .sp-acc-body { display: block; overflow-y: auto; flex: 1 1 0; min-height: 0; }
.sp-acc-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.sp-acc-chk { cursor: pointer; accent-color: #f28e2b; flex-shrink: 0; }
.sp-acc-name { font-size: 11px; color: #aaa; flex: 1; }
.sp-acc-count { font-size: 10px; color: #555; }
.sp-acc-arrow { font-size: 9px; color: #444; margin-left: 3px; }
.sp-solo-btn { background: none; border: none; cursor: pointer; color: #3a3a3a; font-size: 13px; padding: 0 1px; line-height: 1; flex-shrink: 0; }
.sp-solo-btn:hover { color: #666; }
.sp-solo-btn.soloed { color: #59a14f; }

/* Shared content styles (used in both accordions) */
.sp-section { margin-bottom: 12px; }
.sp-section h4 { font-size: 10px; color: #555; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 5px; }
.sp-section p { font-size: 11px; color: #888; line-height: 1.65; margin: 0; }
.sp-profile-row { display: flex; justify-content: space-between; font-size: 11px; padding: 2px 0; border-bottom: 1px solid #1a1a1a; }
.sp-profile-row .prl { color: #666; }
.sp-profile-row .prv { color: #bbb; }
.sp-stats-tbl { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; }
.sp-stats-tbl th { font-size: 9px; color: #444; text-align: right; padding: 1px 3px; font-weight: normal; text-transform: uppercase; }
.sp-stats-tbl th:first-child { text-align: left; }
.sp-stats-tbl td { padding: 2px 3px; color: #888; text-align: right; }
.sp-stats-tbl td:first-child { color: #666; text-align: left; }
.ref-tag { font-size: 10px; background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 3px; padding: 1px 5px; color: #666; display: inline-block; margin: 2px 2px 2px 0; }
a.ref-tag { color: #76b7b2; text-decoration: none; }
a.ref-tag:hover { color: #9dd4d0; border-color: #3a5a5a; }

#progress-overlay { position: absolute; inset: 0; background: rgba(14,14,14,0.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 20; }
#progress-overlay p { color: #aaa; font-size: 13px; }
#pbar-wrap { width: 260px; height: 6px; background: #2a2a2a; border-radius: 3px; }
#pbar { height: 100%; background: #f28e2b; border-radius: 3px; width: 0%; transition: width 0.3s; }

/* ── Modal dialogs ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.72); z-index: 100; display: none; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: #181818; border: 1px solid #333; border-radius: 8px; display: flex; flex-direction: column; max-height: 88vh; box-shadow: 0 8px 40px rgba(0,0,0,0.6); }
.modal-header { padding: 14px 18px; border-bottom: 1px solid #2a2a2a; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.modal-header h2 { font-size: 14px; font-weight: 600; color: #eee; flex: 1; }
.modal-close { background: none; border: none; color: #666; font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: #ccc; }
.modal-body { overflow-y: auto; padding: 18px; flex: 1; }

/* Session dialog */
#session-modal .modal { width: min(860px, 96vw); }
.conv-turn { margin-bottom: 18px; }
.conv-turn .role { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; margin-bottom: 5px; }
.conv-turn.user .role { color: #76b7b2; }
.conv-turn.assistant .role { color: #f28e2b; }
.conv-turn .bubble { background: #111; border: 1px solid #252525; border-radius: 6px; padding: 10px 14px; font-size: 12px; line-height: 1.7; color: #ccc; white-space: pre-wrap; word-break: break-word; }
.conv-turn.user .bubble { border-color: #1e3333; }
.conv-turn .ts { font-size: 10px; color: #444; margin-top: 3px; }

/* Tool-call entries — compact single-line rows between chat bubbles */
.conv-turn.tool { margin-bottom: 2px; }
.conv-turn.tool .tool-row {
  display: flex; align-items: baseline; gap: 7px;
  padding: 2px 10px 2px 12px;
  border-left: 2px solid #242424;
  font-size: 11px; line-height: 1.4;
  overflow: hidden;
}
.conv-turn.tool.has-detail .tool-row { cursor: pointer; }
.conv-turn.tool.has-detail .tool-row:hover { background: rgba(255,255,255,0.025); }
.conv-turn.tool .tool-icon { color: #444; flex-shrink: 0; font-style: normal; }
.conv-turn.tool .tool-name { color: #59a14f; font-weight: 700; flex-shrink: 0; min-width: 36px; }
.conv-turn.tool .tool-summary {
  color: #666; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.conv-turn.tool .tool-result {
  color: #444; font-size: 10px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  flex-shrink: 0; max-width: 280px;
}
.conv-turn.tool .tool-expander {
  color: #3a3a3a; font-size: 9px; flex-shrink: 0;
  display: inline-block; transition: transform 0.12s; line-height: 1;
}
.conv-turn.tool.open .tool-expander { transform: rotate(90deg); color: #555; }
/* Expanded command block */
.conv-turn.tool .tool-detail { display: none; padding: 4px 12px 6px 14px; }
.conv-turn.tool.open .tool-detail { display: block; }
.conv-turn.tool .tool-cmd {
  background: #0c0c0c; border: 1px solid #1e1e1e; border-radius: 3px;
  padding: 6px 9px; font-size: 10px; color: #888; line-height: 1.55;
  white-space: pre-wrap; word-break: break-all; font-family: inherit; margin: 0;
}
.conv-turn.tool.tool-error .tool-row { border-left-color: #4a1515; }
.conv-turn.tool.tool-error .tool-name { color: #c05050; }
.conv-turn.tool.tool-error .tool-result { color: #804040; }

/* Tools embedded inside an assistant bubble */
.bubble-tools {
  margin-top: 8px; padding-top: 6px;
  border-top: 1px solid #1e1e1e;
  white-space: normal;   /* override bubble's pre-wrap for tool rows */
}
.bubble-tool { margin-bottom: 0; }
.bubble-tool .tool-row {
  border-left: none !important;
  padding-left: 0 !important;
}
.bubble-tool.has-detail .tool-row:hover { border-radius: 2px; }
.bt-dur { color: #444; font-size: 10px; }

/* Response stats line (under assistant bubbles) */
.conv-stats {
  font-size: 10px; color: #3a3a3a; margin-top: 3px;
  padding-left: 2px; display: flex; gap: 8px; align-items: center;
}
.conv-stats .cs-think { color: #59a14f; }
.conv-stats .cs-dur   { color: #555; }
.conv-stats .cs-out   { color: #555; }
.conv-stats .cs-in    { color: #3a3a3a; }

/* Session-continuation / injected notes */
.conv-turn.note .role { color: #556; font-style: italic; }
.conv-turn.note .bubble {
  background: #0e0e12; border-color: #1e1e2a; color: #777;
  font-size: 11px; font-style: italic;
}

/* About dialog */
#about-modal .modal { width: min(560px, 96vw); }
.about-section { margin-bottom: 18px; }
.about-section h3 { font-size: 12px; color: #f28e2b; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 8px; }
.about-section p, .about-section li { font-size: 12px; color: #aaa; line-height: 1.7; }
.about-section a { color: #76b7b2; text-decoration: none; }
.about-section a:hover { text-decoration: underline; }
.about-section ul { padding-left: 18px; }
.apology { background: #1a1410; border: 1px solid #3a2a10; border-radius: 6px; padding: 12px 14px; margin-top: 8px; font-size: 12px; color: #aaa; line-height: 1.7; font-style: italic; }

/* PSD mode toggle — floats at top-right of psdCanvas, pointer-events on buttons only */
#psd-mode-toggle {
  position: absolute;
  top: 2px;
  right: 1px;
  z-index: 5;
  pointer-events: none;
  display: flex;
  border: 1px solid #2a3a2a;
  border-radius: 3px;
  overflow: hidden;
}
#psd-mode-toggle button {
  background: #111;
  color: #555;
  border: none;
  padding: 2px 5px;
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  pointer-events: auto;
  line-height: 1.4;
}
#psd-mode-toggle button + button { border-left: 1px solid #2a3a2a; }
#psd-mode-toggle button:hover { background: #1a1a1a; color: #888; }

/* Tile generation progress overlay */
#tile-prog { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,0.80); color: #aaa; font-size: 10px; font-family: inherit; padding: 6px 9px; border-radius: 3px; pointer-events: none; z-index: 11; display: none; min-width: 158px; border: 1px solid #2a3a2a; }
#tile-prog .tp-title { font-size: 9px; color: #59a14f; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 5px; }
#tile-prog .tp-row { display: flex; align-items: center; gap: 7px; line-height: 16px; }
#tile-prog .tp-lbl { width: 26px; color: #777; text-align: right; font-size: 9px; }
#tile-prog .tp-bar { flex: 1; height: 4px; background: #222; border-radius: 2px; overflow: hidden; }
#tile-prog .tp-fill { display: block; height: 100%; background: #2a5a2a; border-radius: 2px; transition: width 0.3s linear; }
#tile-prog .tp-fill.running { background: #59a14f; }
#tile-prog .tp-cnt { width: 54px; text-align: right; color: #888; font-size: 9px; }
