/* =========================================================
   Elterngeld-Chatbot – Stylesheet
   Mobile-First, anpassbar per CSS-Variable --mandant-farbe
   ========================================================= */

:root {
    --mandant-farbe: #FFFC00;          /* Standard: BW Gelb */
    --mandant-farbe-hell: #FFFDE8;
    --mandant-farbe-dunkel: #2A2623;
    --mandant-text-farbe: #2A2623;     /* Textfarbe auf farbigem Header */

    --bg-page: #f0f2f5;
    --bg-header: var(--mandant-farbe);
    --bg-chat: #ffffff;
    --bg-user-msg: #0B5CFF;
    --bg-agent-msg: #ffffff;
    --bg-input: #ffffff;

    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-user-msg: #ffffff;
    --text-agent-msg: #1a1a2e;
    --text-header: var(--mandant-text-farbe);

    --border-color: #e5e7eb;
    --border-radius-sm: 4px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --border-radius-pill: 50px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.18);

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;

    --transition: 0.2s ease;
    --header-height: 64px;
    --status-bar-height: 32px;
}

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

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    background: var(--bg-page);
    overflow: hidden;
}

/* ── Header ── */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: var(--bg-header);
    color: var(--text-header);
    z-index: 100;
    box-shadow: var(--shadow-md);
    transition: background var(--transition);
}

.header-content {
    height: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header-logo h1 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    line-height: 1.2;
}

.header-subtitle {
    font-size: var(--font-size-xs);
    opacity: 0.85;
    display: block;
}

/* ── Mandanten-Navigation ── */
.mandant-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.mandant-btn {
    padding: 5px 10px;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: var(--border-radius-pill);
    background: transparent;
    color: white;
    font-size: var(--font-size-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.mandant-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: white;
}

.mandant-btn.active {
    background: white;
    color: var(--btn-color, var(--mandant-farbe));
    border-color: white;
}

.reset-btn {
    padding: 5px 10px;
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: var(--border-radius-pill);
    background: rgba(0,0,0,0.2);
    color: rgba(255,255,255,0.85);
    font-size: var(--font-size-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    margin-left: 8px;
}

.reset-btn:hover {
    background: rgba(0,0,0,0.4);
    border-color: white;
    color: white;
}

/* ── Main Layout ── */
.app-main {
    position: fixed;
    top: var(--header-height);
    bottom: var(--status-bar-height);
    left: 0; right: 0;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

.chat-section {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
}

/* ── Nachrichten ── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* Willkommensnachricht */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    margin-bottom: 12px;
    display: flex;
    justify-content: center;
    color: var(--mandant-farbe-dunkel);
}

.welcome-message h2 {
    font-size: var(--font-size-lg);
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-message p {
    margin-bottom: 20px;
    font-size: var(--font-size-sm);
}

.start-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: var(--mandant-farbe-dunkel);
    color: #ffffff;
    border: none;
    border-radius: var(--border-radius-pill);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.start-btn:hover {
    opacity: 0.85;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* Nachrichten-Zeilen */
.message {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    max-width: 85%;
    animation: fadeInUp 0.2s ease;
}

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

.user-message {
    flex-direction: row-reverse;
    margin-left: auto;
}

.agent-message {
    flex-direction: row;
    margin-right: auto;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    align-self: flex-end;
    background: var(--mandant-farbe-hell);
}

.user-message .message-avatar {
    background: var(--bg-user-msg);
}

.message-content {
    padding: 10px 14px;
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-sm);
    line-height: 1.6;
    word-wrap: break-word;
    max-width: 100%;
}

.user-message .message-content {
    background: var(--bg-user-msg);
    color: var(--text-user-msg);
    border-bottom-right-radius: var(--border-radius-sm);
}

.agent-message .message-content {
    background: var(--bg-agent-msg);
    color: var(--text-agent-msg);
    border-bottom-left-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

/* Markdown in Agent-Nachrichten */
.message-content strong { font-weight: 700; }
.message-content em { font-style: italic; }
.message-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'Courier New', monospace;
}
.message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: var(--border-radius-md);
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.85em;
}
.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.message-content ul, .message-content ol {
    margin: 6px 0 6px 20px;
}
.message-content li { margin: 3px 0; }
.message-content h1, .message-content h2, .message-content h3 {
    margin: 10px 0 6px;
    color: var(--mandant-farbe-dunkel);
}
.message-content h1 { font-size: 1.2em; }
.message-content h2 { font-size: 1.1em; }
.message-content h3 { font-size: 1em; }
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: var(--font-size-xs);
}
.message-content th {
    background: var(--mandant-farbe-hell);
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    border: 1px solid var(--border-color);
}
.message-content td {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
}
.message-content tr:nth-child(even) td { background: #f9fafb; }
.message-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 10px 0;
}
.message-content blockquote {
    border-left: 3px solid var(--mandant-farbe);
    padding-left: 10px;
    color: var(--text-secondary);
    font-style: italic;
    margin: 8px 0;
}

/* Tipp-Indikator */
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ── Eingabebereich ── */
.input-area {
    padding: 8px 12px 12px;
    background: var(--bg-input);
    border-top: 1px solid var(--border-color);
}

/* Upload-Zone */
.upload-section {
    margin-bottom: 8px;
}

.upload-zone {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    background: #fafafa;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--mandant-farbe);
    background: var(--mandant-farbe-hell);
    color: var(--mandant-farbe-dunkel);
}

.upload-icon { display: flex; color: var(--mandant-farbe-dunkel); }

/* Upload-Queue */
.upload-queue {
    background: var(--mandant-farbe-hell);
    border: 1px solid var(--mandant-farbe);
    border-radius: var(--border-radius-md);
    padding: 8px 10px;
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: var(--font-size-sm);
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    min-height: 36px;
}

.queue-item-icon { flex-shrink: 0; }

.queue-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--font-size-xs);
    color: var(--text-primary);
    min-width: 0;
}

