.agent-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: #171717;
    color: #e5e7eb;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.session-list,
.workflow-timeline,
.chat-messages {
    scrollbar-color: #4b5563 #1f1f1f;
    scrollbar-width: thin;
}

.session-list::-webkit-scrollbar,
.workflow-timeline::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.session-list::-webkit-scrollbar-track,
.workflow-timeline::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: #1f1f1f;
}

.session-list::-webkit-scrollbar-thumb,
.workflow-timeline::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 999px;
    border: 2px solid #1f1f1f;
}

.session-list::-webkit-scrollbar-thumb:hover,
.workflow-timeline::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.agent-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    gap: 1px;
    background: #2a2a2a;
    position: relative;
}

.pane-overlay-backdrop {
    position: absolute;
    inset: 0;
    z-index: 10;
    border: none;
    background: rgba(10, 10, 10, 0.55);
    padding: 0;
    cursor: pointer;
}

.session-pane,
.workflow-pane,
.chat-pane {
    background: #1f1f1f;
    min-height: 0;
    overflow: hidden;
}

.chat-pane {
    background: #262626;
}

.session-pane {
    width: 280px;
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    transition: width .2s ease, flex-basis .2s ease, opacity .2s ease, transform .2s ease;
}

.workflow-pane {
    width: 360px;
    flex: 0 0 360px;
    display: flex;
    flex-direction: column;
    transition: width .2s ease, flex-basis .2s ease, opacity .2s ease, transform .2s ease;
}

.chat-pane {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.chat-progress-card {
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid #3a3a3a;
    border-radius: 10px;
    background: #2b2b2b;
}

.chat-progress-status {
    font-size: 13px;
    font-weight: 600;
    color: #f3f4f6;
}

.chat-progress-steps {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-progress-step {
    font-size: 12px;
    color: #cbd5e1;
}

.pane-title {
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 0 16px;
    border-bottom: 1px solid #2f2f2f;
    background: #202020;
    color: #f3f4f6;
    font-size: 14px;
    font-weight: 600;
}

.session-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.workflow-pane-header,
.chat-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.pane-heading,
.pane-title-actions,
.chat-pane-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pane-heading {
    min-width: 0;
}

.pane-toggle-btn {
    padding: 5px 10px;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    background: #2b2b2b;
    color: #e5e7eb;
    font: inherit;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
}

.pane-toggle-btn:hover {
    background: #323232;
}

.chat-pane-nav-label {
    font-size: 13px;
    color: #d1d5db;
}

.session-actions {
    padding: 12px 16px;
    border-bottom: 1px solid #2f2f2f;
    background: #1d1d1d;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-filter,
.session-sort,
.mini-form .input,
.composer-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #3a3a3a;
    border-radius: 10px;
    background: #2a2a2a;
    color: #e5e7eb;
    font-size: 13px;
    box-sizing: border-box;
}

.session-filter::placeholder,
.composer-textarea::placeholder {
    color: #9ca3af;
}

.workflow-timeline {
    overflow-y: auto;
    padding: 18px 16px 18px 38px;
    min-height: 0;
}

.workflow-track {
    position: relative;
    --workflow-marker-center: -19px;
}

.workflow-track::before {
    content: "";
    position: absolute;
    left: var(--workflow-marker-center);
    top: 0;
    bottom: 0;
    width: 1px;
    background: #3a3a3a;
    transform: translateX(-50%);
}

.workflow-track.is-running::before {
    bottom: 10px;
}

.workflow-track::after {
    content: "";
    position: absolute;
    left: var(--workflow-marker-center);
    bottom: 0;
    width: 1px;
    background: #3a3a3a;
    transform: translateX(-50%);
}

.workflow-track.is-running::after {
    height: 10px;
    background: repeating-linear-gradient(to bottom, #6b7280 0 2px, transparent 2px 4px);
}

.workflow-track.is-complete::after {
    left: -23px;
    width: 10px;
    height: 1px;
    background: #3a3a3a;
}

.workflow-item {
    position: relative;
    margin-bottom: 14px;
}

.workflow-marker {
    position: absolute;
    left: -24px;
    top: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #60a5fa;
    transform: translateY(-50%);
}

.workflow-item.user .workflow-marker {
    background: #34d399;
}

.workflow-item.agent .workflow-marker {
    background: #60a5fa;
}

.workflow-item.tool .workflow-marker {
    background: #f59e0b;
}

.workflow-item.done .workflow-marker {
    background: #a78bfa;
}

.workflow-item.error .workflow-marker {
    background: #f87171;
}

.workflow-item.system .workflow-marker {
    background: #9ca3af;
}

.workflow-card {
    background: #262626;
    border: 1px solid #363636;
    border-radius: 12px;
    padding: 11px 12px;
}

.workflow-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
    color: #9ca3af;
    font-size: 12px;
}

.workflow-card-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
}

.workflow-title {
    font-size: 13px;
    font-weight: 600;
    color: #f3f4f6;
}

.workflow-time {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
}

.workflow-expand-btn {
    width: 22px;
    height: 22px;
    border: 1px solid #404040;
    border-radius: 999px;
    background: #2d2d2d;
    color: #d1d5db;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.workflow-expand-btn:hover {
    background: #343434;
}

.workflow-text {
    font-size: 13px;
    color: #d1d5db;
    line-height: 1.45;
}

.workflow-text-preview {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.workflow-details {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #363636;
    font-size: 13px;
    color: #d1d5db;
}

.workflow-detail-section + .workflow-detail-section {
    margin-top: 12px;
}

.workflow-detail-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #9ca3af;
}

.workflow-details-json {
    margin-top: 10px;
    padding: 10px;
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid #363636;
    background: #1b1b1b;
    font-size: 12px;
    color: #d1d5db;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #292929;
}

.chat-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.chat-row.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 50%;
    background: #3a3a3a;
    color: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.chat-row.user .chat-avatar {
    background: #4b5563;
}

.chat-row.assistant .chat-avatar {
    background: #374151;
}

.chat-row.system .chat-avatar {
    background: #52525b;
}

.chat-row.error .chat-avatar {
    background: #7f1d1d;
}

.chat-bubble {
    max-width: 720px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid #363636;
    background: #2a2a2a;
    color: #e5e7eb;
}

.chat-row.user .chat-bubble {
    background: #303846;
    border-color: #3f4a5b;
}

.chat-row.error .chat-bubble {
    background: #3a2020;
    border-color: #5b2d2d;
}

.chat-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 6px;
    color: #9ca3af;
    font-size: 11px;
}

