/* === Reset & Basis === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --blue-light: #dbeafe;
    --green: #16a34a;
    --red: #dc2626;
    --orange: #f59e0b;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-500: #64748b;
    --gray-700: #334155;
    --gray-900: #0f172a;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.5;
    min-height: 100vh;
}

/* === Login === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-avatar { font-size: 64px; margin-bottom: 10px; }
.login-box h1 { font-size: 28px; color: var(--gray-900); margin-bottom: 4px; }
.login-box .subtitle { color: var(--gray-500); margin-bottom: 24px; }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 14px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s;
}
.form-group input:focus { outline: none; border-color: var(--blue); }

.error {
    background: #fef2f2;
    color: var(--red);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid #fecaca;
}

/* === Buttons === */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-outline { background: white; color: var(--gray-700); border: 2px solid var(--gray-200); }
.btn-outline:hover { border-color: var(--gray-300); background: var(--gray-50); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* === Chat Layout === */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 800px;
    margin: 0 auto;
    background: white;
    box-shadow: var(--shadow);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--blue);
    color: white;
    flex-shrink: 0;
}

.chat-header h1 { font-size: 18px; display: flex; align-items: center; gap: 8px; }
.chat-header-actions { display: flex; gap: 8px; }
.chat-header .btn-outline { color: white; border-color: rgba(255,255,255,0.3); background: transparent; }
.chat-header .btn-outline:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.5); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message-user { align-self: flex-end; flex-direction: row-reverse; }
.message-assistant { align-self: flex-start; }

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.message-user .message-avatar { background: var(--blue-light); }
.message-assistant .message-avatar { background: #f0fdf4; }

.message-bubble {
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-user .message-bubble {
    background: var(--blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
    background: var(--gray-100);
    color: var(--gray-900);
    border-bottom-left-radius: 4px;
}

.message-pending .message-bubble {
    background: #fef3c7;
    color: #92400e;
    border: 1px dashed var(--orange);
}

.message-rejected .message-bubble {
    background: #fef2f2;
    color: #991b1b;
    border: 1px dashed var(--red);
    text-decoration: line-through;
}

.pending-notice, .rejected-notice {
    font-size: 12px;
    margin-top: 4px;
    font-style: italic;
}
.pending-notice { color: #b45309; }
.rejected-notice { color: var(--red); }

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}
.typing-indicator span {
    width: 8px; height: 8px;
    background: var(--gray-300);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* === Chat Input === */
.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    background: white;
    flex-shrink: 0;
}

.chat-input-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 24px;
    font-size: 15px;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    line-height: 1.4;
}
.chat-input:focus { outline: none; border-color: var(--blue); }

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--blue);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    font-size: 18px;
}
.send-btn:hover { background: var(--blue-dark); }
.send-btn:disabled { background: var(--gray-300); cursor: not-allowed; }

/* === Admin Layout === */
.admin-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.admin-header h1 { font-size: 20px; display: flex; align-items: center; gap: 8px; }

.admin-nav { display: flex; gap: 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab {
    padding: 10px 20px;
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-weight: 600;
    color: var(--gray-500);
    transition: all 0.2s;
}
.tab.active { background: var(--blue); color: white; border-color: var(--blue); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
}
.card h2 { font-size: 18px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fef2f2; color: #991b1b; }
.badge-count {
    background: var(--red);
    color: white;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
}

/* Tabelle */
.msg-table { width: 100%; border-collapse: collapse; }
.msg-table th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--gray-200); font-size: 13px; color: var(--gray-500); text-transform: uppercase; }
.msg-table td { padding: 12px; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
.msg-table tr:hover { background: var(--gray-50); }
.msg-content { max-width: 400px; word-wrap: break-word; }
.msg-time { font-size: 13px; color: var(--gray-500); white-space: nowrap; }
.msg-actions { display: flex; gap: 6px; }

/* Conversation List */
.conv-list { list-style: none; }
.conv-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.2s;
}
.conv-item:hover { background: var(--gray-50); }
.conv-item-info h3 { font-size: 15px; margin-bottom: 2px; }
.conv-item-info p { font-size: 13px; color: var(--gray-500); }
.conv-item-meta { text-align: right; font-size: 13px; color: var(--gray-500); }

/* Settings Form */
.settings-group { margin-bottom: 20px; }
.settings-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.settings-group input, .settings-group textarea, .settings-group select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}
.settings-group input:focus, .settings-group textarea:focus { outline: none; border-color: var(--blue); }
.settings-group textarea { min-height: 100px; resize: vertical; }
.settings-group .hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* Chat Viewer im Admin */
.chat-viewer {
    max-height: 500px;
    overflow-y: auto;
    padding: 16px;
    background: var(--gray-50);
    border-radius: 8px;
}

/* Pending Alert */
.pending-alert {
    background: #fef3c7;
    border: 2px solid var(--orange);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.8; } }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--gray-500);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }

/* Responsive */
@media (max-width: 768px) {
    .admin-container { padding: 10px; }
    .admin-header { flex-direction: column; gap: 12px; }
    .tabs { overflow-x: auto; }
    .msg-table { font-size: 14px; }
    .msg-actions { flex-direction: column; }
    .chat-container { max-width: 100%; }
}

/* Memory Tags */
.memory-list { list-style: none; }
.memory-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    gap: 10px;
}
.memory-category {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--blue);
    background: var(--blue-light);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
}
.memory-content { flex: 1; font-size: 14px; }
.memory-delete { color: var(--red); cursor: pointer; background: none; border: none; font-size: 16px; }

/* === Sidebar === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
}
.sidebar-overlay.open { display: block; }

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    background: white;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}
.sidebar-header h2 { font-size: 18px; }
.sidebar-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--gray-500);
    cursor: pointer;
    line-height: 1;
}

.sidebar-new { margin: 12px 16px; width: calc(100% - 32px); }

.sidebar-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 0 0 20px;
}

.sidebar-item {
    padding: 12px 20px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}
.sidebar-item:hover { background: var(--gray-50); }
.sidebar-item.active {
    background: var(--blue-light);
    border-left-color: var(--blue);
}

.sidebar-item-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}
.sidebar-item-date { font-size: 12px; color: var(--gray-500); }

.sidebar-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--gray-500);
    font-size: 14px;
}

/* Sidebar Toggle Button */
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.15); }

/* === Bild-Button & Bildmodus === */
.img-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--gray-200);
    background: white;
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.img-btn:hover { border-color: var(--blue); background: var(--blue-light); }
.img-btn.active {
    background: var(--blue);
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-light);
}

.image-mode-hint {
    font-size: 13px;
    color: var(--blue);
    padding: 6px 0 0 54px;
}

/* Bilder im Chat */
.chat-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 12px;
    margin-top: 8px;
    cursor: pointer;
    transition: transform 0.2s;
    display: block;
}
.chat-image:hover { transform: scale(1.02); }

/* Bild-Overlay (Vollbild) */
.image-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 20px;
}
.image-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

/* === Upload-Vorschau === */
.upload-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--blue-light);
    border-radius: 12px;
    margin-bottom: 10px;
}

.upload-preview img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.upload-preview-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
}

.upload-preview-remove {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--red);
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}
.upload-preview-remove:hover { background: #fef2f2; }

.upload-preview-hint {
    font-size: 12px;
    color: var(--blue);
    margin-left: auto;
    font-style: italic;
}

/* Responsive Sidebar */
@media (max-width: 768px) {
    .sidebar { width: 85vw; max-width: 320px; }
    .upload-preview { flex-wrap: wrap; }
    .upload-preview-hint { margin-left: 0; width: 100%; }
}
