/* =========================================================
   CONTENT STUDIO — "lab" layout
   Controls rail on the left; a stream of runs on the right. The agent
   console is a light, monospaced log that streams what the agent is
   doing, styled like the rest of the app rather than a dark terminal.
========================================================= */

:root {
    --lab-ink: #0c151e;                 /* dark CTA surfaces: generate button, new-chat, user bubble */
    --lab-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.lab {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

/* ---------- controls rail ---------- */

.lab-rail {
    position: sticky;
    top: calc(var(--topbar) + 12px);
    max-height: calc(100vh - var(--topbar) - 28px);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.lab-brief {
    padding: 14px 14px 10px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface-soft), var(--surface));
}

.lab-label {
    display: block;
    margin-bottom: 5px;
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: .02em;
    color: var(--text-3);
}

#studioPrompt {
    width: 100%;
    min-height: 92px;
    max-height: 260px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 10px 11px;
    font: inherit;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#studioPrompt:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.lab-brief-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 7px;
    font-size: 10.5px;
    color: var(--text-3);
}

.lab-target { font-weight: 700; color: var(--text-2); }

.lab-hint kbd, .lab-empty kbd {
    padding: 0 4px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    font: inherit;
    font-size: 9.5px;
    font-weight: 700;
    background: var(--surface);
}

.lab-groups {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
}

.lab-group { border-radius: 11px; }
.lab-group + .lab-group { margin-top: 2px; }
.lab-group.is-open { background: var(--surface-soft); }

.lab-group-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 9px;
    border: 0;
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.lab-group-head::after {
    content: "";
    width: 7px;
    height: 7px;
    margin-left: 2px;
    border-right: 1.6px solid var(--text-3);
    border-bottom: 1.6px solid var(--text-3);
    transform: rotate(45deg) translateY(-2px);
    transition: transform var(--transition);
    flex: 0 0 auto;
}

.lab-group.is-open .lab-group-head::after { transform: rotate(225deg) translateY(-1px); }

.lab-group-title { font-size: 12.5px; font-weight: 800; color: var(--text); }

.lab-group-sum {
    flex: 1;
    min-width: 0;
    text-align: right;
    font-size: 11px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lab-group-sum.is-set { color: var(--primary-dark); font-weight: 700; }

.lab-group-body {
    display: none;
    padding: 2px 9px 12px;
    flex-direction: column;
    gap: 11px;
}

.lab-group.is-open .lab-group-body { display: flex; }
.lab-group.is-disabled .lab-group-body > :not(.lab-off-note) { opacity: .45; pointer-events: none; }

.lab-off-note { display: none; }
.lab-group.is-disabled .lab-off-note { display: block; }

.lab-field { display: block; min-width: 0; }
.lab-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }

.studio-folder-dropdown { position: relative; }

.studio-folder-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-2);
    cursor: pointer;
    transition: border-color var(--transition);
}

.studio-folder-trigger:hover,
.studio-folder-dropdown.open .studio-folder-trigger { border-color: var(--primary-soft); }

.studio-folder-chevron {
    width: 14px;
    height: 14px;
    color: var(--text-3);
    transition: transform var(--transition);
}

.studio-folder-dropdown.open .studio-folder-chevron { transform: rotate(180deg); }

#studioFolders.studio-folder-panel { display: none; margin-top: 8px; }
.studio-folder-dropdown.open #studioFolders.studio-folder-panel { display: flex; }

.lab-select, .lab-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 9px;
    font: inherit;
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
}

textarea.lab-input { resize: vertical; line-height: 1.5; }
.lab-select:focus, .lab-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.lab-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-2);
    cursor: pointer;
    padding-bottom: 6px;
}

.lab-toggle input { accent-color: var(--primary); width: 15px; height: 15px; }

.lab-note { margin: 0; font-size: 10.5px; line-height: 1.5; color: var(--text-3); }

.lab .studio-seg { display: flex; flex-wrap: wrap; width: 100%; }
.lab .studio-seg-btn { flex: 1 1 auto; justify-content: center; }

.lab-quick { display: flex; flex-wrap: wrap; gap: 6px; }

.lab-quick button {
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-2);
    cursor: pointer;
}

.lab-quick button:hover { border-color: var(--primary); color: var(--primary-dark); }

/* trends, as selectable cards */
.lab-trends { display: flex; flex-direction: column; gap: 6px; }

