:root {
    color-scheme: light;
    --bg: #eef3f9;
    --panel: #ffffff;
    --text: #172033;
    --muted: #68758d;
    --line: #d9e2ef;
    --brand: #3157d8;
    --brand-dark: #213b9b;
    --sidebar: #111a2d;
    --success: #16805d;
    --warning: #b06b05;
    --danger: #b33737;
    --shadow: 0 14px 40px rgba(31, 51, 84, .08);
}

* { box-sizing: border-box; }

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

button, input, textarea { font: inherit; }

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 28px 22px;
    background: var(--sidebar);
    color: white;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    font-weight: 800;
    background: linear-gradient(135deg, #5f7eff, #3157d8);
}

.brand h1 {
    margin: 0;
    font-size: 18px;
}

.brand p {
    margin: 4px 0 0;
    color: #aeb9d0;
    font-size: 12px;
}

.status-card {
    margin-top: 30px;
    padding: 16px;
    border-radius: 16px;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.09);
}

.status-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.status-line + .status-line { margin-top: 12px; }

.status {
    font-size: 12px;
    padding: 5px 9px;
    border-radius: 999px;
}

.status.neutral { background: #33405d; color: #dfe6f5; }
.status.online { background: rgba(36, 184, 126, .2); color: #7ce0b9; }
.status.working { background: rgba(244, 171, 52, .2); color: #ffd187; }
.status.error { background: rgba(230, 79, 79, .2); color: #ffaaaa; }

.sidebar-note {
    margin-top: 20px;
    color: #aeb9d0;
    line-height: 1.6;
    font-size: 13px;
}

.main {
    min-width: 0;
    padding: 30px;
}

.topbar {
    max-width: 1040px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.topbar h2 { margin: 0; font-size: 27px; }
.topbar p { margin: 6px 0 0; color: var(--muted); }

.panel,
.messages,
.composer {
    max-width: 1040px;
    margin-left: auto;
    margin-right: auto;
}

.panel {
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.identity-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.field label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    background: white;
    outline: none;
}

input:focus, textarea:focus {
    border-color: #8ca2f4;
    box-shadow: 0 0 0 3px rgba(49, 87, 216, .11);
}

.messages {
    min-height: 340px;
    margin-top: 18px;
    padding: 22px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 17px;
}

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

.bubble {
    max-width: min(78%, 760px);
    padding: 13px 15px;
    border-radius: 16px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.user .bubble {
    color: white;
    background: var(--brand);
    border-bottom-right-radius: 5px;
}

.assistant .bubble {
    background: #f1f4f9;
    border: 1px solid #e3e8f0;
    border-bottom-left-radius: 5px;
}

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

.composer {
    margin-top: 18px;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.composer-footer {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

#counter { color: var(--muted); font-size: 12px; }

.button {
    border: 0;
    border-radius: 11px;
    padding: 11px 16px;
    cursor: pointer;
    font-weight: 750;
}

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

.button.primary {
    color: white;
    background: var(--brand);
}

.button.primary:hover { background: var(--brand-dark); }

.button.ghost {
    color: var(--text);
    background: white;
    border: 1px solid var(--line);
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
    }
    .main { padding: 18px; }
    .identity-panel { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; }
    .bubble { max-width: 92%; }
}
