/* Gravity UI — Design-System
   Eigenes Custom-Design (kein Bootstrap/Tailwind).
   Light-Mode Default, optionaler Dark-Mode via [data-theme="dark"].
   Mobile-responsive (Sidebar kollabiert auf <768px).
*/
:root {
    --bg: #fafaf9;
    --bg-elev: #ffffff;
    --bg-sidebar: #f5f5f4;
    --border: #e7e5e4;
    --border-strong: #d6d3d1;
    --text: #1c1917;
    --text-muted: #78716c;
    --text-faint: #a8a29e;
    --accent: #ea580c;
    --accent-soft: #fed7aa;
    --accent-bg: #fff7ed;
    --user-bubble: #ea580c;
    --user-text: #ffffff;
    --assistant-bubble: #ffffff;
    --code-bg: #f5f5f4;
    --code-text: #1c1917;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
    --radius: 10px;
    --radius-sm: 6px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Inter", sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
}

[data-theme="dark"] {
    --bg: #0c0a09;
    --bg-elev: #1c1917;
    --bg-sidebar: #16131280;
    --border: #292524;
    --border-strong: #44403c;
    --text: #f5f5f4;
    --text-muted: #a8a29e;
    --text-faint: #78716c;
    --accent: #fb923c;
    --accent-soft: #7c2d12;
    --accent-bg: #1c1917;
    --user-bubble: #ea580c;
    --user-text: #ffffff;
    --assistant-bubble: #1c1917;
    --code-bg: #0c0a09;
    --code-text: #f5f5f4;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* === Sidebar === */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    width: 24px;
    height: 24px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 13px;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.project-picker {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.project-picker label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

select, input, textarea {
    font-family: inherit;
    font-size: 13px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    width: 100%;
    outline: none;
    transition: border-color 0.1s, box-shadow 0.1s;
}

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

select:disabled, input:disabled, textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.conv-list-header {
    padding: 12px 20px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conv-list-header span {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    transition: all 0.1s;
}

.icon-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.conv-list {
    list-style: none;
    margin: 0;
    padding: 0 8px 12px;
    overflow-y: auto;
    flex: 1;
}

.conv-list:empty::after {
    content: "Noch keine Chats";
    display: block;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-faint);
    font-style: italic;
}

.conv-list li {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    margin-bottom: 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.1s;
}

.conv-list li:hover {
    background: var(--bg-elev);
}

.conv-list li.active {
    background: var(--accent-bg);
    color: var(--accent);
}

.conv-list .conv-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-list .conv-preview {
    font-size: 11px;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-style: italic;
}

.conv-list .conv-meta {
    font-size: 11px;
    color: var(--text-faint);
}

.sidebar-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #16a34a;
    flex-shrink: 0;
}

.status-dot.busy {
    background: var(--accent);
    animation: pulse 1.4s infinite;
}

.status-dot.error {
    background: #dc2626;
}

/* === Main === */
.main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    height: 56px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-elev);
    gap: 16px;
}

.chat-header .title {
    font-weight: 600;
    font-size: 14px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header .title .project {
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 8px;
}

.chat-header .title .project:empty {
    display: none;
}

.chat-header select {
    width: auto;
    min-width: 200px;
    font-size: 12px;
    flex-shrink: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 12px;
    margin: 0 auto 24px;
    max-width: 760px;
    padding: 0 24px;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.message .avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.message.user .avatar {
    background: var(--accent);
    color: white;
}

.message.assistant .avatar {
    background: var(--bg-sidebar);
    color: var(--text);
    border: 1px solid var(--border);
}

.message .body {
    flex: 1;
    min-width: 0;
}

.message .role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.message .content {
    color: var(--text);
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 14px;
}

.message .content code {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12.5px;
}

.message .content pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.5;
    margin: 8px 0;
}

.message .content pre code {
    background: none;
    padding: 0;
    font-size: inherit;
}

.typing {
    display: inline-flex;
    gap: 3px;
    padding: 4px 0;
}

.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    animation: bounce 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* === Input === */
.chat-form {
    border-top: 1px solid var(--border);
    padding: 16px 24px 20px;
    background: var(--bg-elev);
}

.chat-form-inner {
    max-width: 760px;
    margin: 0 auto;
}

.input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px 8px 14px;
    transition: border-color 0.1s, box-shadow 0.1s;
}

.input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.input-wrap textarea {
    border: none;
    background: transparent;
    resize: none;
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    padding: 4px 0;
}

.input-wrap textarea:focus {
    border: none;
    box-shadow: none;
}

.send-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.1s, transform 0.1s;
}

.send-btn:hover:not(:disabled) {
    opacity: 0.9;
}

.send-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hint {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 8px;
    text-align: center;
}

.hint kbd {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 4px;
    font-family: var(--font-mono);
    font-size: 10px;
}

.hint code {
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg-sidebar);
    padding: 1px 4px;
    border-radius: 3px;
}

/* === Empty state === */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty .glyph {
    width: 56px;
    height: 56px;
    background: var(--accent-bg);
    color: var(--accent);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
}

.empty h2 {
    margin: 0 0 6px;
    font-size: 18px;
    color: var(--text);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.empty p {
    margin: 0;
    max-width: 320px;
    line-height: 1.5;
}

/* === Status bar === */
.status {
    font-size: 11px;
    color: var(--text-faint);
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
}

.status.thinking {
    color: var(--accent);
}

.status.error {
    color: #dc2626;
}

.status .pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.4s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 1; }
}

/* Mobile */
@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .chat-header { padding: 0 16px; }
    .chat-header select { min-width: 140px; font-size: 11px; }
    .message { padding: 0 16px; }
    .chat-form { padding: 12px 16px 16px; }
}
