:root {
    color-scheme: dark;
    --bg: #090a10;
    --panel: #10121a;
    --panel-2: #151824;
    --panel-3: #1b1f2d;
    --line: rgba(255, 255, 255, 0.075);
    --line-strong: rgba(168, 85, 247, 0.34);
    --text: #f5f3ff;
    --soft: #d8d4e5;
    --muted: #918ba2;
    --primary: #9333ea;
    --primary-2: #7c3aed;
    --primary-soft: #c4b5fd;
    --success: #22c55e;
    --danger: #fb7185;
    --sidebar: 292px;
    --topbar: 68px;
    --content: 960px;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
    margin: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at 72% -20%, rgba(124, 58, 237, 0.13), transparent 38%),
        var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; }
button { border: 0; color: inherit; }
svg { width: 18px; height: 18px; display: block; fill: currentColor; }

.shell {
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar);
    flex: 0 0 var(--topbar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(9, 10, 16, 0.94);
    position: relative;
    z-index: 50;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { width: 38px; height: 38px; object-fit: contain; }
.brand strong {
    display: block;
    font-family: "Hanken Grotesk", Inter, sans-serif;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.brand span {
    display: block;
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}
.top-actions { display: flex; align-items: center; gap: 13px; }
.host { color: var(--muted); font-size: 11px; }
.system-chip,
.chat-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(168, 85, 247, 0.27);
    border-radius: 999px;
    background: rgba(147, 51, 234, 0.08);
    color: #ddd6fe;
    padding: 8px 11px;
    font: 700 9px/1 "JetBrains Mono", monospace;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}
.pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
}
.mobile-history-toggle {
    display: none;
    min-height: 38px;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--panel-2);
    padding: 0 11px;
    cursor: pointer;
}

