:root {
    color-scheme: light;
    --bg: #f7f7f5;
    --panel: #ffffff;
    --panel-soft: #f0f2ef;
    --text: #1f2420;
    --muted: #667067;
    --line: #dfe4dd;
    --accent: #157a57;
    --accent-dark: #0f5f44;
    --assistant: #ffffff;
    --user: #ddf5e9;
    --shadow: 0 18px 48px rgba(34, 43, 36, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
textarea,
input {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 292px 1fr;
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 18px;
    background: #202820;
    color: #f6fbf6;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #d7f6e5;
    color: #174832;
}

.new-chat,
.conversation-item,
#send-button {
    border: 0;
    cursor: pointer;
}

.new-chat {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    background: #eef8ef;
    color: #193f2e;
    text-align: left;
    font-weight: 650;
}

.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}

.conversation-item {
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.78);
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.chat {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-width: 0;
    max-height: 100vh;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 32px;
    border-bottom: 1px solid var(--line);
    background: rgba(247, 247, 245, 0.88);
    backdrop-filter: blur(14px);
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 13px;
}

h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.25;
}

.status {
    flex: 0 0 auto;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: var(--panel);
    font-size: 13px;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    padding: 32px max(32px, calc((100vw - 980px) / 2));
}

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

.empty-state h2 {
    margin: 0 0 10px;
    color: var(--text);
    font-size: 28px;
}

.empty-state p {
    margin: 0;
    line-height: 1.7;
}

.message {
    display: grid;
    grid-template-columns: 38px minmax(0, 760px);
    gap: 12px;
    align-items: start;
}

.message.user {
    justify-content: end;
    grid-template-columns: minmax(0, 760px) 38px;
}

.avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: #263228;
    color: #ffffff;
    font-weight: 700;
}

.message.user .avatar {
    grid-column: 2;
    background: var(--accent);
}

.bubble {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--assistant);
    box-shadow: 0 8px 24px rgba(33, 40, 35, 0.05);
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.user .bubble {
    grid-column: 1;
    grid-row: 1;
    background: var(--user);
    border-color: #c4ead6;
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 18px max(32px, calc((100vw - 980px) / 2)) 24px;
    border-top: 1px solid var(--line);
    background: var(--bg);
}

#message-input {
    width: 100%;
    max-height: 180px;
    resize: none;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    outline: none;
    line-height: 1.5;
    box-shadow: var(--shadow);
}

#message-input:focus {
    border-color: rgba(21, 122, 87, 0.65);
}

#send-button {
    align-self: end;
    min-width: 82px;
    min-height: 52px;
    padding: 0 20px;
    border-radius: 8px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
}

#send-button:hover {
    background: var(--accent-dark);
}

#send-button:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.admin-body {
    background: #f3f5f1;
}

.admin-shell {
    width: min(960px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.admin-link {
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}

.admin-form {
    display: grid;
    gap: 18px;
}

.admin-section {
    display: grid;
    gap: 14px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 24px rgba(33, 40, 35, 0.05);
}

.admin-section h2 {
    margin: 0;
    font-size: 18px;
}

.admin-section label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
}

.admin-section input[type="text"],
.admin-section input[type="url"],
.admin-section input[type="password"],
.admin-section input[type="number"],
.admin-section textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: #fbfcfa;
    outline: none;
}

.admin-section textarea {
    resize: vertical;
    line-height: 1.55;
}

.admin-section small {
    color: var(--muted);
}

.switch-row {
    display: flex !important;
    grid-template-columns: none !important;
    align-items: center;
    gap: 10px !important;
    color: var(--text) !important;
}

.switch-row input {
    width: 18px;
    height: 18px;
}

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

.admin-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 0;
    background: #f3f5f1;
}

#save-settings {
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
}

#save-settings:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 800px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
        max-height: 220px;
    }

    .chat {
        min-height: calc(100vh - 220px);
    }

    .chat-header,
    .messages,
    .composer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .message,
    .message.user {
        grid-template-columns: 34px minmax(0, 1fr);
        justify-content: stretch;
    }

    .message.user .avatar {
        grid-column: 1;
    }

    .message.user .bubble {
        grid-column: 2;
    }

    .avatar {
        width: 34px;
        height: 34px;
    }

    .admin-header,
    .admin-actions {
        align-items: stretch;
        flex-direction: column;
    }

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