.chat-text {
    font-size: 14px;
    line-height: 1.55;
}

.markdown-content > :first-child {
    margin-top: 0;
}

.markdown-content > :last-child {
    margin-bottom: 0;
}

.markdown-content p,
.markdown-content ul,
.markdown-content ol,
.markdown-content pre,
.markdown-content blockquote,
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    margin: 0 0 0.85em;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 1.4rem;
}

.markdown-content pre {
    overflow-x: auto;
    padding: 10px 12px;
    border-radius: 10px;
    background: #1b1b1b;
    border: 1px solid #363636;
}

.markdown-content code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.92em;
}

.markdown-content :not(pre) > code {
    padding: 0.15em 0.35em;
    border-radius: 6px;
    background: #1b1b1b;
    border: 1px solid #363636;
}

.markdown-content blockquote {
    margin-left: 0;
    padding-left: 12px;
    border-left: 3px solid #4b5563;
    color: #d1d5db;
}

.markdown-content a {
    color: #93c5fd;
}

.stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #9ca3af;
    margin-left: 2px;
    vertical-align: -0.12em;
    border-radius: 1px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0% { opacity: 1 }
    50% { opacity: 0 }
    100% { opacity: 1 }
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
    margin-left: 4px;
}

.typing-dots-inline {
    margin-left: 8px;
    vertical-align: middle;
}

.background-work-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #9ca3af;
    font-style: italic;
}

.chat-row.assistant .chat-bubble.background-activity {
    background: #242a33;
    border-color: #334155;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0% { opacity: 0.2; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); }
    100% { opacity: 0.2; transform: translateY(0); }
}

.tag {
    padding: 2px 6px;
    border-radius: 999px;
    border: 1px solid #404040;
    background: #2f2f2f;
    color: #d1d5db;
    font-size: 10px;
}

.chat-origin-tag {
    background: #253244;
    border-color: #31445d;
}

.agent-tag {
    background: #253244;
    border-color: #31445d;
}

.tool-tag {
    background: #3b3222;
    border-color: #51452e;
}

.mini-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 4px;
}

.mini-form-title {
    font-size: 14px;
    font-weight: 700;
    color: #f3f4f6;
}

.mini-form-description {
    font-size: 13px;
    color: #9ca3af;
    line-height: 1.45;
}

.mini-form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mini-form-label {
    font-size: 12px;
    font-weight: 600;
    color: #d1d5db;
}

.mini-form-error,
.error {
    color: #fca5a5;
    font-size: 12px;
}

.mini-form-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.required {
    color: #fca5a5;
}

.agent-composer {
    border-top: 1px solid #2f2f2f;
    padding: 14px 16px 16px;
    background: #262626;
}

