:root {
    --bg0: #05080f;
    --bg1: #081120;
    --panel: rgba(9, 17, 31, 0.88);
    --panel-strong: rgba(12, 23, 41, 0.96);
    --panel-soft: rgba(255, 255, 255, 0.045);
    --line: rgba(125, 201, 255, 0.13);
    --line-strong: rgba(0, 200, 255, 0.34);
    --cyan: #00c8ff;
    --cyan-dark: #0077b6;
    --teal: #00b8a9;
    --gold: #f0b429;
    --green: #19d18f;
    --amber: #f0b429;
    --red: #ff5c7a;
    --fg1: #f4f9ff;
    --fg2: #d4e3f5;
    --fg3: #9db1cc;
    --fg4: #687b98;
    --font-display: "Playfair Display", Georgia, serif;
    --font-body: "DM Sans", sans-serif;
    --font-mono: "IBM Plex Mono", monospace;
    --shadow: 0 22px 80px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg0);
    color: var(--fg2);
    font-family: var(--font-body);
}

body {
    min-height: 100vh;
    overflow: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.atm {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.atm-grid {
    background-image:
        linear-gradient(rgba(0, 200, 255, 0.055) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 200, 255, 0.055) 1px, transparent 1px);
    background-size: 72px 72px;
    opacity: 0.34;
    mask-image: radial-gradient(circle at 48% 32%, #000 0, transparent 72%);
}

.atm-glow-a {
    width: 680px;
    height: 680px;
    left: -220px;
    top: -220px;
    background: rgba(0, 200, 255, 0.18);
    filter: blur(150px);
}

.atm-glow-b {
    width: 560px;
    height: 560px;
    right: -180px;
    bottom: -160px;
    background: rgba(0, 184, 169, 0.14);
    filter: blur(140px);
}

.app-shell {
    position: relative;
    z-index: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 68px;
    flex: 0 0 68px;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    background: rgba(5, 8, 15, 0.82);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(22px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.72rem;
    min-width: 220px;
}

.brand img {
    width: 112px;
    height: auto;
    display: block;
}

.brand span {
    display: grid;
    gap: 0.05rem;
}

.brand strong {
    color: var(--fg1);
    font-size: 0.96rem;
    letter-spacing: 0;
}

.brand small {
    color: var(--fg4);
    font: 600 0.64rem var(--font-mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.28rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.035);
}

.nav-links a {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    padding: 0 0.82rem;
    border-radius: 9px;
    color: var(--fg3);
    font-size: 0.82rem;
    font-weight: 700;
}

.nav-links a.is-active,
.nav-links a:hover {
    color: var(--fg1);
    background: rgba(0, 200, 255, 0.12);
}

.top-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.status-pill,
.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 0.75rem;
    color: var(--fg3);
    font: 600 0.66rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.status-pill i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 18px rgba(25, 209, 143, 0.65);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;
    min-height: 38px;
    border-radius: 12px;
    padding: 0 0.95rem;
    border: 1px solid transparent;
    font-weight: 800;
    font-size: 0.82rem;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--cyan-dark), var(--cyan)); color: #03101b; box-shadow: 0 10px 30px rgba(0, 200, 255, 0.22); }
.btn-outline { border-color: var(--line-strong); color: var(--fg1); background: rgba(0, 200, 255, 0.045); }
.btn-ghost { border-color: var(--line); color: var(--fg3); background: rgba(255, 255, 255, 0.035); }

.workspace {
    height: calc(100vh - 68px);
    min-height: 0;
    display: grid;
    grid-template-columns: 280px minmax(420px, 1fr) 340px;
    gap: 0.7rem;
    padding: 0.7rem;
}

.workspace-builder {
    grid-template-columns: 280px minmax(460px, 1fr) 360px;
}

.panel {
    min-height: 0;
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    backdrop-filter: blur(24px);
}

.panel-head {
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    padding: 0 0.9rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.032);
}

.panel-title {
    color: var(--fg1);
    font-weight: 800;
    font-size: 0.86rem;
}

.panel-kicker {
    color: var(--fg4);
    font: 600 0.62rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.11em;
}

.panel-body {
    height: calc(100% - 46px);
    min-height: 0;
    overflow: auto;
    padding: 0.8rem;
}

.panel-body::-webkit-scrollbar,
.chat-feed::-webkit-scrollbar,
.trace-list::-webkit-scrollbar { width: 8px; }

.panel-body::-webkit-scrollbar-thumb,
.chat-feed::-webkit-scrollbar-thumb,
.trace-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(125, 201, 255, 0.17);
}

.agent-list {
    display: flex;
    flex-direction: column;
    gap: 0.48rem;
}

.agent-card {
    width: 100%;
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 0.62rem;
    text-align: left;
    border: 1px solid rgba(125, 201, 255, 0.1);
    border-radius: 12px;
    padding: 0.65rem;
    color: inherit;
    background: rgba(255, 255, 255, 0.03);
}

.agent-card.is-active {
    border-color: var(--line-strong);
    background: linear-gradient(135deg, rgba(0, 200, 255, 0.15), rgba(0, 184, 169, 0.06));
}