.lab-trend {
    display: flex;
    gap: 9px;
    align-items: flex-start;
    width: 100%;
    padding: 8px 9px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.lab-trend.is-on { border-color: var(--primary); background: var(--primary-soft-2); }
.lab-trend:disabled { opacity: .45; cursor: not-allowed; }

.lab-trend-box {
    flex: 0 0 15px;
    height: 15px;
    margin-top: 1px;
    border: 1.6px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface);
}

.lab-trend.is-on .lab-trend-box {
    border-color: var(--primary);
    background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2'%3E%3Cpath d='M5 12l4 4L19 6'/%3E%3C/svg%3E") center/11px no-repeat;
}

.lab-trend-title { display: block; font-size: 11.5px; font-weight: 800; color: var(--text); line-height: 1.35; }
.lab-trend-meta { display: block; margin-top: 2px; font-size: 10px; color: var(--text-3); }
.lab-trend-usage { display: block; margin-top: 4px; font-size: 10.5px; color: var(--text-2); line-height: 1.4; }

.studio-insp-chip .lab-star { color: var(--primary); font-size: 11px; }

/* the generate bar */
.lab-go {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.lab-reset {
    border: 0;
    background: none;
    font: inherit;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-3);
    cursor: pointer;
}

.lab-reset:hover { color: var(--danger); }

.lab-generate {
    position: relative;
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 11px 20px;
    border: 0;
    border-radius: 11px;
    background: var(--lab-ink);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    overflow: hidden;
    isolation: isolate;
}

.lab-generate svg { width: 15px; height: 15px; color: var(--primary); }

/* a slow warm sheen across the button: the one flourish in the rail */
.lab-generate-glow {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(110deg, transparent 20%, rgba(0, 113, 219, .45) 50%, transparent 80%);
    background-size: 220% 100%;
    animation: lab-sheen 3.2s ease-in-out infinite;
}

.lab-generate:disabled { opacity: .5; cursor: not-allowed; }
.lab-generate:disabled .lab-generate-glow { animation: none; opacity: 0; }