.queue-item-type {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.type-detected {
    font-size: var(--font-size-xs);
    color: var(--mandant-farbe-dunkel);
    font-weight: 600;
    white-space: nowrap;
}

.type-select {
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: white;
    font-size: var(--font-size-xs);
    cursor: pointer;
}

.queue-month-input {
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: white;
    font-size: var(--font-size-xs);
    width: 120px;
}

.queue-status-icon {
    font-size: 0.85rem;
    font-weight: 600;
    width: 18px;
    text-align: center;
}
.queue-status-icon.done     { color: #10b981; }
.queue-status-icon.error    { color: #ef4444; }
.queue-status-icon.uploading { color: var(--text-secondary); }

/* Datei-Badge-Indikatoren */
.badge-ok       { color: #10b981; font-weight: 600; }
.badge-fehler   { color: #ef4444; font-weight: 600; }
.badge-warnung  { color: #f59e0b; font-weight: 600; }
.badge-hochgeladen, .badge-default { color: var(--text-secondary); }

/* SVG in message-avatar */
.message-avatar svg { display: block; }
.agent-message .message-avatar svg { stroke: var(--mandant-farbe-dunkel); }
.user-message .message-avatar svg   { stroke: #ffffff; }

.queue-item-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 4px;
    border-radius: 3px;
    flex-shrink: 0;
    line-height: 1;
}
.queue-item-remove:hover { background: #fee2e2; color: #ef4444; }

.queue-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 2px;
}

.btn-upload-all {
    padding: 7px 18px;
    background: var(--mandant-farbe);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: var(--font-size-sm);
    transition: background var(--transition);
}
.btn-upload-all:hover { background: var(--mandant-farbe-dunkel); }

/* Hochgeladene Dokumente */
.uploaded-files {
    margin-bottom: 8px;
}

.uploaded-title {
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.file-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-pill);
    font-size: var(--font-size-xs);
    transition: all var(--transition);
}

.file-item.status-ok {
    border-color: #10b981;
    background: #ecfdf5;
    color: #065f46;
}
.file-item.status-fehler {
    border-color: #ef4444;
    background: #fef2f2;
    color: #991b1b;
}
.file-item.status-warnung {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #92400e;
}
.file-item.status-hochgeladen {
    border-color: #6366f1;
    background: #eef2ff;
    color: #3730a3;
}

.file-badge {
    font-size: 0.9rem;
}

/* Texteingabe */
.text-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.message-textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    font-size: var(--font-size-md);
    font-family: var(--font-family);
    resize: none;
    outline: none;
    transition: border-color var(--transition);
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    background: white;
}

.message-textarea:focus {
    border-color: var(--mandant-farbe);
    box-shadow: 0 0 0 3px rgba(0, 146, 70, 0.1);
}

.message-textarea::placeholder {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--mandant-farbe);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.send-btn:hover:not(:disabled) {
    background: var(--mandant-farbe-dunkel);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    box-shadow: none;
}

/* ── Bund-ID Link ── */
.bund-id-link {
    display: inline-block;
    background: #003399;
    color: white !important;
    padding: 10px 20px;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    text-decoration: none;
    margin: 8px 0;
    transition: background var(--transition);
}
.bund-id-link:hover {
    background: #002277;
}

/* ── Status-Bar ── */
.status-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--status-bar-height);
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    z-index: 100;
}

#status-text {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── Error Toast ── */
.toast {
    position: fixed;
    bottom: calc(var(--status-bar-height) + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 10px 20px;
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-sm);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .header-logo h1 { font-size: 1rem; }
    .mandant-btn { font-size: 0.7rem; padding: 4px 8px; }
    .mandant-flag { display: none; }
    .message { max-width: 92%; }
    .chat-section { border: none; }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-page: #0f172a;
        --bg-chat: #1e293b;
        --bg-input: #1e293b;
        --bg-agent-msg: #273548;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
    }
    .message-textarea { background: #273548; color: #f1f5f9; }
    .upload-zone { background: #273548; }
    .messages-container::-webkit-scrollbar-thumb { background: #334155; }
}