.agent-mark,
.msg-avatar,
.preview-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #03101b;
    background: linear-gradient(135deg, var(--cyan), var(--teal));
    font: 800 0.74rem var(--font-mono);
}

.agent-card strong {
    display: block;
    color: var(--fg1);
    font-size: 0.88rem;
}

.agent-card span {
    display: block;
    margin-top: 0.12rem;
    color: var(--fg4);
    font: 600 0.62rem var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.agent-card p {
    margin: 0.34rem 0 0;
    color: var(--fg3);
    font-size: 0.76rem;
    line-height: 1.45;
}

.context-box {
    margin-top: 0.8rem;
    border: 1px solid var(--line);
    border-radius: 13px;
    padding: 0.72rem;
    background: rgba(255, 255, 255, 0.032);
}

.context-box h3 {
    margin: 0 0 0.45rem;
    color: var(--fg1);
    font-size: 0.82rem;
}

.context-row {
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    padding: 0.28rem 0;
    color: var(--fg3);
    font-size: 0.76rem;
}

.context-row b { color: var(--fg1); font-weight: 800; }

.tool-tags,
.prompt-stack,
.tmf-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.tool-tag,
.tmf-tag,
.prompt-chip {
    border: 1px solid var(--line);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.035);
    color: var(--fg3);
    padding: 0.28rem 0.45rem;
    font: 600 0.62rem var(--font-mono);
}

.prompt-chip {
    width: 100%;
    text-align: left;
    color: var(--fg2);
    padding: 0.55rem 0.62rem;
    line-height: 1.35;
}

.prompt-chip:hover {
    border-color: var(--line-strong);
    color: var(--fg1);
}

.chat-panel {
    display: flex;
    flex-direction: column;
}

.studio-hero {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 230px;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(135deg, rgba(0, 200, 255, 0.09), rgba(0, 184, 169, 0.035));
}

.studio-hero h1 {
    margin: 0;
    color: var(--fg1);
    font: 800 clamp(1.7rem, 3vw, 3rem) / 1.02 var(--font-display);
    letter-spacing: 0;
}

.studio-hero h1 em {
    color: var(--cyan);
    font-style: italic;
}

.studio-hero p {
    margin: 0.65rem 0 0;
    max-width: 760px;
    color: var(--fg3);
    line-height: 1.62;
    font-size: 0.95rem;
}

.hero-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.metric-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.65rem;
    background: rgba(5, 8, 15, 0.42);
}

.metric-card strong {
    display: block;
    color: var(--fg1);
    font: 800 1.35rem var(--font-display);
}

.metric-card span {
    display: block;
    margin-top: 0.12rem;
    color: var(--fg4);
    font: 600 0.58rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chat-feed {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 1rem;
}

.msg {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 0.7rem;
    margin-bottom: 1rem;
}

.msg-user {
    grid-template-columns: minmax(0, 1fr) 42px;
}

.msg-user .msg-avatar { grid-column: 2; background: rgba(255, 255, 255, 0.1); color: var(--fg2); }
.msg-user .msg-body { grid-column: 1; grid-row: 1; }

.msg-meta {
    margin-bottom: 0.3rem;
    color: var(--fg4);
    font: 700 0.62rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.msg-bubble {
    border: 1px solid var(--line);
    border-radius: 6px 14px 14px 14px;
    padding: 0.82rem 0.95rem;
    background: rgba(255, 255, 255, 0.04);
    color: var(--fg2);
    line-height: 1.62;
    font-size: 0.9rem;
}

.msg-user .msg-bubble {
    border-radius: 14px 6px 14px 14px;
    background: rgba(0, 200, 255, 0.09);
}

.msg-bubble strong { color: var(--fg1); }
.msg-bubble code { color: var(--cyan); font-family: var(--font-mono); font-size: 0.84em; }

.composer-zone {
    flex: 0 0 auto;
    padding: 0.75rem;
    border-top: 1px solid var(--line);
    background: rgba(5, 8, 15, 0.78);
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 0.55rem;
}

.composer textarea {
    width: 100%;
    min-height: 46px;
    max-height: 140px;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 13px;
    outline: none;
    padding: 0.78rem 0.85rem;
    background: rgba(255, 255, 255, 0.045);
    color: var(--fg1);
}

.composer textarea:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 4px rgba(0, 200, 255, 0.07);
}

.send-btn {
    width: 44px;
    height: 46px;
    border: 0;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--cyan), var(--teal));
    color: #03101b;
    font-weight: 900;
}

.send-btn:disabled { opacity: 0.45; cursor: wait; }

.composer-hint {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.48rem;
    color: var(--fg4);
    font: 600 0.62rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.locked-overlay {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    border: 1px solid rgba(240, 180, 41, 0.25);
    border-radius: 13px;
    padding: 0.7rem;
    background: rgba(240, 180, 41, 0.08);
    color: var(--fg2);
}

.locked-overlay span {
    font-size: 0.82rem;
    line-height: 1.4;
}

.trace-panel {
    display: flex;
    flex-direction: column;
}

.trace-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0.75rem;
}

