:root {
    --lab-bg: #070e18;
    --lab-bg-2: #0d1826;
    --lab-rail: #0a1420;
    --lab-line: rgba(212, 175, 106, 0.16);
    --lab-gold: #d4af6a;
    --lab-gold-2: #f0d9a6;
    --lab-text: #f6f1e8;
    --lab-muted: #8f9db0;
    --lab-card: #121d2e;
    --lab-user: linear-gradient(135deg, #c9a24a 0%, #e6c98a 100%);
    --lab-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
    --lab-focus: 0 0 0 3px rgba(212, 175, 106, 0.22);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--lab-bg);
    color: var(--lab-text);
    font-family: "Instrument Sans", "Segoe UI", sans-serif;
}

.lab-app {
    display: flex;
    height: 100%;
    overflow: hidden;
    background:
        radial-gradient(1200px 500px at 80% -10%, rgba(212, 175, 106, 0.12), transparent 50%),
        radial-gradient(900px 400px at 0% 100%, rgba(54, 92, 140, 0.18), transparent 55%),
        var(--lab-bg);
}

.lab-rail {
    width: 292px;
    height: 100%;
    flex-shrink: 0;
    min-height: 0;
    overflow: hidden;
    background: linear-gradient(180deg, #0c1724 0%, #08111b 100%);
    border-right: 1px solid var(--lab-line);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
}

.lab-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 22px;
}

.lab-brand-logo {
    display: block;
    height: 36px;
    width: auto;
    max-width: 100%;
    padding: 8px 10px;
    background: #fff;
    border-radius: 10px;
}

.lab-brand span {
    color: var(--lab-muted);
    font-size: 12px;
    padding-left: 2px;
}

.lab-new {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    border: 1px solid rgba(212, 175, 106, 0.38);
    background: rgba(212, 175, 106, 0.1);
    color: var(--lab-gold-2);
    border-radius: 12px;
    padding: 11px 12px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 22px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.lab-new:hover {
    background: rgba(212, 175, 106, 0.18);
    border-color: var(--lab-gold);
}

.lab-rail-label {
    color: var(--lab-muted);
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-bottom: 8px;
    padding: 0 6px;
}

.lab-sessions {
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
}

.lab-session {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--lab-text);
    padding: 10px 10px;
    border-radius: 10px;
    cursor: pointer;
    font: inherit;
    transition: background 0.15s ease;
}

.lab-session span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.lab-session.active,
.lab-session:hover {
    background: rgba(255, 255, 255, 0.05);
}

.lab-session .lab-del {
    opacity: 0;
    border: 0;
    background: transparent;
    color: var(--lab-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
}

.lab-session:hover .lab-del,
.lab-session.active .lab-del {
    opacity: 1;
}

.lab-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.lab-top {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--lab-line);
    flex-shrink: 0;
}

.lab-menu {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--lab-line);
    background: transparent;
    border-radius: 10px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.lab-menu span {
    display: block;
    width: 16px;
    height: 1.5px;
    background: var(--lab-gold-2);
}

.lab-top-title {
    flex: 1;
}

.lab-top-title h1 {
    margin: 0;
    font-family: Newsreader, Georgia, serif;
    font-size: 26px;
    font-weight: 500;
}

.lab-top-title p {
    margin: 2px 0 0;
    color: var(--lab-muted);
    font-size: 12px;
}

.lab-back {
    color: var(--lab-gold-2);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--lab-line);
    padding: 8px 14px;
    border-radius: 999px;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.lab-back:hover {
    border-color: var(--lab-gold);
    background: rgba(212, 175, 106, 0.08);
}

.lab-thread {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 28px 8vw 16px;
}

.lab-empty {
    max-width: 720px;
    margin: 8vh auto 0;
}

.lab-empty h2 {
    font-family: Newsreader, Georgia, serif;
    font-weight: 500;
    font-size: 34px;
    margin: 0 0 10px;
    letter-spacing: -0.02em;
}

.lab-empty p {
    color: var(--lab-muted);
    margin: 0 0 28px;
    line-height: 1.6;
}

.lab-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.lab-chip {
    text-align: left;
    background: rgba(18, 29, 46, 0.9);
    border: 1px solid var(--lab-line);
    color: var(--lab-text);
    border-radius: 14px;
    padding: 14px 16px;
    cursor: pointer;
    font: inherit;
    font-size: 13.5px;
    line-height: 1.45;
    box-shadow: var(--lab-shadow);
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.lab-chip:hover {
    border-color: var(--lab-gold);
    transform: translateY(-1px);
}

.lab-msg {
    display: flex;
    gap: 12px;
    max-width: 820px;
    margin: 0 auto 22px;
    animation: labIn 0.28s ease;
}

.lab-msg.user {
    flex-direction: row-reverse;
}

@keyframes labIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.lab-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}

