:root {
    --black: #000000;
    --panel: #05070b;
    --panel-strong: #090d16;
    --panel-soft: #0d1320;
    --navy: #001f54;
    --navy-light: #0b3d91;
    --apple-red: #ff0800;
    --apple-red-soft: rgba(255, 8, 0, 0.2);
    --line: rgba(255, 255, 255, 0.1);
    --line-strong: rgba(255, 255, 255, 0.16);
    --white: #ffffff;
    --muted: #cbd3e3;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--black);
}

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 78% 0%, rgba(255, 8, 0, 0.06), transparent 24rem),
        linear-gradient(135deg, rgba(0, 31, 84, 0.24), transparent 38%),
        var(--black);
    color: var(--white);
    font-family: "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

button,
textarea {
    font: inherit;
}

button {
    color: var(--white);
}

.app-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
    gap: 0;
    padding: 0;
    transition: grid-template-columns 180ms ease;
}

.app-shell.sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
}

.section-border {
    border: 1px solid var(--line);
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.42);
}

.sidebar {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 100vh;
    padding: 12px;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: rgba(3, 6, 13, 0.96);
    box-shadow: none;
    overflow: hidden;
}

.app-shell.sidebar-collapsed .sidebar {
    display: none;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    min-height: 58px;
    padding: 4px 6px 14px;
}

.sidebar-brand img {
    display: block;
    width: min(190px, 100%);
    height: auto;
    object-fit: contain;
}

.sidebar-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding-bottom: 12px;
}

.new-chat-button,
.icon-button,
.recent-chat-button,
.send-button {
    border: 1px solid var(--line);
    background: var(--panel-strong);
    color: var(--white);
    cursor: pointer;
    transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.new-chat-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 12px;
    border-radius: 7px;
    background: rgba(0, 31, 84, 0.58);
    font-weight: 700;
    text-align: left;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 7px;
}

.new-chat-button:hover,
.icon-button:hover,
.recent-chat-button:hover,
.send-button:hover {
    background: rgba(11, 61, 145, 0.68);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
    transform: translateY(-1px);
}

.recents-section {
    min-height: 0;
    padding: 12px 2px 0;
    border-top: 1px solid var(--line);
    background: transparent;
    overflow: auto;
}

.recents-section h2 {
    margin: 2px 4px 10px;
    color: var(--white);
    font-size: 0.82rem;
    font-weight: 750;
}

.recent-list {
    display: grid;
    gap: 6px;
}

.recent-chat-row {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    border: 1px solid transparent;
    border-radius: 7px;
}

.recent-chat-row.active,
.recent-chat-row:hover,
.recent-chat-row.menu-open {
    border-color: rgba(255, 8, 0, 0.24);
    background: rgba(0, 31, 84, 0.42);
}

.recent-chat-row.active {
    box-shadow: inset 3px 0 0 var(--apple-red);
}

.recent-chat-button {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 9px 4px 9px 10px;
    border-color: transparent;
    border-radius: 7px;
    background: transparent;
    text-align: left;
}

.recent-chat-button:hover {
    background: transparent;
    box-shadow: none;
    transform: none;
}

.recent-chat-title {
    display: block;
    overflow: hidden;
    color: var(--white);
    font-size: 0.9rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-chat-meta,
.empty-recents {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.72rem;
}

.recent-chat-menu {
    position: relative;
    display: grid;
    place-items: center;
    padding-right: 4px;
}

.recent-menu-button {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
    transition: background 160ms ease, color 160ms ease, opacity 160ms ease;
}

.recent-chat-row:hover .recent-menu-button,
.recent-chat-row.active .recent-menu-button,
.recent-chat-row.menu-open .recent-menu-button {
    opacity: 1;
}

.recent-menu-button:hover,
.recent-chat-row.menu-open .recent-menu-button {
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
}

.delete-chat-button {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 10;
    display: none;
    min-width: 98px;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #111827;
    color: var(--white);
    cursor: pointer;
    text-align: left;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.42);
}

.recent-chat-row.menu-open .delete-chat-button {
    display: block;
}

