/* Frontend chat styles */

/* === Wrapper (Position determined by classes) === */
.chat-wrapper {
    display: flex;
    flex-direction: column; /* Stack container and toggle button */
    position: fixed;        /* Fixed position on screen */
    z-index: 999999;      /* High stack order */
    pointer-events: none;   /* Allow clicks through the wrapper */
}

/* Enable pointer events for direct children (button, container) */
.chat-wrapper > * {
    pointer-events: auto;
}

/* === Wrapper Position Classes (Applied by JS) === */
.chat-wrapper.pos-bottom-right { bottom: 2rem; right: 2rem; }
.chat-wrapper.pos-bottom-left { bottom: 2rem; left: 2rem; }
.chat-wrapper.pos-top-right { top: 2rem; right: 2rem; }
.chat-wrapper.pos-top-left { top: 2rem; left: 2rem; }

/* === Chat window Base Styles === */
#chat-container {
    /* Position and margin are now set based on wrapper class below */
    /* Size (width, height) are primarily set by JS inline styles */
    min-width: 300px;    /* Minimum width */

    /* Base appearance */
    display: flex;
    flex-direction: column;
    background: white; /* Will be overridden by inline style if set */
    border: .1rem solid #ccc;
    border-radius: 10px; /* Main container radius */
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    overflow: hidden; /* Contains content like chat body AND clips children to border-radius */

    /* Visibility & Animation */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, visibility 0s linear 0.3s;
    /* Initial transform set based on position below */
}

/* === Chat Window Positioning & Opening Animation (Relative to Wrapper) === */
.chat-wrapper.pos-bottom-right #chat-container,
.chat-wrapper.pos-bottom-left #chat-container {
    position: absolute;
    bottom: 100%;           /* Place above the toggle button */
    margin-bottom: 10px;    /* Space between button and window */
    transform: translateY(10px); /* Start slightly below final position for animation */
}
.chat-wrapper.pos-top-right #chat-container,
.chat-wrapper.pos-top-left #chat-container {
    position: absolute;
    top: 100%;              /* Place below the toggle button */
    margin-top: 10px;       /* Space between button and window */
    transform: translateY(-10px);/* Start slightly above final position for animation */
}
/* Horizontal Alignment */
.chat-wrapper.pos-bottom-right #chat-container,
.chat-wrapper.pos-top-right #chat-container { right: 0; left: auto; }
.chat-wrapper.pos-bottom-left #chat-container,
.chat-wrapper.pos-top-left #chat-container { left: 0; right: auto; }
/* Open State - Common */
#chat-container.open {
    opacity: 1;
    transform: translateY(0); /* Final animation position */
    visibility: visible;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out; /* Remove visibility delay */
}

/* === Chat Window Inner Elements === */
#chat-header {
    padding: 0.8rem 1rem;
    font-weight: bold;
    cursor: grab; /* Default cursor when dragging is allowed */
    flex-shrink: 0;
    display: flex; /* Added for positioning title and close button */
    justify-content: space-between; /* Added */
    align-items: center; /* Added */
    /* background-color, color set by JS */
}
#chat-header:active { cursor: grabbing; }

#chat-header-title { /* Added to allow title to take available space */
    flex-grow: 1;
}

#chat-close-btn {
    font-size: 1.5em; /* Adjust size as needed */
    font-weight: bold;
    line-height: 1;
    padding: 0.2em 0.4em;
    cursor: pointer;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    margin-left: 10px; /* Space from title if title is long */
}
#chat-close-btn:hover {
    background-color: rgba(0,0,0,0.1); /* Subtle hover effect, adapt to header color */
}


#chat-body {
    min-height: 200px; flex-grow: 1; overflow-y: auto;
    background: #ffffff; /* Default background, overridden by inline style if set */
    padding: .8rem; line-height: 1.5;
    /* font-size will be overridden by inline style if set */
}
#chat-body p { margin: 0.5em 0; word-wrap: break-word; }
#chat-body p strong { margin-right: 5px; }