.lab-msg.assistant .lab-avatar {
    background: var(--lab-user);
    color: #1a1408;
}

.lab-msg.user .lab-avatar {
    background: #24344a;
    color: var(--lab-gold-2);
}

.lab-bubble {
    flex: 1;
    min-width: 0;
    background: var(--lab-card);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 18px 18px 18px 6px;
    padding: 16px 18px;
    line-height: 1.65;
    font-size: 15px;
    white-space: normal;
    word-break: break-word;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.lab-msg.user .lab-bubble {
    flex: 0 1 auto;
    max-width: 78%;
    background: rgba(212, 175, 106, 0.14);
    border-color: rgba(212, 175, 106, 0.28);
    border-radius: 18px 18px 6px 18px;
    white-space: pre-wrap;
}

.lab-bubble h3 {
    margin: 0 0 8px;
    font-family: Newsreader, Georgia, serif;
    font-size: 18px;
    font-weight: 500;
    color: var(--lab-gold-2);
}

.lab-bubble a.lab-link,
.lab-bubble a {
    color: var(--lab-gold-2);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.lab-bubble a.lab-link:hover,
.lab-bubble a:hover {
    color: var(--lab-gold);
}

.lab-bubble p {
    margin: 0 0 10px;
}

.lab-bubble p:last-child {
    margin-bottom: 0;
}

.lab-table-wrap {
    margin: 12px -6px 4px;
    overflow-x: auto;
    border: 1px solid rgba(212, 175, 106, 0.18);
    border-radius: 12px;
    background: rgba(7, 14, 24, 0.45);
}

.lab-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    line-height: 1.4;
}

.lab-table th,
.lab-table td {
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    white-space: normal;
}

.lab-table th {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--lab-muted);
    background: rgba(212, 175, 106, 0.08);
}

.lab-table tr:last-child td {
    border-bottom: 0;
}

.lab-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.lab-table-action {
    white-space: nowrap;
}

.lab-table-action a,
.lab-table a.lab-link {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(212, 175, 106, 0.35);
    background: rgba(212, 175, 106, 0.12);
    color: var(--lab-gold-2);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.lab-table-action a:hover,
.lab-table a.lab-link:hover {
    background: rgba(212, 175, 106, 0.22);
    color: var(--lab-gold);
}

.lab-list {
    margin: 8px 0 4px;
    padding: 0 0 0 4px;
    list-style: none;
}

.lab-list li {
    position: relative;
    margin: 0 0 8px;
    padding: 8px 12px 8px 28px;
    border-radius: 10px;
    background: rgba(7, 14, 24, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.lab-list li:last-child {
    margin-bottom: 0;
}

.lab-list li::before {
    position: absolute;
    left: 12px;
    top: 14px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--lab-gold);
    content: '';
}

ol.lab-list {
    counter-reset: lab-item;
}

ol.lab-list li {
    padding-left: 36px;
}

ol.lab-list li::before {
    display: none;
}

ol.lab-list li::after {
    position: absolute;
    left: 12px;
    top: 8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(212, 175, 106, 0.16);
    color: var(--lab-gold-2);
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    counter-increment: lab-item;
    content: counter(lab-item);
}

.lab-bubble code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.28);
    padding: 1px 5px;
    border-radius: 5px;
}

.lab-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 4px;
    border-radius: 50%;
    background: var(--lab-gold);
    animation: labDot 1s infinite ease-in-out;
}

.lab-typing span:nth-child(2) { animation-delay: 0.15s; }
.lab-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes labDot {
    0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.lab-composer {
    padding: 8px 8vw 20px;
    flex-shrink: 0;
}

.lab-sessions,
.lab-thread {
    scrollbar-width: thin;
    scrollbar-color: rgba(212, 175, 106, 0.45) transparent;
}

.lab-sessions::-webkit-scrollbar,
.lab-thread::-webkit-scrollbar {
    width: 8px;
}

.lab-sessions::-webkit-scrollbar-thumb,
.lab-thread::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 106, 0.4);
    border-radius: 999px;
}

.lab-sessions::-webkit-scrollbar-track,
.lab-thread::-webkit-scrollbar-track {
    background: transparent;
}

.lab-composer form {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #101c2c;
    border: 1px solid var(--lab-line);
    border-radius: 18px;
    padding: 10px 10px 10px 16px;
    box-shadow: var(--lab-shadow);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.lab-composer form:focus-within {
    border-color: rgba(212, 175, 106, 0.45);
    box-shadow: var(--lab-shadow), var(--lab-focus);
}

.lab-composer textarea {
    flex: 1;
    resize: none;
    max-height: 160px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--lab-text);
    font: inherit;
    line-height: 1.5;
    padding: 8px 0;
}

.lab-composer button {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: var(--lab-user);
    color: #1a1408;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.lab-composer button:hover:not(:disabled) {
    filter: brightness(1.06);
}

