:root {
    color-scheme: light;
    --bg: #f4f6f3;
    --panel: #ffffff;
    --panel-soft: #eef3ef;
    --text: #222523;
    --muted: #66706a;
    --line: #d9e0db;
    --accent: #14795a;
    --accent-strong: #0e5e45;
    --accent-soft: #dff1ea;
    --project-blue: #1769d6;
    --warn: #b85b38;
    --code: #181c1a;
    --shadow: 0 18px 45px rgba(35, 45, 39, 0.12);
}

* {
    box-sizing: border-box;
}

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

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

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
    border-right: 1px solid var(--line);
    background: var(--panel);
    min-height: 100vh;
}

.brand {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 12px;
    align-items: center;
}

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

.brand h1 {
    margin: 0;
    font-size: 1.2rem;
    line-height: 1.1;
}

.brand p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.35;
}

.project-law-box {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid #cfe0fb;
    border-radius: 8px;
    background: #f2f7ff;
}

.project-law-box span {
    color: var(--project-blue);
    font-weight: 850;
}

.project-law-box a {
    display: grid;
    min-height: 34px;
    place-items: center;
    border-radius: 7px;
    background: var(--project-blue);
    color: #fff;
    padding: 0 12px;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 800;
}

.project-law-box a:hover {
    background: #0f55b1;
}

.control-group,
.model-box,
.quick-actions,
.conversation-panel {
    display: grid;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 38px;
    color: var(--text);
    font-weight: 650;
}

.toggle input {
    width: 42px;
    height: 24px;
    margin: 0;
    accent-color: var(--accent);
}

.model-box {
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
    color: var(--muted);
    font-size: 0.86rem;
}

.model-box strong {
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 700;
}

.quick-actions button {
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--text);
    font-weight: 650;
}

.quick-actions button:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.conversation-panel {
    min-height: 0;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.section-head span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.section-head button {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--panel-soft);
    color: var(--text);
    padding: 0 10px;
    font-weight: 750;
}

.conversation-list {
    display: grid;
    gap: 8px;
    overflow-y: auto;
    max-height: 34vh;
    padding-right: 2px;
}

.conversation-item {
    display: grid;
    gap: 4px;
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 8px 10px;
    text-align: left;
}

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

.conversation-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 750;
}

.conversation-date {
    color: var(--muted);
    font-size: 0.78rem;
}

.empty-conversations {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

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

.messages {
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    padding: 28px clamp(16px, 4vw, 56px);
}

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

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

.message.user .avatar {
    grid-column: 2;
    background: #343936;
}

.message.user .bubble {
    grid-column: 1;
    grid-row: 1;
    background: #e7ece8;
}

.avatar {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 800;
}

.bubble {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}

.bubble p {
    margin: 0 0 10px;
    line-height: 1.58;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble code {
    border-radius: 5px;
    background: #edf1ee;
    padding: 0.12rem 0.28rem;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: 0.92em;
}

.code-block {
    position: relative;
    margin: 12px 0;
    overflow: hidden;
    border-radius: 8px;
    background: var(--code);
}

.code-block pre {
    margin: 0;
    overflow-x: auto;
    padding: 16px;
}

.code-block code {
    display: block;
    background: transparent;
    color: #eef7f0;
    padding: 0;
    white-space: pre;
}

.copy-code {
    position: absolute;
    top: 8px;
    right: 8px;
    min-width: 34px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.78rem;
}

.sources {
    display: grid;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.sources a {
    color: var(--accent-strong);
    overflow-wrap: anywhere;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 700;
}

.sources a:hover {
    text-decoration: underline;
}

.meta {
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.82rem;
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px;
    gap: 10px;
    padding: 16px clamp(16px, 4vw, 56px) 20px;
    border-top: 1px solid var(--line);
    background: rgba(244, 246, 243, 0.94);
    backdrop-filter: blur(10px);
}

.composer textarea {
    width: 100%;
    max-height: 180px;
    min-height: 48px;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    padding: 13px 14px;
    outline: none;
    line-height: 1.4;
}

.composer textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(20, 121, 90, 0.16);
}

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

.composer button:disabled {
    cursor: wait;
    opacity: 0.68;
}

.typing .bubble {
    color: var(--muted);
}

.status-ok {
    color: var(--accent-strong) !important;
}

.status-warn {
    color: var(--warn) !important;
}

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

    .side-panel {
        position: sticky;
        top: 0;
        z-index: 5;
        gap: 12px;
        padding: 14px 16px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        min-height: 0;
    }

    .control-group,
    .quick-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .quick-actions button:first-child {
        grid-column: 1 / -1;
    }

    .model-box {
        display: none;
    }

    .conversation-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-height: 132px;
    }

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

    .messages {
        padding: 18px 14px;
    }

    .message,
    .message.user {
        grid-template-columns: 32px minmax(0, 1fr);
    }

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

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

    .avatar {
        width: 32px;
        height: 32px;
        font-size: 0.72rem;
    }

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