.blocked-card {
    width: min(520px, calc(100vw - 28px));
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--panel);
    padding: 34px;
    text-align: center;
    box-shadow: var(--shadow);
}
.blocked-icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    margin: 0 auto 17px;
    border: 1px solid var(--line-strong);
    border-radius: 17px;
    background: rgba(147, 51, 234, 0.12);
    color: var(--primary-soft);
    font-weight: 900;
}
.blocked-card h1 {
    margin: 0;
    font: 800 clamp(27px, 5vw, 38px)/1.08 "Hanken Grotesk", Inter, sans-serif;
    letter-spacing: -0.04em;
}
.blocked-card p { margin: 12px 0 22px; color: var(--muted); line-height: 1.65; }
.blocked-card a,
.primary {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    padding: 0 16px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: background .18s ease, transform .18s ease;
}
.blocked-card a:hover,
.primary:hover { background: #a344ee; transform: translateY(-1px); }

.app {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    overflow: hidden;
}
.history {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 13px;
    border-right: 1px solid var(--line);
    background: #0d0f16;
    padding: 20px 16px 16px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(168, 85, 247, .24) transparent;
}
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.history-title span,
.quota-kicker,
.history-section-label {
    display: block;
    color: var(--muted);
    font: 700 9px/1.2 "JetBrains Mono", monospace;
    letter-spacing: .14em;
    text-transform: uppercase;
}
.history-title strong {
    display: block;
    margin-top: 6px;
    font: 800 23px/1.1 "Hanken Grotesk", Inter, sans-serif;
    letter-spacing: -.035em;
}
.history-close {
    width: 36px;
    height: 36px;
    display: none;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel-2);
    cursor: pointer;
}
.history .primary { width: 100%; }
.quota {
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--panel);
    padding: 13px;
}
.quota strong {
    display: block;
    margin-top: 5px;
    color: var(--text);
    font-size: 14px;
}
.quota small {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 10px;
}
.quota-track {
    height: 5px;
    margin-top: 11px;
    overflow: hidden;
    border-radius: 99px;
    background: rgba(255, 255, 255, .07);
}
.quota-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}
.history-section-label { margin: 4px 2px -2px; }
.conversation-list {
    display: grid;
    gap: 7px;
    padding-bottom: 12px;
}
.conversation-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 5px;
}
.conversation {
    min-width: 0;
    min-height: 58px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    padding: 10px 11px;
    text-align: left;
    cursor: pointer;
    transition: background .18s ease, border-color .18s ease;
}
.conversation:hover,
.conversation.active {
    border-color: var(--line);
    background: var(--panel-2);
}
.conversation.active { border-color: var(--line-strong); }
.conversation strong,
.conversation span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conversation strong { color: var(--soft); font-size: 12px; line-height: 1.3; }
.conversation span { margin-top: 5px; color: var(--muted); font-size: 9px; }
.conversation-delete {
    width: 34px;
    height: 34px;
    align-self: center;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: transparent;
    color: #6f687d;
    cursor: pointer;
    opacity: 0;
    transition: opacity .18s ease, background .18s ease, color .18s ease;
}
.conversation-wrap:hover .conversation-delete,
.conversation-delete:focus-visible { opacity: 1; }
.conversation-delete:hover { background: rgba(251, 113, 133, .1); color: var(--danger); }
.conversation-delete svg { width: 16px; height: 16px; }
.soft-note {
    border: 1px dashed var(--line);
    border-radius: 13px;
    color: var(--muted);
    padding: 13px;
    font-size: 11px;
    line-height: 1.55;
}
.profile-card {
    margin-top: auto;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 18px;
    align-items: center;
    gap: 9px;
    border-top: 1px solid var(--line);
    padding: 15px 2px 0;
    color: inherit;
    text-decoration: none;
}
.profile-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: rgba(147, 51, 234, .14);
    color: var(--primary-soft);
}
.profile-avatar svg { width: 17px; height: 17px; }
.profile-card strong,
.profile-card span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-card strong { font-size: 12px; }
.profile-card span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.profile-arrow { color: #6f687d; }
.history-overlay { display: none; }

.chat-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(rgba(255, 255, 255, .018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px),
        #0a0b11;
    background-size: 52px 52px;
}
.chat-header {
    min-height: 93px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(10, 11, 17, .91);
    padding: 17px clamp(20px, 4vw, 46px);
}
.chat-header p {
    margin: 0;
    color: var(--muted);
    font: 700 9px/1.2 "JetBrains Mono", monospace;
    letter-spacing: .13em;
    text-transform: uppercase;
}
.chat-header h1 {
    max-width: min(64vw, 720px);
    margin: 6px 0 0;
    overflow: hidden;
    color: var(--text);
    font: 800 clamp(23px, 3vw, 32px)/1.05 "Hanken Grotesk", Inter, sans-serif;
    letter-spacing: -.04em;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-greeting { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }

.messages {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    padding: 26px max(20px, calc((100% - var(--content)) / 2)) 18px;
    scrollbar-width: thin;
    scrollbar-color: rgba(168, 85, 247, .22) transparent;
    scroll-behavior: smooth;
}
.messages::-webkit-scrollbar,
.history::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-thumb,
.history::-webkit-scrollbar-thumb { border-radius: 99px; background: rgba(168, 85, 247, .22); }

.empty {
    width: min(760px, 100%);
    margin: auto;
    text-align: center;
}
.empty-mark {
    width: 76px;
    height: 76px;
    display: grid;
    place-items: center;
    margin: 0 auto 18px;
    border: 1px solid var(--line-strong);
    border-radius: 24px;
    background: rgba(147, 51, 234, .1);
}
.empty-mark img { width: 45px; height: 45px; object-fit: contain; }
.empty h2 {
    margin: 0;
    font: 800 clamp(30px, 5vw, 46px)/1.08 "Hanken Grotesk", Inter, sans-serif;
    letter-spacing: -.05em;
}
.empty > p {
    max-width: 610px;
    margin: 12px auto 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.7;
}
.prompt-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 25px;
}
.prompt-grid button {
    min-height: 76px;
    display: grid;
    align-content: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--panel);
    color: var(--soft);
    padding: 13px;
    text-align: left;
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.prompt-grid button:hover {
    border-color: var(--line-strong);
    background: var(--panel-2);
    transform: translateY(-2px);
}
.prompt-grid button strong { font-size: 12px; }
.prompt-grid button span { color: var(--muted); font-size: 10px; line-height: 1.4; }

.message-row {
    width: 100%;
    max-width: 900px;
    display: flex;
    align-items: flex-start;
    gap: 11px;
    animation: message-in .2s ease-out;
}
@keyframes message-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.message-row.from-user {
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 760px;
}
.avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--panel-2);
    color: var(--soft);
}
.avatar img { width: 24px; height: 24px; object-fit: contain; }
.avatar svg { width: 17px; height: 17px; }
.from-user .avatar { border-color: var(--line-strong); background: rgba(147, 51, 234, .16); color: var(--primary-soft); }
.bubble {
    min-width: 0;
    max-width: calc(100% - 47px);
    border: 1px solid var(--line);
    border-radius: 16px;
    border-top-left-radius: 5px;
    background: rgba(16, 18, 26, .96);
    padding: 13px 15px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .14);
}
.from-user .bubble {
    border-color: rgba(168, 85, 247, .25);
    border-radius: 16px;
    border-top-right-radius: 5px;
    background: #221535;
}
.bubble-head { margin-bottom: 7px; }
.bubble-head strong {
    color: var(--muted);
    font: 700 9px/1.2 "JetBrains Mono", monospace;
    letter-spacing: .12em;
    text-transform: uppercase;
}
.bubble-body {
    color: #e8e5ee;
    font-size: 14px;
    line-height: 1.72;
    overflow-wrap: anywhere;
}
.bubble-body p { margin: 0 0 11px; }
.bubble-body p:last-child,
.bubble-body ul:last-child,
.bubble-body ol:last-child,
.bubble-body blockquote:last-child { margin-bottom: 0; }
.bubble-body h3 {
    margin: 17px 0 8px;
    color: #fff;
    font: 800 17px/1.3 "Hanken Grotesk", Inter, sans-serif;
}
.bubble-body ul,
.bubble-body ol { margin: 8px 0 13px; padding-left: 21px; }
.bubble-body li { margin: 5px 0; padding-left: 2px; }
.bubble-body code {
    border: 1px solid rgba(196, 181, 253, .16);
    border-radius: 6px;
    background: #0a0b11;
    color: #e9d5ff;
    padding: 2px 5px;
    font: 500 .9em/1.4 "JetBrains Mono", monospace;
}
.bubble-body pre {
    margin: 12px 0;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #08090e;
    padding: 13px;
}
.bubble-body pre code {
    display: block;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0;
    color: #ece9f3;
    white-space: pre;
}
.bubble-body blockquote {
    margin: 10px 0;
    border-left: 3px solid var(--primary);
    color: var(--muted);
    padding-left: 12px;
}
.message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    border-top: 1px solid var(--line);
    padding-top: 9px;
}
.message-actions button {
    min-height: 29px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    padding: 0 8px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
}
.message-actions button:hover { border-color: var(--line); background: var(--panel-2); color: var(--text); }
.message-actions svg { width: 14px; height: 14px; }
.message-image {
    display: block;
    max-width: min(380px, 100%);
    max-height: 300px;
    margin: 4px 0 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #08090e;
    object-fit: contain;
}
.typing { display: inline-flex; align-items: center; gap: 5px; padding: 6px 0; }
.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-soft);
    animation: typing 1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .14s; }