.lab-composer button:disabled {
    opacity: 0.45;
    cursor: default;
}

.lab-hint {
    max-width: 820px;
    margin: 8px auto 0;
    color: var(--lab-muted);
    font-size: 11px;
    text-align: center;
}

.lab-error {
    color: #ffb4b4;
    font-size: 13px;
}

@media (max-width: 860px) {
    .lab-rail {
        position: fixed;
        inset: 0 auto 0 0;
        height: 100%;
        z-index: 20;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
    }
    .lab-app.rail-open .lab-rail {
        transform: none;
    }
    .lab-menu {
        display: flex;
    }
    .lab-thread,
    .lab-composer {
        padding-left: 16px;
        padding-right: 16px;
    }
    .lab-chips {
        grid-template-columns: 1fr;
    }
    .lab-empty h2 {
        font-size: 28px;
    }
}

html:has(body.lab-login-body) {
    overflow: auto;
    height: auto;
    min-height: 100%;
}

.lab-login-body {
    min-height: 100%;
    height: auto;
    overflow: auto;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(720px 380px at 18% -8%, rgba(212, 175, 106, 0.18), transparent 58%),
        radial-gradient(640px 360px at 92% 108%, rgba(54, 92, 140, 0.28), transparent 52%),
        radial-gradient(420px 260px at 80% 12%, rgba(212, 175, 106, 0.06), transparent 60%),
        var(--lab-bg);
}

.lab-login {
    width: 100%;
    max-width: 440px !important;
    margin: 0 auto !important;
    padding: 48px 20px 36px;
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    gap: 0 !important;
    align-items: stretch;
}

.lab-login-logo {
    display: block;
    height: 40px;
    width: auto;
    max-width: 180px;
    padding: 8px 10px;
    background: #fff;
    border-radius: 10px;
    margin: 0 0 22px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.lab-login-card {
    width: 100%;
    background: linear-gradient(180deg, rgba(22, 35, 54, 0.92) 0%, rgba(14, 24, 38, 0.94) 100%);
    border: 1px solid rgba(212, 175, 106, 0.2);
    border-radius: 24px;
    padding: 32px 32px 28px;
    box-shadow: var(--lab-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(16px);
}

.lab-login-kicker {
    margin: 0 0 10px;
    color: var(--lab-gold);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.lab-login-card h1 {
    margin: 0;
    font-family: Newsreader, Georgia, serif;
    font-size: 32px;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.lab-login-sub {
    color: var(--lab-muted);
    margin: 8px 0 26px;
    font-size: 15px;
}

.lab-field {
    margin-bottom: 16px;
}

.lab-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--lab-muted);
    margin-bottom: 8px;
}

.lab-control {
    position: relative;
    display: flex;
    align-items: center;
}

.lab-control-icon {
    position: absolute;
    left: 14px;
    color: var(--lab-gold);
    pointer-events: none;
    opacity: 0.85;
}

.lab-control input {
    width: 100%;
    margin: 0;
    background: rgba(7, 14, 24, 0.72);
    border: 1px solid rgba(212, 175, 106, 0.18);
    border-radius: 14px;
    color: var(--lab-text);
    font: inherit;
    font-size: 15px;
    padding: 14px 72px 14px 44px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.lab-control input::placeholder {
    color: #6d7b8e;
}

.lab-control input:hover {
    border-color: rgba(212, 175, 106, 0.32);
}

.lab-control input:focus {
    border-color: var(--lab-gold);
    box-shadow: var(--lab-focus);
    background: rgba(7, 14, 24, 0.9);
}

.lab-login-card .lab-pwd-toggle,
.lab-pwd-toggle {
    position: absolute !important;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: auto !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 8px;
    padding: 6px 8px !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--lab-gold-2) !important;
    font: inherit !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    line-height: 1;
    filter: none !important;
}

.lab-pwd-toggle:hover {
    background: rgba(212, 175, 106, 0.1) !important;
}

.lab-login-card .lab-login-submit,
.lab-login-submit {
    width: 100%;
    margin-top: 10px;
    border: 0;
    border-radius: 14px;
    padding: 14px 16px;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    background: var(--lab-user);
    color: #1a1408;
    box-shadow: 0 10px 24px rgba(201, 162, 74, 0.22);
    transition: filter 0.15s ease, transform 0.15s ease;
}

.lab-login-submit:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.lab-login-submit:active {
    transform: none;
}

.lab-login-error {
    background: rgba(255, 90, 90, 0.1);
    border: 1px solid rgba(255, 150, 150, 0.28);
    color: #ffb4b4;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

@media (max-width: 800px) {
    .lab-login {
        grid-template-columns: none !important;
        padding: 32px 16px 28px;
    }

    .lab-login-card {
        padding: 26px 22px 22px;
        border-radius: 20px;
    }

    .lab-login-card h1 {
        font-size: 28px;
    }
}
