/* ── Farben: Hell- und Dunkel-Modus ── */
:root {
    --bg: #f0f4f8;
    --container-bg: #ffffff;
    --text: #1a202c;
    --text-muted: #718096;
    --border: #e2e8f0;
    --input-bg: #f7fafc;
    --bot-msg-bg: #ebf8ff;
    --bot-msg-border: #4299e1;
    --user-msg-bg: #4299e1;
    --user-msg-text: #ffffff;
    --btn-bg: #4299e1;
    --btn-hover: #3182ce;
    --btn-disabled: #a0aec0;
    --shadow: rgba(0, 0, 0, 0.1);
    --toggle-bg: #e2e8f0;
}

[data-theme="dark"] {
    --bg: #1a202c;
    --container-bg: #2d3748;
    --text: #f7fafc;
    --text-muted: #a0aec0;
    --border: #4a5568;
    --input-bg: #1a202c;
    --bot-msg-bg: #2c4a6e;
    --bot-msg-border: #4299e1;
    --user-msg-bg: #3182ce;
    --user-msg-text: #ffffff;
    --btn-bg: #4299e1;
    --btn-hover: #63b3ed;
    --btn-disabled: #4a5568;
    --shadow: rgba(0, 0, 0, 0.4);
    --toggle-bg: #4a5568;
}

/* ── Reset ── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

/* ── Topbar ── */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--container-bg);
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 200;
    justify-content: space-between;
    gap: 12px;
}

.topbar img {
    height: 40px;
    object-fit: contain;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.2px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 14px;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background 0.2s ease, color 0.2s ease;
}

.nav-link:hover {
    background: var(--input-bg);
    color: var(--text);
}

.nav-link.active {
    background: var(--bot-msg-bg);
    color: var(--text);
}

/* ── Body ── */
body {
    padding-top: 60px;
    font-family: 'Segoe UI', Arial, sans-serif;
    background-color: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s ease;
    touch-action: manipulation;
}

/* ── Container ── */
.container {
    background: var(--container-bg);
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    max-width: 620px;
    height: 100dvh;
    max-height: 100dvh;
    box-shadow: 0 8px 32px var(--shadow);
    transition: background 0.3s ease, box-shadow 0.3s ease;
    animation: slideUp 0.4s ease;
    display: flex;
    flex-direction: column;
    touch-action: pan-y;
}

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

/* ── Header ── */
.header {
    display: flex;
    flex-direction: column;
    gap: 0px;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--border);
}

.logo-center {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    animation: bounce 2s infinite;
}

.logo-center img {
    width: 120px;
    height: 120px;
    object-fit: contain;
}

/* Erste Zeile: Buttons rechts */
.header-top {
    display: flex;
    justify-content: flex-end;
}

/* Zweite Zeile: Subtitle linksbündig */
.subtitle {
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Buttons im Header ── */
.theme-toggle {
    background: var(--toggle-bg);
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.2s ease, background 0.3s ease;
    flex-shrink: 0;
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(20deg);
}

.reset-btn {
    background: var(--toggle-bg);
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
}

.reset-btn:hover {
    transform: scale(1.1);
    background: #fed7d7;
}

.logout-btn {
    background: var(--toggle-bg);
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    padding: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-btn svg {
    width: 100%;
    height: 100%;
}

.logout-btn:hover {
    transform: scale(1.1);
    background: #fed7d7;
}

/* ── Quick Actions ── */
.quick-actions-wrapper {
    position: relative;
    flex-shrink: 0;
}

.quick-actions-btn {
    background: var(--toggle-bg);
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.3s ease;
}

.quick-actions-btn:hover {
    transform: scale(1.1);
}

.quick-actions-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--container-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    width: 240px;
    box-shadow: 0 8px 24px var(--shadow);
    z-index: 100;
    flex-direction: column;
    gap: 6px;
}

.quick-actions-panel.open {
    display: flex;
}

.quick-actions-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
}

.quick-actions-panel button {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-family: inherit;
    line-height: 1.4;
}

.quick-actions-panel button:hover {
    background: var(--bot-msg-bg);
    border-color: var(--bot-msg-border);
}

/* ── Chat Box ── */
.chat-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 4px;
    margin-bottom: 16px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