/* Classes for message colors (colors come from inline CSS) */
.chat-message { /* Base class for all messages */ }
.user-message { /* Specific class for user messages */ }
.ai-message { /* Specific class for AI messages */ }
.error-message { color: #dc3232; font-style: italic; } /* Error messages remain red */

/* Prompt Suggestions Area */
#chat-prompt-suggestions {
    padding: 8px 10px 5px 10px;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
    display: flex; /* Should be set by JS when prompts are available */
    flex-direction: row;
    flex-wrap: nowrap;   /* Verhindert, dass die Buttons in die nächste Zeile umbrechen */
    overflow-x: auto;  /* Ermöglicht horizontales Scrollen */
    overflow-y: hidden;/* Verhindert vertikales Scrollen für den Container selbst */
    gap: 8px;
    background-color: #f9f9f9; /* Fallback, kann durch Inline-Style überschrieben werden */
    height: 50px; /* Angepasste feste Höhe für eine Zeile */
    box-sizing: border-box;
    flex-shrink: 0;
    align-items: center; /* Vertikale Zentrierung der Prompt-Buttons */
}
button.prompt-suggestion {
    /* background-color and color are now set via inline styles from backend */
    border: 1px solid #ccc;
    border-radius: 15px;
    padding: 4px 10px;
    /* font-size is now set via inline styles from backend */
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease; /* Transition für Farbe hinzugefügt */
    white-space: nowrap;
    line-height: 1.4;
}
button.prompt-suggestion:hover {
    /* background-color and color for hover are now set via inline styles from backend */
    border-color: #bbb; /* Kann beibehalten oder auch konfigurierbar gemacht werden */
}
button.prompt-suggestion:active {
    background-color: #cfcfcf; /* Kann beibehalten oder auch konfigurierbar gemacht werden */
}

/* NEW: Confirmation Buttons Container */
.chat-confirmation-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    border-top: 1px solid #eee;
    justify-content: flex-start; /* Aligns buttons to the start */
    background-color: #f9f9f9;
}
.chat-confirmation-buttons button {
    flex-grow: 0; /* Prevents buttons from growing to fill space */
    flex-shrink: 0; /* Prevents buttons from shrinking excessively */
    /* Inherit prompt-suggestion styles */
}
.chat-confirmation-buttons button.confirm-yes {
    background-color: #4CAF50; /* Green for Yes */
    color: white;
    border-color: #4CAF50;
}
.chat-confirmation-buttons button.confirm-yes:hover {
    background-color: #45a049;
    border-color: #45a049;
}
.chat-confirmation-buttons button.confirm-no {
    background-color: #f44336; /* Red for No */
    color: white;
    border-color: #f44336;
}
.chat-confirmation-buttons button.confirm-no:hover {
    background-color: #da190b;
    border-color: #da190b;
}


/* Input Container */
#chat-input-container {
    background: #f1f1f1; padding: 0.5rem 0.8rem; border-top: 1px solid #ddd;
    flex-shrink: 0;
}
#chat-options {
    display: flex; justify-content: flex-end; margin-bottom: 5px;
}
#chat-options span#voice-output {
    font-size: 16px; color: #555; padding: 5px; border-radius: 50%;
    background: transparent; cursor: pointer; transition: background-color 0.2s, color 0.2s;
}
#chat-options span#voice-output:hover { background-color: #eee; }
#chat-options span#voice-output.fa-volume-up { color: #0073e6; }
#chat-options span#voice-output.fa-volume-off { color: #555; }