.composer-textarea {
    min-height: 60px;
    max-height: 180px;
    resize: none;
    font-size: 14px;
    background: #303030;
    border-color: #454545;
}

.composer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.composer-hint {
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid #4b5563;
    border-radius: 10px;
    background: #243244;
    color: #dbeafe;
    font-size: 12px;
    line-height: 1.4;
}

.spacer {
    flex: 1;
}

.session-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.session-pane.is-collapsed,
.workflow-pane.is-collapsed {
    width: 0;
    flex-basis: 0;
    opacity: 0;
    border-width: 0;
}

.session-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #2f2f2f;
    min-width: 0;
}

.session-item.active {
    background: #2a2a2a;
}

.session-link {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    border: none;
    background: transparent;
    padding: 0;
    text-align: left;
    cursor: pointer;
    color: #e5e7eb;
    min-width: 0;
}

.session-name {
    font-size: 13px;
    overflow-wrap: anywhere;
}

.session-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.session-status-badge {
    border: 1px solid #4b5563;
    background: #273142;
    color: #bfdbfe;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.session-id,
.session-created {
    font-size: 12px;
    overflow-wrap: anywhere;
}

.session-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #d1d5db;
    appearance: none;
    -webkit-appearance: none;
}

.session-delete-btn .icon-mask {
    width: 20px;
    height: 20px;
}

.session-delete-btn:hover:not(:disabled) {
    background: #303030;
    color: #f3f4f6;
}

.session-delete-btn:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

.btn {
    padding: 5px 10px;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    background: #2b2b2b;
    color: #e5e7eb;
    font: inherit;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
}

.btn:hover:not(:disabled) {
    background: #323232;
}

.btn.primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

.btn.primary:hover:not(:disabled) {
    background: #2563eb;
}

.btn.danger {
    background: #7f1d1d;
    border-color: #7f1d1d;
    color: #fff;
}

.btn.danger:hover:not(:disabled) {
    background: #991b1b;
    border-color: #991b1b;
}

.btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.btn.next {
    margin-left: 10px;
}

@media (min-width: 961px) {
    .chat-pane-header-left {
        display: flex;
    }
}

@media (max-width: 1320px) and (min-width: 961px) {
    .agent-body {
        gap: 0;
        background: #171717;
    }

    .session-pane {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 20;
        width: min(320px, calc(100vw - 220px));
        max-width: 360px;
        box-shadow: 0 0 0 1px #2f2f2f;
    }

    .session-pane.is-collapsed {
        width: min(320px, calc(100vw - 220px));
        flex-basis: auto;
        opacity: 0;
        border-width: 0 1px 0 0;
        transform: translateX(-100%);
        pointer-events: none;
    }
}

@media (max-width: 1080px) and (min-width: 961px) {
    .workflow-pane {
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        z-index: 20;
        width: min(360px, calc(100vw - 220px));
        max-width: 400px;
        box-shadow: 0 0 0 1px #2f2f2f;
    }

    .workflow-pane.is-collapsed {
        width: min(360px, calc(100vw - 220px));
        flex-basis: auto;
        opacity: 0;
        border-width: 0 0 0 1px;
        transform: translateX(100%);
        pointer-events: none;
    }
}

@media (max-width: 960px) {
    .agent-body {
        gap: 0;
        background: #171717;
    }

    .session-pane-header {
        flex-wrap: wrap;
        align-items: center;
    }

    .session-pane-header .pane-heading {
        flex: 1 1 auto;
        min-width: 0;
    }

    .session-pane-header .pane-title-actions {
        flex: 0 0 auto;
        margin-left: auto;
    }

    .session-pane,
    .workflow-pane {
        position: absolute;
        top: 0;
        bottom: 0;
        z-index: 20;
        width: min(320px, calc(100% - 24px));
        max-width: calc(100% - 24px);
        box-shadow: 0 0 0 1px #2f2f2f;
    }

    .session-pane {
        left: 0;
    }

    .workflow-pane {
        right: 0;
    }

    .session-pane.is-collapsed {
        width: min(320px, calc(100% - 24px));
        flex-basis: auto;
        opacity: 0;
        border-width: 0 1px 0 0;
        transform: translateX(-100%);
        pointer-events: none;
    }

    .workflow-pane.is-collapsed {
        width: min(320px, calc(100% - 24px));
        flex-basis: auto;
        opacity: 0;
        border-width: 0 0 0 1px;
        transform: translateX(100%);
        pointer-events: none;
    }

    .chat-pane {
        width: 100%;
    }

    .chat-pane-header {
        justify-content: flex-start;
        gap: 12px;
    }

    .chat-pane-header > span {
        margin-left: auto;
    }
}
