@import url("https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700&family=Unbounded:wght@500;600&display=swap");

:root {
    color-scheme: dark;
    --bg: #323541;
    --bg-card: #2a2d3a;
    --bg-elevated: #3a3e4e;
    --text: #fafafa;
    --muted: #c4c4ce;
    --accent: #facc15;
    --accent-ink: #18181b;
    --line: rgba(255, 255, 255, 0.1);
    --danger: #fca5a5;
    --ok: #86efac;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    --font: "Onest", "Segoe UI", sans-serif;
    --display: "Unbounded", "Segoe UI", sans-serif;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    min-height: 100%;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background:
        radial-gradient(900px 420px at 12% -10%, rgba(250, 204, 21, 0.14), transparent 55%),
        var(--bg);
}

button, textarea, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.brand-mark {
    margin: 0;
    font-family: var(--display);
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    color: var(--accent);
}

.brand-sub {
    color: var(--muted);
    font-size: 0.92rem;
}

.btn, .icon-btn {
    border: 1px solid transparent;
    border-radius: 8px;
    min-height: 44px;
}

.btn {
    padding: 0 14px;
    background: var(--bg-elevated);
}

.btn.primary {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}

.btn.primary:hover { background: #ffe56a; }

.btn.ghost {
    background: transparent;
    border-color: var(--line);
}

.btn.ghost:hover { background: rgba(255, 255, 255, 0.04); }

.btn.danger { color: var(--danger); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    padding: 0;
    background: var(--accent);
    color: var(--accent-ink);
}

.icon-btn:hover { background: #ffe56a; }

.icon-btn:disabled, .btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.gate {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.gate-card {
    width: min(440px, 100%);
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 28px 24px 24px;
}

.gate-card h1 {
    margin: 10px 0 8px;
    font-family: var(--display);
    font-size: 1.7rem;
    line-height: 1.2;
    font-weight: 500;
}

.lede { margin: 0 0 18px; color: var(--muted); }

.gate-card label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.gate-card input {
    width: 100%;
    min-height: 48px;
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
}

.gate-card input:focus-visible { outline-offset: 0; }

.gate-card .btn { width: 100%; }

.form-error {
    margin: 10px 0 0;
    color: var(--danger);
}

code {
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.92em;
}

.app {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    min-height: 0;
    padding: 16px;
    overflow: hidden;
    background: var(--bg-card);
    border-right: 1px solid var(--line);
}

.side-head { display: grid; gap: 12px; }

.brand { display: flex; align-items: baseline; justify-content: space-between; }

.side-head .btn, .side-foot .btn { width: 100%; }

.chat-list {
    overflow-x: hidden;
    overflow-y: auto;
    display: grid;
    align-content: start;
    gap: 6px;
    min-width: 0;
    min-height: 0;
    flex: 1;
}

.chat-item {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    overflow: hidden;
    text-align: left;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
}

.chat-item:hover { background: rgba(255, 255, 255, 0.04); }

.chat-item.is-active {
    background: rgba(250, 204, 21, 0.12);
    border-color: rgba(250, 204, 21, 0.45);
}

.chat-item-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-meta {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

.empty-list { margin: 8px; color: var(--muted); }

.side-foot { display: grid; gap: 10px; }

.status-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    flex: 0 0 auto;
}

.dot.is-ok { background: var(--ok); }
.dot.is-bad { background: #f87171; }
.dot.is-wait { background: var(--accent); }

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 64px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
}

.topbar h1 {
    flex: 1;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--display);
    font-size: 1.05rem;
    font-weight: 500;
}

.menu-btn {
    display: none;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.banner {
    margin: 12px 16px 0;
    padding: 10px 12px;
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    background: rgba(250, 204, 21, 0.12);
    color: var(--text);
}

.thread {
    flex: 1;
    overflow: auto;
    padding: 20px 16px 8px;
}

.thread-inner {
    width: min(760px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 14px;
}

.msg { max-width: 100%; }

.msg-user {
    justify-self: end;
    width: min(85%, 560px);
    padding: 10px 12px;
    border-radius: 12px 12px 4px 12px;
    background: rgba(250, 204, 21, 0.16);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg-assistant {
    padding: 2px 2px 0;
    overflow-wrap: anywhere;
}

.msg-assistant.is-error {
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(248, 113, 113, 0.12);
    color: #fecaca;
}

.msg p { margin: 0 0 0.75em; }
.msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 0 0 0.75em; padding-left: 1.2em; }

.msg-meta {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.75rem;
}

.inline-code, .code-block {
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.inline-code {
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: var(--bg-elevated);
}

.code-block {
    margin: 0 0 0.75em;
    padding: 12px;
    overflow: auto;
    border-radius: 8px;
    background: #232633;
    border: 1px solid var(--line);
}

.msg a { color: #fde68a; }

.pending-note { color: var(--muted); }

.dots::after {
    content: "";
    animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
}

.empty-state {
    margin-top: 8vh;
    display: grid;
    gap: 14px;
    justify-items: start;
}

.empty-state h2 {
    margin: 0;
    font-family: var(--display);
    font-size: 1.8rem;
    font-weight: 500;
}

.suggestions { display: grid; gap: 8px; width: min(520px, 100%); }

.suggestion {
    min-height: 44px;
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
}

.suggestion:hover { border-color: rgba(250, 204, 21, 0.55); }

.composer {
    width: min(792px, calc(100% - 24px));
    margin: 0 auto 16px;
}

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg-card);
}

.composer textarea {
    flex: 1;
    min-height: 44px;
    max-height: 180px;
    resize: none;
    border: 0;
    padding: 10px 8px;
    background: transparent;
}

.composer textarea::placeholder { color: #c4c4ce; }
.composer textarea:focus { outline: none; }

.composer-box:focus-within {
    border-color: rgba(250, 204, 21, 0.7);
}

.backdrop {
    display: none;
}

@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .menu-btn { display: inline-flex; }
    .sidebar {
        position: fixed;
        z-index: 3;
        inset: 0 auto 0 0;
        width: min(320px, 88vw);
        transform: translateX(-105%);
        transition: transform 180ms ease;
    }
    .app.is-nav-open .sidebar { transform: none; }
    .app.is-nav-open .backdrop {
        display: block;
        position: fixed;
        z-index: 2;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        border: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