/* Message input Form */
form#chat-form { display: flex; align-items: stretch; gap: 8px; }
textarea#chat-input {
    flex-grow: 1; border: 1px solid #ccc; border-radius: 5px; padding: 0.5rem 0.8rem;
    font-size: 1em; /* Fallback font-size, actual is overridden by inline style if set */
    resize: none; min-height: 40px;
    max-height: 100px; line-height: 1.4; font-family: inherit; box-sizing: border-box;
}
#send-btn {
    border-radius: 5px; border: none; padding: 0.5rem 1rem; font-size: 1em;
    cursor: pointer; transition: background-color 0.2s ease, opacity 0.2s ease;
    flex-shrink: 0; align-self: center;
}
#send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* === Chat toggle button (Common styles) === */
#chat-toggle {
    display: flex; align-items: center; justify-content: center; align-self: flex-end;
    border: none; padding: 0.7rem 1.2rem; font-size: 1em; cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
#chat-toggle:hover { box-shadow: 0 4px 8px rgba(0,0,0,0.2); }

/* --- Default Toggle Button Style Classes (Frontend) --- */
#chat-toggle.t-text { border-radius: 5px; }
#chat-toggle.t-text span { margin-right: 8px; font-size: 1.1em; line-height: 1; }
#chat-toggle.t-icon { width: 50px; height: 50px; border-radius: 50%; padding: 0; font-size: 1.3em; line-height: 1; }

/* --- Custom Icon Toggle Button Style (Frontend) --- */
#chat-toggle.custom-icon-toggle {
    width: 55px; height: 55px; border-radius: 50%; padding: 0; overflow: hidden; background-color: transparent;
}
#chat-toggle.custom-icon-toggle img {
    display: block; max-width: 70%; max-height: 70%; object-fit: contain; border-radius: 0;
}
#chat-toggle.custom-icon-toggle:hover img { opacity: 0.85; }

/* === Cursor for non-draggable window === */
#chat-container.chat-window-non-draggable #chat-header {
    cursor: default; /* Standard arrow cursor when dragging is disabled */
}
#chat-container.chat-window-non-draggable #chat-close-btn { /* Ensure close button is still usable */
    cursor: pointer;
}


