:root {
    /* BREDEX corporate palette (from bredex.de) */
    --bg: #f5f6f7;
    --surface: #ffffff;
    --border: #e2e4e8;
    --text: #4c4c4f;
    --muted: #7a7a7e;
    --primary: #2b329b;        /* indigo – primary action (site buttons) */
    --primary-hover: #232a82;
    --accent: #008872;         /* teal – links / highlights */
    --accent-2: #109282;
    --accent-tint: #e5f3f1;    /* light teal background tint */
    --magenta: #d60a49;        /* logo highlight */
    --danger: #d9534f;
    --user-bubble: #2b329b;
    --assistant-bubble: #f0f1f4;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Maven Pro", Calibri, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

/* Brand lockup (helix mark + wordmark) shown in headers and cards */
.brand { display: inline-flex; align-items: center; gap: 0.55rem; text-decoration: none; }
.brand-mark { height: 34px; width: auto; display: block; }
.brand-mark-sm { height: 26px; }
.brand-name { font-weight: 700; font-size: 1.25rem; letter-spacing: 0.04em; color: var(--text); }
.brand-sub { font-weight: 500; color: var(--accent); font-size: 1.05rem; margin-left: 0.15rem; }
.brand-centered { justify-content: center; margin-bottom: 0.5rem; }
.brand-centered .brand-mark { height: 48px; }
.brand-centered .brand-name { font-size: 1.6rem; }
.brand-centered .brand-sub { font-size: 1.35rem; }

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

/* Discreet Impressum link in the bottom-right corner (non-chat pages). */
.impressum-link {
    position: fixed;
    bottom: 0.6rem;
    right: 1rem;
    z-index: 50;
    font-size: 0.8rem;
    color: var(--muted);
    text-decoration: none;
}
.impressum-link:hover { color: var(--accent); text-decoration: underline; }

/* DE/EN language switch */
.lang-switch {
    position: fixed;
    bottom: 0.6rem;
    left: 1rem;
    z-index: 50;
    font-size: 0.8rem;
}
.lang-switch.inline { position: static; font-size: 0.85rem; }
.lang-switch a {
    color: var(--muted);
    text-decoration: none;
    padding: 0 0.25rem;
}
.lang-switch a.active { color: var(--text); font-weight: 700; }
.lang-switch a:hover { color: var(--accent); }

/* Consistent bottom-left footer: language switch + imprint together (non-chat pages). */
.page-footer {
    position: fixed;
    bottom: 0.6rem;
    left: 1rem;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.page-footer > a {
    font-size: 0.8rem;
    color: var(--muted);
    text-decoration: none;
}
.page-footer > a:hover { color: var(--accent); text-decoration: underline; }
/* Footer (language switch + imprint) pinned to the bottom of the chat sidebar. */
.sidebar-footer {
    margin-top: auto;
    padding-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.sidebar-impressum {
    font-size: 0.85rem;
    color: var(--muted);
    text-decoration: none;
}
.sidebar-impressum:hover { color: var(--accent); text-decoration: underline; }
.small { font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.9rem; }
.inline { display: inline; margin: 0; }

/* Buttons — normalized so <a>, <button> and submit inputs render identically */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    vertical-align: middle;
}
.btn:hover { background: #f0f0f3; }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #ececf0; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #fdecec; }

/* Centered card layout (join, event created) */
.centered {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.05);
}
.card h1 { margin-top: 0; }

.join-form { display: flex; flex-direction: column; gap: 0.75rem; margin: 1.5rem 0 0.5rem; }
.code-input {
    font-size: 1.6rem;
    letter-spacing: 0.4rem;
    text-align: center;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.big-code {
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: 0.5rem;
    margin: 1rem 0;
    color: var(--primary);
}

/* Separator + organizer login tile on the join page */
.login-divider {
    height: 1px;
    background: var(--border);
    margin: 1.75rem 0 1.1rem;
}
.organizer-tile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-align: left;
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.85rem;
    color: var(--text);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.organizer-tile:hover {
    background: var(--accent-tint);
    border-color: var(--accent-2);
}
.organizer-tile-mark { height: 30px; width: auto; flex-shrink: 0; }
.organizer-tile-text { display: flex; flex-direction: column; line-height: 1.3; flex: 1; }
.organizer-tile-label { font-weight: 600; }
.organizer-tile-arrow { color: var(--muted); font-size: 1.25rem; flex-shrink: 0; }

.error-code {
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0.75rem 0 0.25rem;
    line-height: 1;
}
.error-message { color: var(--muted); margin: 0 0 1.5rem; }

/* Admin */
.admin-body { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.admin-header-right { display: flex; align-items: center; gap: 0.75rem; }
.admin-main { margin-top: 1.5rem; }
.page-title { margin: 0 0 1rem; font-size: 1.4rem; color: var(--text); }

.event-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.event-table th, .event-table td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--border); }
.event-table th { background: #fafafb; font-weight: 600; }
.code-cell { font-size: 1.05rem; letter-spacing: 0.1rem; }
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }

.badge { padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.78rem; }
.badge-active { background: var(--accent-tint); color: var(--accent); }
.badge-inactive { background: #f0f0f3; color: var(--muted); }
.badge-you { background: #e9ebf8; color: var(--primary-hover); margin-left: 0.3rem; }

.event-form { display: flex; flex-direction: column; gap: 0.4rem; max-width: 640px; }
.event-form label { font-weight: 600; margin-top: 0.75rem; }
.event-form input, .event-form textarea {
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    width: 100%;
}
.form-actions { margin-top: 1.25rem; }

/* Chat (ChatGPT-style) */
/* 100dvh = dynamic viewport height: accounts for the mobile browser toolbar so the
   composer never ends up below the visible area (100vh kept as fallback). */
.chat-body { height: 100vh; height: 100dvh; margin: 0; overflow: hidden; }
.chat-layout { display: flex; height: 100vh; height: 100dvh; }

/* Sidebar with the conversation list */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    gap: 0.75rem;
    overflow-y: auto;
}
.sidebar-backdrop { display: none; }
.new-chat-btn { width: 100%; }
.chat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.chat-list-item {
    display: flex;
    align-items: center;
    border-radius: var(--radius);
    overflow: hidden;
}
.chat-list-item:hover { background: #ececf0; }
.chat-list-item.active { background: var(--accent-tint); }
.chat-list-title {
    flex: 1;
    text-align: left;
    background: none;
    border: none;
    padding: 0.55rem 0.6rem;
    cursor: pointer;
    font: inherit;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-list-delete {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.6rem;
    opacity: 0;
}
.chat-list-item:hover .chat-list-delete,
.chat-list-item.active .chat-list-delete { opacity: 1; }
.chat-list-delete:hover { color: var(--danger); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header-left { display: flex; align-items: center; gap: 0.6rem; }
.icon-btn { padding: 0.4rem 0.6rem; font-size: 1.1rem; line-height: 1; }
/* Hamburger toggle is only needed on mobile (sidebar is always visible on desktop). */
#toggle-sidebar { display: none; }
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.chat-title { font-weight: 600; }
.chat-actions { display: flex; gap: 0.5rem; align-items: center; }

.messages {
    flex: 1;
    min-height: 0;            /* lets the list scroll instead of pushing header/composer out */
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
}
.message { display: flex; }
.message.user { justify-content: flex-end; }
.bubble {
    padding: 0.7rem 1rem;
    border-radius: 14px;
    max-width: 80%;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.message.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.message.assistant .bubble { background: var(--assistant-bubble); color: var(--text); border-bottom-left-radius: 4px; white-space: normal; }
.bubble.error { background: #fdecec; color: var(--danger); }

/* Markdown rendering inside assistant bubbles */
.message.assistant .bubble > :first-child { margin-top: 0; }
.message.assistant .bubble > :last-child { margin-bottom: 0; }
.message.assistant .bubble p { margin: 0 0 0.6rem; }
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3,
.message.assistant .bubble h4 { margin: 0.9rem 0 0.5rem; line-height: 1.3; }
.message.assistant .bubble h1 { font-size: 1.3rem; }
.message.assistant .bubble h2 { font-size: 1.15rem; }
.message.assistant .bubble h3 { font-size: 1.05rem; }
.message.assistant .bubble h4 { font-size: 1rem; }
.message.assistant .bubble ul,
.message.assistant .bubble ol { margin: 0 0 0.6rem; padding-left: 1.4rem; }
.message.assistant .bubble li { margin: 0.2rem 0; }
.message.assistant .bubble a { color: var(--accent); }
.message.assistant .bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.1rem 0.35rem;
    border-radius: 5px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.9em;
}
.message.assistant .bubble pre.code-block {
    background: #1e1e1e;
    color: #e6e6e6;
    padding: 0.9rem 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0 0 0.6rem;
}
.message.assistant .bubble pre.code-block code {
    background: none;
    padding: 0;
    color: inherit;
    white-space: pre;
    font-size: 0.85rem;
}

.composer {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
}
.composer textarea {
    flex: 1;
    resize: none;
    padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    max-height: 180px;
}
.empty-hint { text-align: center; color: var(--muted); margin-top: 2rem; }

/* Mandatory consent overlay (data-protection notice) */
.consent-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(31, 35, 41, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.consent-overlay.hidden { display: none; }
.consent-card {
    background: var(--surface);
    border-radius: 16px;
    width: 100%;
    max-width: 540px;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 1.75rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.consent-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.consent-head svg { color: var(--magenta); flex-shrink: 0; }
.consent-head h2 { margin: 0; font-size: 1.3rem; }
.consent-list {
    list-style: none;
    margin: 1rem 0 1.25rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.consent-list li { display: flex; gap: 0.7rem; align-items: flex-start; }
.consent-list li svg { flex-shrink: 0; margin-top: 1px; color: var(--accent); }
.consent-list li.warn svg { color: var(--magenta); }
.consent-check {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin-bottom: 1.25rem;
    cursor: pointer;
    font-size: 0.95rem;
}
.consent-check input { margin-top: 0.2rem; flex-shrink: 0; }
.consent-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* On small screens the sidebar becomes an off-canvas drawer toggled by the ☰ button. */
@media (max-width: 768px) {
    /* Show the hamburger toggle. */
    #toggle-sidebar { display: inline-flex; }

    /* Sidebar slides in from the left; hidden by default so the chat is fully visible. */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        width: 82%;
        max-width: 300px;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.18);
    }
    .chat-layout.nav-open .sidebar { transform: translateX(0); }

    /* Dimmed backdrop behind the open drawer; tap to close. */
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 25;
    }
    .chat-layout.nav-open .sidebar-backdrop { display: block; }

    /* Keep the chat usable on small screens. */
    .messages,
    .composer { padding-left: 1rem; padding-right: 1rem; }
}
