:root {
    color-scheme: light;
    --bg: #f5f7f4;
    --surface: #ffffff;
    --surface-2: #eef3ef;
    --surface-3: #e7ece8;
    --line: #d5ddd7;
    --line-strong: #aebcb1;
    --text: #18211b;
    --muted: #627067;
    --accent: #126b52;
    --accent-2: #d94f30;
    --accent-soft: #dceee8;
    --danger: #b42318;
    --success: #18734d;
    --shadow: 0 18px 50px rgba(33, 50, 39, 0.12);
}

* {
    box-sizing: border-box;
}

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

body {
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    color: var(--text);
    background:
        linear-gradient(120deg, rgba(18, 107, 82, 0.08), transparent 38%),
        linear-gradient(180deg, #fbfcfb 0%, var(--bg) 100%);
}

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

button {
    cursor: pointer;
}

textarea {
    resize: vertical;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
}

.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
}

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

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    margin-bottom: 18px;
}

.kicker {
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 24px;
    line-height: 1.2;
}

h2 {
    font-size: 18px;
}

.muted,
.status-line,
.empty-note {
    color: var(--muted);
    line-height: 1.6;
}

.status-line {
    min-height: 22px;
    margin-top: 10px;
    font-size: 13px;
}

.status-line.error {
    color: var(--danger);
}

.status-line.success {
    color: var(--success);
}

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

.session-drawer {
    min-height: 100vh;
    border-right: 1px solid var(--line);
    background: #f8faf8;
    padding: 16px;
}

.drawer-head,
.app-topbar,
.composer-actions,
.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.drawer-head {
    margin-bottom: 14px;
}

.main-panel {
    min-width: 0;
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    height: 100vh;
}

.app-topbar {
    min-height: 70px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(12px);
}

.title-block {
    min-width: 0;
    flex: 1;
}

.title-block h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.control-strip {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.param-grid {
    display: grid;
    grid-template-columns: 1fr 100px;
    gap: 10px;
}

.field {
    display: grid;
    gap: 7px;
    margin-top: 14px;
}

.compact-field {
    margin-top: 0;
}

.field span {
    color: var(--muted);
    font-size: 13px;
}

.field input,
.field select,
.field textarea,
.composer textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    outline: none;
}

.field input,
.field select {
    min-height: 42px;
    padding: 0 10px;
}

.field textarea,
.composer textarea {
    padding: 11px 12px;
    line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.composer textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-btn,
.ghost-btn,
.icon-btn,
.quick-chip,
.delete-btn {
    border: 0;
    border-radius: 8px;
    min-height: 42px;
    padding: 0 14px;
    font-weight: 700;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
}

.primary-btn:disabled {
    opacity: 0.65;
}

.ghost-btn,
.icon-btn,
.quick-chip {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
}

.compact {
    min-height: 38px;
}

.full {
    width: 100%;
}

.icon-btn,
.delete-btn {
    width: 42px;
    padding: 0;
    font-size: 20px;
}

.delete-btn {
    background: transparent;
    color: var(--muted);
}

.quick-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: #fbfcfb;
}

.quick-chip {
    white-space: nowrap;
    min-height: 36px;
    font-size: 13px;
}

.session-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.session-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 8px;
}

.session-item.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.session-main {
    min-width: 0;
    flex: 1;
    display: grid;
    gap: 4px;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 4px;
}

.session-main strong,
.session-main span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-main span {
    color: var(--muted);
    font-size: 12px;
}

.message-list {
    overflow: auto;
    padding: 18px;
    display: grid;
    align-content: start;
    gap: 12px;
}

.message-card {
    width: min(820px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
    background: var(--surface);
}

.message-card.user {
    justify-self: end;
    background: #eef6f2;
    border-color: #c9dfd4;
}

.message-card.assistant {
    justify-self: start;
}

.message-card.pending {
    opacity: 0.75;
}

.message-meta {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
}

.message-body {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.78;
}

.empty-state {
    width: min(520px, 100%);
    display: grid;
    gap: 8px;
    margin: 12vh auto 0;
    padding: 18px;
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.72);
}

.empty-state strong {
    color: var(--text);
}

.composer {
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding: 14px 18px max(14px, env(safe-area-inset-bottom));
}

.attachment-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.file-input {
    display: none;
}

.attachment-hint {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.attachment-list {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--surface-2);
}

.attachment-check {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.attachment-check span {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.attachment-check strong,
.attachment-check small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-check small {
    color: var(--muted);
    font-size: 12px;
}

.attachment-actions {
    display: flex;
    gap: 6px;
}

.link-btn {
    border: 0;
    background: transparent;
    color: var(--accent);
    font-weight: 700;
    padding: 6px;
}

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

.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.attachment-tag {
    display: inline-flex;
    max-width: 100%;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--muted);
    padding: 4px 8px;
    font-size: 12px;
}

.composer textarea {
    min-height: 96px;
}

.composer-actions {
    margin-top: 10px;
}

.composer-actions .primary-btn {
    min-width: 116px;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 20;
}

@media (max-width: 860px) {
    .workspace-view {
        display: block;
    }

    .session-drawer {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(84vw, 340px);
        transform: translateX(-105%);
        transition: transform 180ms ease;
        z-index: 30;
        box-shadow: var(--shadow);
    }

    .session-drawer.open {
        transform: translateX(0);
    }

    .main-panel {
        height: 100vh;
    }

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

    .param-grid {
        grid-template-columns: 1fr 112px;
    }

    .app-topbar,
    .quick-actions,
    .message-list,
    .composer {
        padding-left: 12px;
        padding-right: 12px;
    }

    .message-list {
        padding-top: 12px;
    }

    .composer-actions {
        display: grid;
        grid-template-columns: 1fr 1fr 1.2fr;
    }

    .attachment-bar,
    .attachment-item {
        align-items: stretch;
        flex-direction: column;
    }

    .attachment-actions {
        justify-content: flex-end;
    }
}

@media (min-width: 861px) {
    #openDrawerBtn,
    #closeDrawerBtn,
    .drawer-backdrop {
        display: none !important;
    }
}