/* ============================================ */
/* === Admin Appearance Settings - Icon List CSS === */
/* ============================================ */
.ai-chat-icon-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 4px; max-height: 200px; overflow-y: auto; }
.ai-chat-icon-option { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; padding: 5px; border: 2px solid transparent; border-radius: 4px; transition: background-color 0.2s, border-color 0.2s; position: relative; background-color: #fff; min-width: 60px; box-sizing: border-box; text-align: center; }
.ai-chat-icon-option:has(input[type="radio"]:checked) { border-color: #2271b1; background-color: #f0f6fc; }
.ai-chat-icon-option:hover { background-color: #f0f0f0; border-color: #ccc; }
.ai-chat-icon-option input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.ai-chat-icon-option img { max-width: 32px; max-height: 32px; border: 1px solid #eee; display: block; object-fit: contain; }
.ai-chat-icon-option span { font-size: 0.8em; color: #555; word-break: break-all; max-width: 55px; line-height: 1.2; }
label:has(input.ai-chat-icon-type-selector) { font-weight: bold; display: block; margin-bottom: 5px; }

/* === General Admin Styles === */
.ai-chat-settings-wrap .form-table th { width: 200px; }
.ai-chat-settings-wrap .ai-chat-error { color: #dc3232; font-weight: bold; border-left: 3px solid #dc3232; padding-left: 8px; margin: 5px 0; }
.ai-chat-settings-wrap .ai-chat-warning { color: #d63638; border-left: 3px solid #d63638; padding-left: 8px; margin: 5px 0; }
.ai-chat-settings-wrap .ai-chat-code-box { background: #f7f7f7; padding: 15px; border: 1px solid #ccc; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word; font-family: monospace; font-size: 0.9em; margin-top: 10px; }
.ai-chat-settings-wrap #ai-chat-preview-output { border: 1px solid #ddd; background-color: #fff; min-height: 100px; max-height: 250px; overflow-y: auto; padding: 10px; margin-bottom: 10px; font-size: 0.9em; line-height: 1.5; }
.ai-chat-settings-wrap #ai-chat-preview-input { width: 100%; margin-bottom: 10px; box-sizing: border-box; }
.ai-chat-settings-wrap .ai-chat-preview-controls { display: flex; gap: 10px; align-items: center; }

/* === Styling für die Lade-Nachricht (Frontend) === */
.ai-chat-loading { opacity: 0.7; font-style: italic; display: inline-block; }
.ai-chat-loading .thinking { display: inline-block; margin-left: 4px; }
.ai-chat-loading .thinking::after { display: inline-block; overflow: hidden; vertical-align: bottom; animation: dots 1.4s linear infinite; content: '.'; width: 0.3em; text-align: left; box-sizing: content-box; }
@keyframes dots { 0%, 20% { content: '.'; width: 0.3em; } 40% { content: '..'; width: 0.6em; } 60%, 80%, 100% { content: '...'; width: 0.9em; } }

/* === Footer Banner Styling === */
#chat-footer-banner {
    padding: 6px 12px;
    font-size: 0.8em;
    line-height: 1.4;
    text-align: center;
    /* color and background-color are now set via inline styles from backend */
    border-top: 1px solid #e5e5e5;
    flex-shrink: 0;
}

#chat-footer-banner a {
    /* color is now set via inline styles from backend (applies to #chat-footer-banner a as well) */
    text-decoration: none;
}
#chat-footer-banner a:hover {
    text-decoration: underline;
}

/* === SPRACHAUSWAHL: Custom Dropdown mit Flaggen === */
#chat-language-dropdown {
    position: relative; /* Wichtig für die Positionierung der Liste */
    display: inline-block;
    margin-left: auto; /* Schiebt es nach rechts im Flex-Container */
    margin-right: 10px; /* Abstand zum Schließen-Button */
    z-index: 1000; /* Sicherstellen, dass es über anderen Elementen liegt */
}

/* NEU: Anpassung für den Fall, dass nur Flaggen im Header-Button angezeigt werden sollen */
#chat-language-dropdown.flags-only-mode .selected-language-display {
    padding: 5px; /* Kompakteres Padding */
    justify-content: center; /* Flagge zentrieren */
}

#chat-language-dropdown.flags-only-mode .selected-language-display img {
    margin-right: 0; /* Kein rechter Rand neben der Flagge */
}

#chat-language-dropdown.flags-only-mode .selected-language-display span {
    display: none; /* Ländernamen ausblenden */
}


.selected-language-display {
    display: flex;
    align-items: center;
    padding: 5px 8px;
    border-radius: 5px;
    cursor: pointer;
    background-color: rgba(255, 255, 255, 0.2); /* Leichter Hintergrund, passt sich Header an */
    transition: background-color 0.2s ease;
    color: inherit; /* Textfarbe vom Header erben */
}

.selected-language-display:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.selected-language-display img {
    width: 24px; /* Größe der Flagge im Dropdown-Button */
    height: 16px; /* 3:2 Seitenverhältnis für Flaggen */
    object-fit: cover;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 2px;
    margin-right: 8px;
}

.dropdown-arrow {
    font-size: 0.8em;
    margin-left: 5px;
}

/* Anpassung des Dropdown-Pfeil-Rands im Flaggen-Modus */
#chat-language-dropdown.flags-only-mode .dropdown-arrow {
    margin-left: 5px; /* Kleinen Rand für den Pfeil beibehalten */
}


.language-options-list {
    display: none; /* Standardmäßig versteckt */
    position: absolute;
    top: 100%; /* Unter dem ausgewählten Element */
    right: 0; /* Rechtsbündig zum Button */
    background-color: #fff; /* Hintergrund der Dropdown-Liste */
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    min-width: 150px; /* Mindestbreite der Liste */
    padding: 5px 0;
    margin-top: 5px; /* Abstand zum Button */
    max-height: 200px; /* Maximale Höhe, um Scrollen zu ermöglichen */
    overflow-y: auto;
}