/* Slack-style split send: the main action plus a chevron that offers the other one */
.send-split { position: relative; margin-left: auto; display: inline-flex; align-items: stretch; }
.send-split .lab-generate { margin-left: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.send-split-toggle {
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
    border: 0;
    border-left: 1px solid rgba(255, 255, 255, .25);
    border-radius: 0 11px 11px 0;
    background: var(--lab-ink);
    color: rgba(255, 255, 255, .8);
    cursor: pointer;
}
.send-split-toggle svg { width: 14px; height: 14px; }
.send-split-toggle:hover { color: #fff; }
.send-split-menu {
    display: none;
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 30;
    min-width: 240px;
    padding: 6px;
    border: 1px solid var(--line, #e5e5e5);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .14);
}
.send-split.open .send-split-menu { display: block; }
.send-split-menu button {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 8px;
    background: none;
    text-align: left;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--lab-ink);
    cursor: pointer;
}
.send-split-menu button small { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted, #777); }
.send-split-menu button:hover { background: var(--soft, #f4f4f4); }

@keyframes lab-sheen { 0% { background-position: 120% 0; } 60%, 100% { background-position: -120% 0; } }

/* ---------- stage: the runs ---------- */

.lab-stage { min-width: 0; }

.lab-stage-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 12px;
}

.lab-stage-title { font-size: 16px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; }
.lab-stage-sub { font-size: 11.5px; color: var(--text-3); }

.lab-stream { display: flex; flex-direction: column; gap: 16px; }

.lab-empty {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    padding: 48px 32px 30px;
    text-align: center;
}

/* a faint grid, the studio's "workbench" */
.lab-empty-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 28px 28px;
    mask-image: radial-gradient(ellipse at top, #000 20%, transparent 70%);
    opacity: .6;
}

.lab-empty > :not(.lab-empty-grid) { position: relative; }

.lab-empty h2 {
    margin: 0 0 10px;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}

.lab-empty p {
    margin: 0 auto 22px;
    max-width: 56ch;
    font-size: 13px;
    line-height: 1.65;
    color: var(--text-2);
}

.lab-starters { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.lab-starter {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
    font: inherit;
    font-size: 12.5px;
    font-weight: 800;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: border-color var(--transition), transform var(--transition);
}

.lab-starter span { font-size: 10px; font-weight: 700; color: var(--primary-dark); }
.lab-starter:hover { border-color: var(--primary); transform: translateY(-1px); }

/* ---------- a run ---------- */

.run {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.run-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 13px 16px 0;
}

.run-time { margin-left: auto; font-size: 11px; color: var(--text-3); }

.run-brief {
    margin: 9px 16px 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.run-plan { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 16px 0; }

.run-chip {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-hover);
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-2);
}

/* ---------- the agent console ---------- */

.agent {
    margin: 13px 16px 0;
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--text);
    overflow: hidden;
    border: 1px solid var(--border);
}

.agent-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.agent-orb {
    flex: 0 0 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-3);
}

.agent.is-live .agent-orb { background: var(--primary); box-shadow: 0 0 0 0 rgba(0, 113, 219, .6); animation: agent-pulse 1.6s infinite; }
.agent.is-done .agent-orb { background: var(--success); }
.agent.is-failed .agent-orb { background: var(--danger); }

@keyframes agent-pulse { 70% { box-shadow: 0 0 0 7px rgba(0, 113, 219, 0); } 100% { box-shadow: 0 0 0 0 rgba(0, 113, 219, 0); } }

.agent-title { font-size: 12px; font-weight: 800; }
.agent-meta { font-family: var(--lab-mono); font-size: 10.5px; color: var(--text-3); margin-left: auto; }

.agent-chev {
    width: 7px;
    height: 7px;
    border-right: 1.6px solid var(--text-3);
    border-bottom: 1.6px solid var(--text-3);
    transform: rotate(45deg) translateY(-2px);
    transition: transform var(--transition);
}

.agent.is-open .agent-chev { transform: rotate(225deg); }

.agent-log {
    display: none;
    list-style: none;
    margin: 0;
    padding: 2px 12px 12px;
    border-top: 1px solid var(--border);
    font-family: var(--lab-mono);
    font-size: 11.5px;
    line-height: 1.6;
    max-height: 320px;
    overflow-y: auto;
}

.agent.is-open .agent-log { display: block; }

/* proposed ideas: same console chrome, body is the readable brief */
.idea-body { display: none; }
.idea.is-open .idea-body {
    display: block;
    margin: 0 12px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text);
}
.idea-actions { display: none; padding: 0 12px 12px; }
.idea.is-open .idea-actions { display: flex; justify-content: flex-end; }

.agent-line {
    display: grid;
    grid-template-columns: 44px 14px 1fr;
    gap: 6px;
    padding: 5px 0 0;
    animation: agent-in .25s ease-out both;
}

.agent-t { color: var(--text-3); font-size: 10.5px; padding-top: 1px; }
.agent-mark { color: var(--success); }
.agent-line.is-setup .agent-mark { color: var(--primary); }
.agent-line.is-fail { color: var(--danger); }
.agent-line.is-fail .agent-mark { color: var(--danger); }
.agent-line.is-plan { color: var(--text-3); }
.agent-line.is-plan .agent-mark { color: var(--text-3); }
.agent-msg { overflow-wrap: anywhere; }

/* the line the agent is on right now gets a blinking caret */
.agent.is-live .agent-line:last-child .agent-msg::after {
    content: "▍";
    margin-left: 3px;
    color: var(--primary);
    animation: agent-caret 1s steps(1) infinite;
}

@keyframes agent-caret { 50% { opacity: 0; } }
@keyframes agent-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- output + editing ---------- */

.run-output {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.run-output .cs-media { border-radius: 12px; }

.run-edited {
    align-self: flex-start;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 10.5px;
    font-weight: 800;
}

.run-edit { display: flex; flex-direction: column; gap: 10px; }
.run-edit .lab-input { font-size: 13px; }
.run-edit textarea.is-body { min-height: 220px; font-family: inherit; }

.run-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 16px; }
.run-actions .btn { padding: 7px 12px; font-size: 11.5px; }
.run-actions .run-spacer { flex: 1; }

.run-wait {
    padding: 14px 16px 16px;
    font-size: 12px;
    color: var(--text-3);
}

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
    .lab { grid-template-columns: 1fr; }
    .lab-rail { position: static; max-height: none; }
    .lab-groups { overflow: visible; }
}

@media (max-width: 720px) {
    .lab-row { grid-template-columns: 1fr; }
    .lab-empty { padding: 34px 18px 22px; }
    .agent-line { grid-template-columns: 38px 12px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .lab-generate-glow, .agent.is-live .agent-orb, .agent-line,
    .agent.is-live .agent-line:last-child .agent-msg::after { animation: none; }
}