.trace-step {
    border: 1px solid var(--line);
    border-left: 3px solid var(--cyan);
    border-radius: 12px;
    padding: 0.68rem;
    margin-bottom: 0.65rem;
    background: rgba(255, 255, 255, 0.035);
}

.trace-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    color: var(--fg1);
    font: 700 0.7rem var(--font-mono);
}

.trace-sub {
    margin-top: 0.36rem;
    color: var(--fg4);
    font: 600 0.6rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.trace-io {
    margin: 0.32rem 0 0;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--fg3);
    font: 500 0.64rem/1.5 var(--font-mono);
}

.answer-json {
    border-color: rgba(0, 184, 169, 0.4);
    border-left-color: var(--teal);
}

.health-critical { color: var(--red); }
.health-attention { color: var(--amber); }
.health-healthy { color: var(--green); }

.builder-grid {
    height: 100%;
    display: grid;
    grid-template-columns: inherit;
    gap: 0.7rem;
}

.builder-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.template-card,
.editor-section,
.inspect-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.035);
    padding: 0.75rem;
}

.template-card.is-active {
    border-color: var(--line-strong);
    background: rgba(0, 200, 255, 0.08);
}

.template-card h3,
.editor-section h3,
.inspect-card h3 {
    margin: 0 0 0.35rem;
    color: var(--fg1);
    font-size: 0.9rem;
}

.template-card p,
.editor-section p,
.inspect-card p {
    margin: 0;
    color: var(--fg3);
    line-height: 1.55;
    font-size: 0.8rem;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.field {
    display: grid;
    gap: 0.32rem;
}

.field-wide { grid-column: 1 / -1; }

.field label {
    color: var(--fg4);
    font: 700 0.62rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.field input,
.field select,
.field textarea {
    min-width: 0;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--fg1);
    padding: 0.68rem 0.75rem;
}

.field textarea {
    min-height: 180px;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    line-height: 1.55;
}

.check-row {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    padding: 0.48rem 0;
    border-bottom: 1px solid rgba(125, 201, 255, 0.08);
}

.check-row:last-child { border-bottom: 0; }

.check-row input { width: 16px; height: 16px; margin-top: 0.15rem; accent-color: var(--cyan); }
.check-row strong { display: block; color: var(--fg1); font-size: 0.8rem; }
.check-row span { display: block; color: var(--fg4); font-size: 0.72rem; line-height: 1.45; margin-top: 0.12rem; }

.proof-page {
    height: calc(100vh - 68px);
    overflow: auto;
    padding: 1rem;
}

.proof-hero {
    min-height: min(620px, calc(100vh - 100px));
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 42%);
    align-items: center;
    gap: 2rem;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: clamp(1.2rem, 4vw, 3rem);
    background: linear-gradient(135deg, rgba(0, 200, 255, 0.12), rgba(255, 255, 255, 0.035));
}

.proof-hero h1 {
    margin: 0;
    color: var(--fg1);
    font: 800 clamp(2.4rem, 6vw, 5.5rem) / 0.98 var(--font-display);
    max-width: 880px;
}

.proof-hero h1 em { color: var(--cyan); }
.proof-hero p { max-width: 760px; color: var(--fg3); line-height: 1.72; font-size: 1.05rem; }
.proof-hero img { width: 100%; border-radius: 18px; border: 1px solid var(--line); filter: brightness(0.78) saturate(0.9); }

.eyebrow {
    color: var(--cyan);
    font: 700 0.7rem var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.2rem; }

.proof-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 0.8rem;
}

.proof-grid article {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1rem;
    background: var(--panel);
}

.proof-grid span {
    color: var(--cyan);
    font: 700 0.7rem var(--font-mono);
}

.proof-grid h2 { color: var(--fg1); font-size: 1rem; margin: 0.6rem 0 0.35rem; }
.proof-grid p { color: var(--fg3); line-height: 1.58; font-size: 0.86rem; margin: 0; }

.image-band {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 0.8rem;
    padding-bottom: 1rem;
}

.image-band img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 16px;
    filter: brightness(0.78) saturate(0.88);
}

@media (max-width: 1180px) {
    body { overflow: auto; }
    .app-shell { min-height: 100vh; height: auto; }
    .workspace,
    .workspace-builder,
    .builder-grid {
        height: auto;
        min-height: calc(100vh - 68px);
        grid-template-columns: 1fr;
    }
    .panel { min-height: 320px; }
    .trace-panel { min-height: 520px; }
}

@media (max-width: 820px) {
    .topbar {
        height: auto;
        flex-wrap: wrap;
        padding: 0.75rem;
    }
    .brand { min-width: 0; }
    .nav-links { order: 3; width: 100%; overflow-x: auto; }
    .top-actions { margin-left: 0; flex-wrap: wrap; }
    .workspace { height: auto; padding: 0.55rem; }
    .studio-hero,
    .proof-hero,
    .proof-grid,
    .image-band {
        grid-template-columns: 1fr;
    }
    .hero-metrics,
    .field-grid {
        grid-template-columns: 1fr;
    }
    .composer-hint { flex-direction: column; gap: 0.25rem; }
}
