:root {
    color-scheme: light;
    --bg: #f6f3ed;
    --panel: #ffffff;
    --ink: #1f2933;
    --muted: #6b7280;
    --line: #ded8ce;
    --primary: #1864ab;
    --primary-dark: #0b4f8a;
    --accent: #2f9e44;
    --danger: #c92a2a;
    --shadow: 0 18px 45px rgba(31, 41, 51, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.login-shell,
.install-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel,
.install-panel {
    width: min(100%, 920px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-panel {
    max-width: 420px;
}

h1 {
    margin: 0 0 18px;
    font-size: 24px;
    letter-spacing: 0;
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 6px;
}

.notice.error {
    background: #fff5f5;
    color: var(--danger);
    border: 1px solid #ffc9c9;
}

.notice.success {
    background: #ebfbee;
    color: #2b8a3e;
    border: 1px solid #b2f2bb;
}

.login-form,
.install-form {
    display: grid;
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
    color: #374151;
    font-size: 14px;
}

label.wide {
    grid-column: 1 / -1;
}

input,
textarea {
    width: 100%;
    border: 1px solid #c9d1d9;
    border-radius: 6px;
    padding: 11px 12px;
    color: var(--ink);
    background: #fff;
    outline: none;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(24, 100, 171, 0.14);
}

.login-form button,
.install-form button,
.primary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
}

.login-form button:hover,
.install-form button:hover,
.primary-link:hover {
    background: var(--primary-dark);
}

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

.sidebar {
    background: #18324a;
    color: #edf2f7;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand {
    height: 64px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand span {
    font-weight: 800;
    letter-spacing: 0;
}

.brand a {
    color: #cdd7e1;
    text-decoration: none;
    font-size: 13px;
}

.new-chat {
    margin: 14px;
    min-height: 42px;
    border-radius: 6px;
    background: #2f9e44;
    color: #fff;
    font-weight: 700;
}

.conversation-list {
    overflow: auto;
    padding: 0 10px 16px;
}

.conversation-item {
    width: 100%;
    min-height: 44px;
    padding: 9px 10px;
    border-radius: 6px;
    display: grid;
    gap: 2px;
    text-align: left;
    background: transparent;
    color: #edf2f7;
}

.conversation-item:hover,
.conversation-item.active {
    background: rgba(255, 255, 255, 0.12);
}

.conversation-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-item time {
    color: #b7c3cf;
    font-size: 12px;
}

.chat {
    height: 100vh;
    display: grid;
    grid-template-rows: 64px minmax(0, 1fr) auto;
    background: #fbfaf8;
}

.chat-header {
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    background: rgba(255, 255, 255, 0.86);
}

.chat-header h1 {
    margin: 0;
    max-width: min(62vw, 720px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 18px;
}

.chat-header p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.icon-button {
    display: none;
    width: 38px;
    height: 38px;
    border-radius: 6px;
    background: #e7edf3;
    color: #163047;
}

.messages {
    overflow: auto;
    padding: 28px min(5vw, 62px);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.empty-state {
    margin: auto;
    max-width: 520px;
    color: var(--muted);
    text-align: center;
    line-height: 1.7;
}

.message {
    display: grid;
    gap: 7px;
    max-width: 880px;
}

.message.user {
    align-self: flex-end;
    justify-items: end;
}

.message.assistant {
    align-self: flex-start;
}

.role {
    color: var(--muted);
    font-size: 12px;
}

.bubble {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 15px;
    line-height: 1.68;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #fff;
}

.message.user .bubble {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 92px;
    gap: 12px;
    padding: 16px 22px 20px;
    border-top: 1px solid var(--line);
    background: #fff;
}

.composer textarea {
    min-height: 48px;
    max-height: 180px;
    resize: none;
}

.composer button {
    min-height: 48px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}

.composer button:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

@media (max-width: 760px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 20;
        width: min(84vw, 320px);
        transform: translateX(-100%);
        transition: transform 0.18s ease;
    }

    .app.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .icon-button {
        display: inline-grid;
        place-items: center;
    }

    .chat-header {
        padding: 0 14px;
    }

    .messages {
        padding: 20px 14px;
    }

    .composer {
        grid-template-columns: 1fr;
        padding: 12px;
    }
}