.typing span:nth-child(3) { animation-delay: .28s; }
@keyframes typing {
    0%, 80%, 100% { opacity: .28; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.composer-dock {
    flex: 0 0 auto;
    padding: 0 max(18px, calc((100% - var(--content)) / 2)) max(10px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(10, 11, 17, 0), #0a0b11 26%);
}
.composer {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 17px;
    background: #151722;
    padding: 7px;
    box-shadow: 0 16px 50px rgba(0, 0, 0, .3);
}
.composer:focus-within {
    border-color: rgba(168, 85, 247, .5);
    box-shadow: 0 0 0 3px rgba(147, 51, 234, .08), 0 16px 50px rgba(0, 0, 0, .3);
}
.composer textarea {
    min-width: 0;
    min-height: 44px;
    max-height: 150px;
    flex: 1;
    resize: none;
    overflow-y: auto;
    border: 0;
    outline: 0;
    border-radius: 11px;
    background: transparent;
    color: var(--text);
    padding: 11px 8px;
    line-height: 1.5;
    scrollbar-width: thin;
    scrollbar-color: rgba(168, 85, 247, .2) transparent;
}
.composer textarea::placeholder { color: #746e80; }
.composer > button {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    cursor: pointer;
    transition: background .18s ease, transform .18s ease, opacity .18s ease;
}
.composer .attach-button {
    border: 1px solid var(--line);
    background: var(--panel-3);
    color: var(--primary-soft);
}
.composer .send-button { background: var(--primary); color: #fff; }
.composer > button:hover { transform: translateY(-1px); }
.composer .send-button:hover { background: #a344ee; }
.composer > button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.composer > button svg { width: 20px; height: 20px; }
.image-preview {
    position: absolute;
    left: 0;
    bottom: calc(100% + 9px);
    width: min(390px, 100%);
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 30px;
    align-items: center;
    gap: 9px;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    background: #171923;
    padding: 8px;
    box-shadow: var(--shadow);
}
.image-preview[hidden] { display: none; }
.image-preview img { width: 42px; height: 42px; border-radius: 9px; object-fit: cover; }
.image-preview span { overflow: hidden; color: var(--soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.image-preview button {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--panel-3);
    color: var(--muted);
    cursor: pointer;
}
.image-preview button svg { width: 14px; height: 14px; }
.ai-note {
    margin: 8px 0 0;
    color: #777180;
    text-align: center;
    font: 600 8px/1.5 "JetBrains Mono", monospace;
    letter-spacing: .08em;
    text-transform: uppercase;
}

@media (max-width: 900px) {
    .host { display: none; }
    .mobile-history-toggle { display: inline-flex; }
    .app { grid-template-columns: minmax(0, 1fr); }
    .history {
        width: min(330px, 88vw);
        position: fixed;
        z-index: 80;
        top: var(--topbar);
        bottom: 0;
        left: 0;
        transform: translateX(-102%);
        transition: transform .22s ease;
        box-shadow: 30px 0 80px rgba(0, 0, 0, .45);
    }
    .history.open { transform: translateX(0); }
    .history-close { display: grid; }
    .history-overlay {
        display: block;
        position: fixed;
        z-index: 70;
        inset: var(--topbar) 0 0;
        background: rgba(0, 0, 0, .62);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    .history-overlay.open { opacity: 1; pointer-events: auto; }
    .conversation-delete { opacity: 1; }
    .chat-header { min-height: 82px; padding: 14px 18px; }
    .chat-header h1 { max-width: 64vw; font-size: 25px; }
    .chat-greeting { display: none; }
    .messages { padding-inline: 16px; }
    .composer-dock { padding-inline: 14px; }
}

@media (max-width: 600px) {
    :root { --topbar: 62px; }
    .topbar { padding: 0 12px; }
    .brand img { width: 34px; height: 34px; }
    .brand strong { font-size: 16px; }
    .brand span { max-width: 148px; overflow: hidden; font-size: 9px; text-overflow: ellipsis; }
    .system-chip { display: none; }
    .mobile-history-toggle { width: 39px; height: 39px; justify-content: center; padding: 0; }
    .mobile-history-toggle span { display: none; }
    .chat-header { min-height: 72px; padding: 12px 14px; }
    .chat-header h1 { max-width: 58vw; margin-top: 4px; font-size: 21px; }
    .chat-header p { font-size: 8px; }
    .chat-status { padding: 7px 8px; font-size: 7px; }
    .messages { gap: 14px; padding: 18px 10px 12px; }
    .empty { margin: auto; }
    .empty-mark { width: 56px; height: 56px; margin-bottom: 13px; border-radius: 18px; }
    .empty-mark img { width: 34px; height: 34px; }
    .empty h2 { font-size: 29px; }
    .empty > p { margin-top: 9px; font-size: 12px; line-height: 1.6; }
    .prompt-grid { grid-template-columns: 1fr; gap: 7px; margin-top: 17px; }
    .prompt-grid button { min-height: 52px; padding: 10px 12px; }
    .prompt-grid button span { display: none; }
    .message-row { gap: 7px; }
    .avatar { width: 31px; height: 31px; flex-basis: 31px; border-radius: 9px; }
    .avatar img { width: 20px; height: 20px; }
    .avatar svg { width: 15px; height: 15px; }
    .bubble {
        max-width: calc(100% - 38px);
        border-radius: 13px;
        padding: 11px 12px;
    }
    .bubble-body { font-size: 13px; line-height: 1.65; }
    .bubble-body h3 { font-size: 16px; }
    .composer-dock { padding-inline: 8px; }
    .composer { gap: 5px; border-radius: 15px; padding: 6px; }
    .composer textarea { min-height: 40px; padding: 9px 6px; font-size: 13px; }
    .composer > button { width: 40px; height: 40px; flex-basis: 40px; border-radius: 11px; }
    .ai-note { margin-top: 6px; font-size: 7px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