.delete-chat-button:hover {
    border-color: rgba(255, 8, 0, 0.38);
    background: rgba(255, 8, 0, 0.18);
}

.empty-recents {
    padding: 8px 4px;
    line-height: 1.35;
}

.sidebar-reveal {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 20;
    display: none;
}

.app-shell.sidebar-collapsed .sidebar-reveal {
    display: grid;
}

.workspace {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    background: rgba(2, 4, 9, 0.9);
    box-shadow: none;
    overflow: hidden;
}

.topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    min-height: 58px;
    padding: 8px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(5, 10, 20, 0.72);
    box-shadow: none;
}

.model-title {
    justify-self: center;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(0, 31, 84, 0.5);
    color: var(--white);
    font-weight: 750;
}

.mobile-menu {
    visibility: hidden;
}

.chat-stage {
    position: relative;
    display: grid;
    min-height: 0;
    padding: 24px;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    pointer-events: none;
}

.empty-state.is-hidden {
    display: none;
}

.empty-state h2 {
    color: var(--white);
    font-size: clamp(1.45rem, 2vw, 2.1rem);
    font-weight: 650;
    text-align: center;
}

.chat-history {
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
}

.chat-history:empty {
    border-color: transparent;
    background: transparent;
}

.message {
    width: fit-content;
    max-width: min(760px, 82%);
    padding: 13px 15px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--white);
    animation: fadeIn 220ms ease;
    overflow-wrap: anywhere;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message p {
    color: var(--white);
    line-height: 1.48;
    white-space: pre-wrap;
}

.user-message {
    margin-left: auto;
    border-color: rgba(255, 8, 0, 0.22);
    background: linear-gradient(135deg, rgba(11, 61, 145, 0.9), rgba(0, 31, 84, 0.94));
}

.ai-message {
    margin-right: auto;
    background: rgba(13, 19, 32, 0.86);
}

.message-time {
    margin-top: 7px;
    color: var(--muted);
    font-size: 0.7rem;
    text-align: right;
}

.composer-section {
    width: min(820px, calc(100% - 48px));
    margin: 0 auto 26px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: transparent;
    box-shadow: none;
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    min-height: 58px;
    padding: 10px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: rgba(9, 13, 22, 0.98);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
}

#userInput {
    width: 100%;
    min-height: 40px;
    max-height: 150px;
    padding: 10px 4px;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--white);
    font-size: 1rem;
    line-height: 1.35;
}

#userInput::placeholder {
    color: var(--muted);
}

.composer:focus-within {
    border-color: rgba(255, 8, 0, 0.44);
    box-shadow: 0 0 0 1px var(--apple-red-soft), 0 18px 42px rgba(0, 0, 0, 0.42);
}

.send-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border-color: transparent;
    background: var(--apple-red);
}

.typing-indicator {
    display: none;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding-bottom: 10px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--apple-red);
    animation: typing 1s infinite;
}

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

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

@keyframes typing {
    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.55;
    }

    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
        padding: 0;
    }

    .sidebar {
        position: fixed;
        inset: 10px auto 10px 10px;
        z-index: 30;
        width: min(300px, calc(100vw - 20px));
        min-height: auto;
        border: 1px solid var(--line-strong);
        border-radius: 10px;
        box-shadow: 0 20px 55px rgba(0, 0, 0, 0.55);
    }

    .app-shell.sidebar-collapsed .sidebar {
        display: none;
    }

    .app-shell:not(.sidebar-collapsed) .workspace {
        pointer-events: none;
        filter: brightness(0.68);
    }

    .sidebar-reveal {
        display: grid;
    }

    .app-shell:not(.sidebar-collapsed) .sidebar-reveal {
        display: none;
    }

    .workspace {
        min-height: 100vh;
        border-radius: 0;
    }
}

@media (max-width: 640px) {
    .chat-stage {
        padding: 14px;
    }

    .composer-section {
        width: calc(100% - 20px);
        margin-bottom: 10px;
        padding: 8px;
    }

    .message {
        max-width: 94%;
    }
}