/* ── Nachrichten ── */
.message {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

.bot-message { justify-content: flex-start; }

.bot-message span {
    background: var(--bot-msg-bg);
    border-left: 4px solid var(--bot-msg-border);
    color: var(--text);
    padding: 12px 16px;
    border-radius: 0 12px 12px 12px;
    max-width: 85%;
    line-height: 1.6;
    font-size: 15px;
}

.user-message { justify-content: flex-end; }

.user-message span {
    background: var(--user-msg-bg);
    color: var(--user-msg-text);
    padding: 12px 16px;
    border-radius: 12px 12px 0 12px;
    max-width: 85%;
    line-height: 1.6;
    font-size: 15px;
}

/* ── Tipp-Animation ── */
.typing span {
    background: var(--bot-msg-bg);
    border-left: 4px solid var(--bot-msg-border);
    color: var(--text-muted);
    padding: 12px 16px;
    border-radius: 0 12px 12px 12px;
    font-size: 22px;
    letter-spacing: 4px;
    animation: typing 1s infinite;
}

@keyframes typing {
    0%, 100% { opacity: 0.3; }
    50%       { opacity: 1; }
}

/* ── Eingabebereich ── */
.input-area {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    border-top: 2px solid var(--border);
    padding-top: 16px;
}

textarea {
    flex: 1;
    padding: 12px 14px;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    color: var(--text);
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, background 0.3s ease;
    font-family: inherit;
    max-height: 120px;
}

textarea:focus { border-color: var(--btn-bg); }
textarea::placeholder { color: var(--text-muted); }

/* ── Senden-Button ── */
#btn {
    width: 46px;
    height: 46px;
    background: var(--btn-bg);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

#btn:hover { background: var(--btn-hover); transform: scale(1.05); }
#btn:active { transform: scale(0.95); }
#btn:disabled { background: var(--btn-disabled); cursor: not-allowed; transform: none; }

/* ── Scrollbar ── */
.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-track { background: transparent; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Markdown Styling ── */
.bot-message span p { margin-bottom: 8px; }
.bot-message span p:last-child { margin-bottom: 0; }
.bot-message span strong { font-weight: 700; color: var(--text); }
.bot-message span ul, .bot-message span ol { padding-left: 20px; margin: 6px 0; }
.bot-message span li { margin-bottom: 4px; line-height: 1.5; }

/* ── Ladezeit ── */
.ladezeit {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ── Fehlermeldung ── */
.message.fehler span {
    background: #fff5f5;
    border-left: 4px solid #fc8181;
    color: #c53030;
    padding: 12px 16px;
    border-radius: 0 12px 12px 12px;
    max-width: 85%;
    font-size: 15px;
}

[data-theme="dark"] .message.fehler span {
    background: #3d1515;
    border-left-color: #fc8181;
    color: #feb2b2;
}

/* ── Desktop (ab 601px) ── */
@media (min-width: 601px) {
    body {
        align-items: stretch;
        padding-top: 60px;
    }

    .container {
        max-width: 100%;
        border-radius: 0;
        padding: 24px 60px;
        box-shadow: none;
        height: calc(100dvh - 60px);
        max-height: calc(100dvh - 60px);
    }

    .logo-center img {
        width: 100px;
        height: 100px;
    }

    .subtitle {
        font-size: 14px;
    }

    .header-buttons {
        gap: 12px;
    }

    .theme-toggle, .reset-btn, .quick-actions-btn, .logout-btn {
        width: 44px;
        height: 44px;
        font-size: 20px;
        position: relative;
    }

    /* Tooltips für Desktop-Buttons */
    .header-buttons button::after,
    .quick-actions-wrapper .quick-actions-btn::after {
        content: attr(title);
        position: absolute;
        bottom: calc(100% + 8px);
        left: 50%;
        transform: translateX(-50%) scale(0.8);
        background: #1a202c;
        color: #fff;
        font-size: 12px;
        padding: 5px 10px;
        border-radius: 6px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    .header-buttons button::before,
    .quick-actions-wrapper .quick-actions-btn::before {
        content: '';
        position: absolute;
        bottom: calc(100% + 2px);
        left: 50%;
        transform: translateX(-50%);
        border: 5px solid transparent;
        border-top-color: #1a202c;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .header-buttons button:hover::after,
    .header-buttons button:hover::before,
    .quick-actions-wrapper .quick-actions-btn:hover::after,
    .quick-actions-wrapper .quick-actions-btn:hover::before {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }

    .theme-toggle:hover,
    .reset-btn:hover,
    .quick-actions-btn:hover,
    .logout-btn:hover {
        transform: scale(1.2);
    }

    .bot-message span, .user-message span {
        font-size: 16px;
        max-width: 65%;
    }

    .message.fehler span {
        font-size: 16px;
        max-width: 65%;
    }

    textarea {
        font-size: 16px;
        padding: 14px 18px;
    }

    #btn {
        width: 52px;
        height: 52px;
        font-size: 20px;
    }

    .chat-box {
        gap: 16px;
        padding: 12px 0;
    }

    .quick-actions-panel {
        width: 280px;
    }

    .quick-actions-panel button {
        font-size: 14px;
    }

    /* Topbar auf Desktop — unverändert lassen */
}

/* ── Responsive (Handy) ── */
@media (max-width: 600px) {
    body { align-items: stretch; padding: 0; }

    .container {
        border-radius: 0;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        box-shadow: none;
    }

    .input-area { padding-bottom: env(safe-area-inset-bottom); }

    .logo-center img { width: 90px; height: 90px; }

    .theme-toggle, .reset-btn, .quick-actions-btn, .logout-btn {
        width: 36px;
        height: 36px;
        font-size: 15px;
    }

    .bot-message span, .user-message span { font-size: 14px; max-width: 92%; }
    textarea { font-size: 16px; }
    #btn { width: 44px; height: 44px; font-size: 16px; }

    .quick-actions-wrapper { position: static; }
    .quick-actions-panel {
        position: fixed;
        top: auto;
        bottom: 90px;
        left: 12px;
        right: 12px;
        width: auto;
    }

    .nav-brand span {
        display: none;
    }

    .nav-links {
        gap: 4px;
    }

    .nav-link {
        font-size: 12px;
        padding: 7px 8px;
    }
}
