:root {
    --primary: #6C5CE7;
    --secondary: #00B894;
    --bg: #0F1220;
    --surface: #1A1E33;
    --surface-alt: #242A47;
    --text: #F5F6FA;
    --muted: #A9AEC7;
    --accent: #FDCB6E;
    --border: #33395C;
    --radius: 14px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --danger: #FF7675;
    --success: #00B894;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

button {
    font-family: inherit;
}

/* ---------------- Login-Seite ---------------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(24px, var(--safe-top)) 20px max(24px, var(--safe-bottom));
    background: var(--bg); /* Fallback für Browser ohne color-mix()-Unterstützung */
}
.login-body {
    background:
        radial-gradient(circle at 20% 15%, color-mix(in srgb, var(--primary) 25%, transparent) 0%, transparent 45%),
        radial-gradient(circle at 80% 85%, color-mix(in srgb, var(--secondary) 20%, transparent) 0%, transparent 45%),
        var(--bg);
}

.login-wrap { width: 100%; display: flex; justify-content: center; }

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    padding: 32px 28px;
    box-shadow: 0 25px 70px rgba(0,0,0,0.45);
}

.brand { text-align: center; margin-bottom: 24px; }

.brand-badge {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: white;
    font-size: 1rem;
}

.brand h1 { font-size: 1.3rem; margin: 0 0 4px; }
.brand p { color: var(--muted); margin: 0; font-size: 0.9rem; }

.login-form { display: flex; flex-direction: column; gap: 6px; }

.login-form label {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 8px;
}

.login-form input {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 70%, black 5%);
    color: var(--text);
    font-size: 1.05rem;
}

.code-input {
    text-align: center;
    letter-spacing: 12px;
    font-size: 1.6rem !important;
    font-weight: 700;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent);
}

.login-form button {
    margin-top: 16px;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
}

.login-form button:active { transform: scale(0.98); }

.hint { text-align: center; color: var(--muted); font-size: 0.82rem; margin-top: 18px; }

.badge-category {
    display: inline-block;
    background: var(--surface-alt);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 16px;
}
.alert-error { background: color-mix(in srgb, var(--danger) 18%, transparent); border: 1px solid var(--danger); color: #ffc2c1; }
.alert-success { background: color-mix(in srgb, var(--success) 18%, transparent); border: 1px solid var(--success); color: #9df3da; }

/* ---------------- Chat-Oberfläche ---------------- */

.chat-body { background: var(--bg); }

.chat-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 900px;
    margin: 0 auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: max(14px, var(--safe-top)) 16px 14px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.chat-header-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-header-info h1 { font-size: 1.02rem; margin: 0; display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-header-info h1 .title-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.unread-badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 999px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--surface-alt);
}

.chat-category-pill {
    align-self: flex-start;
    background: color-mix(in srgb, var(--primary) 25%, transparent);
    color: var(--text);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 9px;
    border-radius: 999px;
}

.chat-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.me-badge {
    font-size: 0.78rem;
    color: var(--muted);
    display: none;
}
@media (min-width: 560px) {
    .me-badge { display: inline-block; }
}

.icon-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 1rem;
    cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.notes-panel {
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notes-panel-head { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; }
.notes-meta { color: var(--muted); font-size: 0.72rem; }

.notes-panel textarea {
    width: 100%;
    min-height: 90px;
    resize: vertical;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.9rem;
}

.notes-panel button {
    align-self: flex-end;
    border: none;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

.msg {
    max-width: 82%;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    align-self: flex-start;
}

.msg-admin {
    border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
    background: color-mix(in srgb, var(--accent) 12%, var(--surface-alt));
}

.msg-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 3px;
}

.msg-author-wrap { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg-author { font-weight: 700; color: var(--primary); }
.msg-admin .msg-author { color: var(--accent); }

.msg-alliance {
    background: color-mix(in srgb, var(--secondary) 22%, transparent);
    color: var(--text);
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 999px;
}

.msg-meta-right { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }

.msg-edited {
    font-size: 0.66rem;
    font-style: italic;
    color: var(--muted);
    opacity: 0.8;
}

.msg-action-btn {
    background: none;
    border: none;
    padding: 0 2px;
    font-size: 0.82rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.55;
    color: inherit;
}
.msg-action-btn:hover, .msg-action-btn:active { opacity: 1; }

.msg-body {
    font-size: 0.94rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-edit-textarea {
    width: 100%;
    min-height: 60px;
    resize: vertical;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 8px 10px;
}

.msg-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.readonly-notice {
    text-align: center;
    padding: 14px;
    color: var(--muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    padding-bottom: max(14px, var(--safe-bottom));
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 14px;
    padding-bottom: max(12px, var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
}

.composer textarea {
    flex: 1;
    resize: none;
    max-height: 140px;
    min-height: 44px;
    padding: 11px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.35;
}
.composer textarea:focus { outline: none; border-color: var(--primary); }

.composer button {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
}
.composer button:active { transform: scale(0.94); }

@media (max-width: 599px) {
    .chat-shell { border-left: none; border-right: none; }
    .msg { max-width: 90%; }
}