/* NEU: Anpassung der Dropdown-Liste selbst im Flaggen-Modus */
#chat-language-dropdown.flags-only-mode .language-options-list {
    min-width: unset; /* Minimale Breite aufheben */
    width: auto; /* Breite automatisch an Inhalt anpassen */
}

.language-options-list.active {
    display: block; /* Anzeigen, wenn aktiv */
}

.language-option-item {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    cursor: pointer;
    color: #333; /* Textfarbe der Optionen */
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* NEU: Anpassung für einzelne Listenpunkte im Flaggen-Modus */
.language-option-item.flags-only-mode {
    padding: 5px 8px; /* Kompakteres Padding */
    justify-content: center; /* Flagge zentrieren */
}

.language-option-item:hover {
    background-color: #f0f0f0; /* Hintergrund bei Hover */
    color: #000;
}

.language-option-item img {
    width: 24px; /* Größe der Flaggen in der Liste */
    height: 16px;
    object-fit: cover;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 2px;
    margin-right: 10px;
}

/* NEU: Ländernamen in den Listenpunkten ausblenden */
.language-option-item.flags-only-mode span {
    display: none;
}


/* === NEW: Form Modal Styles === */
.ai-chat-modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1000000; /* High z-index to be on top of everything */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    justify-content: center; /* Center content horizontally */
    align-items: center; /* Center content vertically */
}

.ai-chat-modal.active {
    display: flex; /* Show when active */
}

.ai-chat-modal-content {
    background-color: #fefefe;
    margin: auto; /* Centered */
    padding: 20px;
    border: 1px solid #888;
    width: 90%; /* Adjust width as needed */
    max-width: 500px; /* Max width for larger screens */
    border-radius: 10px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 90vh; /* Max height to allow scrolling for long forms */
    overflow-y: auto; /* Enable scrolling within modal content */
}

.ai-chat-modal-close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 15px;
    cursor: pointer;
}

.ai-chat-modal-close-btn:hover,
.ai-chat-modal-close-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#ai-chat-modal-title {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.5em;
    color: #333;
}

#ai-chat-modal-body {
    flex-grow: 1; /* Allows body to take available space */
    padding-bottom: 15px; /* Space above footer */
    /* Basic styling for form elements within the modal */
}

#ai-chat-modal-body input[type="text"],
#ai-chat-modal-body input[type="email"],
#ai-chat-modal-body input[type="number"],
#ai-chat-modal-body textarea,
#ai-chat-modal-body select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box; /* Include padding in width */
}

#ai-chat-modal-body label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.ai-chat-modal-footer {
    border-top: 1px solid #eee;
    padding-top: 15px;
    text-align: right; /* Align submit button to the right */
}

#ai-chat-modal-submit-btn {
    /* Styles are handled by WordPress .button.button-primary */
}

.ai-chat-modal-message {
    margin-top: 10px;
    text-align: center;
    font-weight: bold;
}
.ai-chat-modal-message.success {
    color: green;
}
.ai-chat-modal-message.error {
    color: red;
}
/* "AI:" ausblenden */
#ai-loading-indicator > strong {
  display: none !important;
}

/* Lade-Text ausblenden */
#ai-loading-indicator .thinking {
  font-size: 0 !important;
  line-height: 0 !important;
  letter-spacing: 0 !important;
}

/* Kreisel statt Punkte (überschreibt die dots-Animation) */
#ai-loading-indicator .thinking::after {
  content: '' !important;               /* Punkte entfernen */
  display: inline-block;
  width: 20px;                          /* Größe des Kreisels */
  height: 20px;
  margin-left: 6px;
  box-sizing: border-box;
  border: 2px solid currentColor;       /* Kreisel-Ring */
  border-right-color: transparent;      /* "Lücke" für Dreheffekt */
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite !important; /* statt dots */
  vertical-align: middle;
}

/* Dreh-Animation für den Kreisel */
@keyframes ai-spin {
  to { transform: rotate(360deg); }
}