/**
 * Chatbase Modal Styles
 *
 * Styles für das Chatbase-Modal und die Chat-Bubble für TYPO3.
 *
 * @package    Chatbase
 * @subpackage CSS
 * @version    1.2.0
 */

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');

/* ==========================================================================
   Animated Border Custom Property (for loading animation)
   ========================================================================== */

@property --chatbase-border-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

/* ==========================================================================
   Modal Basis
   ========================================================================== */

.chatbase-modal {
    font-family: 'Roboto', sans-serif;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: none;
    place-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.chatbase-modal.is-visible {
    display: grid;
    opacity: 1;
    pointer-events: auto;
}

.chatbase-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1;
}

/* ==========================================================================
   Content Container (Viewport Height)
   ========================================================================== */

.chatbase-modal-content {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 800px;
    height: 100%;
    height: 100dvh;
    background: transparent;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Header
   ========================================================================== */

.chatbase-header {
    height: 60px;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 101;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-bottom: 15px;
}

.chatbase-header-title {
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    font-size: 1.1rem;
}

.chatbase-menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.chatbase-menu-toggle:hover {
    transform: scale(1.1);
}

.chatbase-header-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ==========================================================================
   Close Button (X)
   ========================================================================== */

.chatbase-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0.8;
}

.chatbase-close-btn:hover {
    transform: scale(1.1);
    opacity: 1;
}

/* ==========================================================================
   Dropdown Menu
   ========================================================================== */

.chatbase-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    width: 200px;
    display: none;
    overflow: hidden;
}

.chatbase-menu-dropdown.is-open {
    display: block;
}

.chatbase-menu-dropdown ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chatbase-menu-dropdown li {
    border-bottom: 1px solid #eee;
}

.chatbase-menu-dropdown li:last-child {
    border-bottom: none;
}

.chatbase-menu-dropdown a {
    display: block;
    padding: 12px 20px;
    color: #333;
    text-decoration: none;
    font-family: 'Roboto', sans-serif;
    font-size: 0.95rem;
    transition: background 0.1s;
}

.chatbase-menu-dropdown a:hover {
    background: #f5f5f5;
}

/* ==========================================================================
   Chat Container (Grid Layout)
   ========================================================================== */

.chatbase-chat-container {
    width: 100%;
    height: 90%;
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 100%;
    align-content: center;
    gap: 10px;
    transition: all 0.5s ease;
}

.chatbase-chat-container.has-messages {
    align-content: stretch;
}

/* ==========================================================================
   Messages Container (Scrollable Area)
   ========================================================================== */

.chatbase-messages {
    display: none;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    padding: 0;
    box-sizing: border-box;
    margin-bottom: 0;
    transition: flex-grow 0.5s ease;
}

.chatbase-messages.active {
    display: block;
    padding: 20px;
    margin-bottom: 10px;
}

/* ==========================================================================
   Individual Messages
   ========================================================================== */

.chatbase-message {
    font-family: 'Roboto', sans-serif;
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 8px;
    max-width: 80%;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
}

.chatbase-message.user {
    background-color: var(--chatbase-chat-color, #007bff);
    color: white;
    margin-left: auto;
}

.chatbase-message.assistant {
    background-color: #f1f1f1;
    color: #333;
    margin-right: auto;
}

.chatbase-message a {
    text-decoration: underline;
}

/* ==========================================================================
   Bottom Group (Input + Footer)
   ========================================================================== */

.chatbase-bottom-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chatbase-input-wrapper {
    width: 100%;
    position: relative;
    border-radius: 26px;
    background: #ffffff;
    border: 2px solid #e0e0e0;
    box-sizing: border-box;
    min-height: 52px;
    transition: height 0.1s ease, border-color 0.3s ease;
}

/* ==========================================================================
   Input-Wrapper: keine Animation während Loading
   ========================================================================== */

.chatbase-input-wrapper.is-loading {
    border: 2px solid #e0e0e0;
    background: #ffffff;
    animation: none;
}

.chatbase-modal textarea#chatbase-input {
    width: 100%;
    padding: 14px 90px 14px 20px;
    font-size: 1.1rem;
    border: none;
    background: transparent;
    outline: none;
    box-sizing: border-box;
    resize: none;
    overflow-y: hidden;
    line-height: 1.1rem;
    font-family: 'Roboto', sans-serif;
    display: block;
    height: 52px;
    color: #333;
}

.chatbase-mic {
    position: absolute;
    right: 55px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #666;
    transition: all 0.2s ease;
    border-radius: 50%;
}

.chatbase-mic:hover {
    background: #f0f0f0;
    color: var(--chatbase-main-color, #007bff);
}

.chatbase-mic.recording {
    color: #ff4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
    50% {
        opacity: 0.7;
        transform: translateY(-50%) scale(1.1);
    }
}

.chatbase-voice-toast {
    padding: 8px 14px;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
    border-radius: 8px;
    font-size: 0.82rem;
    text-align: center;
    animation: chatbase-toast-fade 4s ease forwards;
}

@keyframes chatbase-toast-fade {
    0%   { opacity: 0; transform: translateY(5px); }
    10%  { opacity: 1; transform: translateY(0); }
    80%  { opacity: 1; }
    100% { opacity: 0; }
}

.chatbase-submit {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--chatbase-main-color, #007bff);
}

.chatbase-footer {
    margin-top: 10px;
    text-align: center;
}

.chatbase-footer a {
    font-size: 12px;
    color: #ffffff;
    text-decoration: none;
}

/* ==========================================================================
   Chat Bubble (Floating Button)
   ========================================================================== */

.chatbase-bubble {
    position: fixed;
    width: 60px;
    height: 60px;
    background-color: var(--chatbase-main-color, #007bff);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 99998;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chatbase-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chatbase-bubble svg {
    width: 30px;
    height: 30px;
    fill: white;
}

/* ==========================================================================
   Loading Animation (Rotating Gradient Outline on "schreibt...")
   ========================================================================== */

@keyframes chatbase-border-spin {
    to {
        --chatbase-border-angle: 360deg;
    }
}

@keyframes chatbase-loader-pulse {
    0%, 100% {
        opacity: 0.6;
        filter: blur(0px);
    }
    50% {
        opacity: 1;
        filter: blur(1px);
    }
}

@keyframes chatbase-dot-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

@keyframes chatbase-dot-glow {
    0%, 100% {
        box-shadow: 0 0 0 rgba(0, 123, 255, 0);
    }
    30% {
        box-shadow: 0 0 8px rgba(0, 123, 255, 0.4);
    }
}

.chatbase-message.chatbase-loader {
    color: #888;
    font-style: normal;
    border: 3px solid transparent;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background:
        linear-gradient(#f8f8f8, #f8f8f8) padding-box,
        conic-gradient(
            from var(--chatbase-border-angle),
            var(--chatbase-main-color, #007bff),
            #a855f7,
            #ff0095,
            #ff8c00,
            #00ff99,
            var(--chatbase-main-color, #007bff)
        ) border-box;
    box-shadow: 0 0 12px 2px rgba(168, 85, 247, 0.2);
    animation: chatbase-border-spin 2s linear infinite, chatbase-loader-pulse 2s ease-in-out infinite;
}

.chatbase-loader-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 20px;
}

.chatbase-loader-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--chatbase-main-color, #007bff);
    animation: chatbase-dot-bounce 1.2s ease-in-out infinite, chatbase-dot-glow 1.2s ease-in-out infinite;
}

.chatbase-loader-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.chatbase-loader-dot:nth-child(3) {
    animation-delay: 0.3s;
}

.chatbase-loader-text {
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}

.chatbase-messages.loading-response {
    animation: none;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.chatbase-no-scroll {
    overflow: hidden !important;
}

/* ==========================================================================
   Navigation Links (Internal Links in Chat)
   ========================================================================== */

.chatbase-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    margin: 4px 0;
    background: #e8f0fe;
    background: color-mix(in srgb, var(--chatbase-main-color, #007bff) 10%, transparent);
    border: 1px solid var(--chatbase-main-color, #007bff);
    border-radius: 8px;
    color: var(--chatbase-main-color, #007bff) !important;
    text-decoration: none !important;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background 0.2s ease, transform 0.15s ease;
    cursor: pointer;
}

.chatbase-nav-link:hover {
    background: color-mix(in srgb, var(--chatbase-main-color, #007bff) 18%, transparent);
    transform: translateX(3px);
}

.chatbase-nav-link-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.chatbase-nav-link-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 250px;
}

/* ==========================================================================
   Navigation Toast
   ========================================================================== */

.chatbase-nav-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Roboto', sans-serif;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    z-index: 100000;
    animation: chatbase-nav-toast-in 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

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

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .chatbase-modal-content {
        max-width: 100%;
        padding: 5px;
    }

    .chatbase-header {
        height: 50px;
        padding: 0 15px;
    }

    .chatbase-message {
        max-width: 90%;
    }
}

/* ==========================================================================
   Accessibility: Focus Styles
   ========================================================================== */

.chatbase-bubble:focus-visible,
.chatbase-menu-toggle:focus-visible,
.chatbase-close-btn:focus-visible,
.chatbase-submit:focus-visible,
.chatbase-mic:focus-visible {
    outline: 2px solid var(--chatbase-main-color, #007bff);
    outline-offset: 2px;
}

.chatbase-modal textarea#chatbase-input:focus-visible {
    box-shadow: inset 0 0 0 2px var(--chatbase-main-color, #007bff);
    border-radius: 26px;
}

/* ==========================================================================
   Accessibility: Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .chatbase-modal {
        transition: none;
    }

    .chatbase-chat-container {
        transition: none;
    }

    .chatbase-messages {
        transition: none;
        scroll-behavior: auto;
    }

    .chatbase-bubble {
        transition: none;
    }

    .chatbase-bubble:hover {
        transform: none;
    }

    .chatbase-menu-toggle,
    .chatbase-close-btn,
    .chatbase-mic,
    .chatbase-nav-link {
        transition: none;
    }

    .chatbase-nav-link:hover {
        transform: none;
    }

    .chatbase-nav-toast {
        animation: none;
    }

    .chatbase-mic.recording {
        animation: none;
    }

    .chatbase-message.chatbase-loader {
        animation: none;
        border: 2px solid var(--chatbase-main-color, #007bff);
        background: #f8f8f8;
        box-shadow: none;
    }

    .chatbase-loader-dot {
        animation: none;
        opacity: 0.6;
    }

    @keyframes pulse {
        0%, 50%, 100% {
            opacity: 1;
            transform: translateY(-50%) scale(1);
        }
    }
}

/* ==========================================================================
   Contwise Cards
   ========================================================================== */

.contwise-card {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    margin: 8px 0;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.contwise-card--empty {
    padding: 16px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
}

/* Card Image */
.contwise-card-image {
    position: relative;
    overflow: hidden;
    max-height: 180px;
}

.contwise-card-image img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
}

/* Map */
.contwise-card-map {
    border-top: 1px solid #f0f0f0;
    overflow: hidden;
    max-height: 120px;
}

.contwise-card-map img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

/* Status Badge */
.contwise-card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.contwise-badge--open { background: #16a34a; }
.contwise-badge--partial { background: #d97706; }
.contwise-badge--closed { background: #dc2626; }

/* Inline Badge (for lists) */
.contwise-card-badge-inline {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Card Body */
.contwise-card-body {
    padding: 12px 14px;
}

.contwise-card-title {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.3;
}

.contwise-card-teaser {
    margin: 0 0 8px 0;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Metadata Row */
.contwise-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.contwise-meta-item {
    display: inline-block;
    padding: 2px 8px;
    background: #f3f4f6;
    border-radius: 12px;
    font-size: 11px;
    color: #374151;
    white-space: nowrap;
}

/* Detail Link */
.contwise-card-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: var(--chatbase-main-color, #007bff);
    color: #fff !important;
    font-size: 12px;
    font-weight: 500;
    border-radius: 8px;
    text-decoration: none !important;
    transition: opacity 0.2s;
}

.contwise-card-link:hover {
    opacity: 0.85;
}

.contwise-card-link-small {
    font-size: 11px;
    color: var(--chatbase-main-color, #007bff);
    text-decoration: none;
    font-weight: 500;
}

.contwise-card-link-small:hover {
    text-decoration: underline;
}

/* Compact Card (Search Results) */
.contwise-card-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 8px 0;
}

.contwise-card--compact {
    margin: 0;
}

.contwise-card--compact .contwise-card-body {
    padding: 10px 12px;
}

.contwise-card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.contwise-card-header-row .contwise-card-title {
    margin: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Closures Card */
.contwise-card--closures {
    border-color: #fbbf24;
    background: #fffbeb;
}

.contwise-closures-title {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #92400e;
}

.contwise-closures-none {
    margin: 0;
    font-size: 13px;
    color: #6b7280;
}

.contwise-closures-list {
    list-style: none;
    margin: 8px 0 0 0;
    padding: 0;
}

.contwise-closure-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #fde68a;
    font-size: 12px;
}

.contwise-closure-item:last-child {
    border-bottom: none;
}

.contwise-closure-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #374151;
}

/* Skeleton Loading */
.contwise-card-placeholder {
    margin: 8px 0;
}

.contwise-card-skeleton {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.contwise-skeleton-image {
    height: 120px;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: contwise-shimmer 1.5s infinite;
}

.contwise-skeleton-lines {
    padding: 12px 14px;
}

.contwise-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: contwise-shimmer 1.5s infinite;
    margin-bottom: 8px;
}

.contwise-skeleton-line.short {
    width: 60%;
}

@keyframes contwise-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Responsive */
@media (max-width: 480px) {
    .contwise-card-image img {
        height: 140px;
    }

    .contwise-card-map img {
        height: 100px;
    }

    .contwise-card-meta {
        gap: 4px;
    }

    .contwise-meta-item {
        font-size: 10px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .contwise-skeleton-image,
    .contwise-skeleton-line {
        animation: none;
        background: #e5e7eb;
    }
}

/* ==========================================================================
   Webcam Cards
   ========================================================================== */

.webcam-card {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    margin: 8px 0;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.webcam-card--empty {
    padding: 16px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
}

.webcam-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #1e293b;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.webcam-card-icon {
    flex-shrink: 0;
}

.webcam-card-item {
    border-top: 1px solid #f0f0f0;
}

.webcam-card-item:first-of-type {
    border-top: none;
}

.webcam-card-image {
    overflow: hidden;
    max-height: 200px;
}

.webcam-card-image img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.webcam-card-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.03);
}

.webcam-card-name {
    font-size: 13px;
    font-weight: 500;
    color: #1f2937;
}

.webcam-card-ort {
    font-size: 11px;
    color: #6b7280;
    padding: 2px 8px;
    background: #f3f4f6;
    border-radius: 12px;
}

.webcam-card-more {
    padding: 8px 14px;
    font-size: 12px;
    color: #6b7280;
    text-align: center;
    border-top: 1px solid #f0f0f0;
}

.webcam-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.webcam-card-update {
    font-size: 11px;
    color: #9ca3af;
}

.webcam-card-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--chatbase-main-color, #007bff);
    text-decoration: none;
    font-weight: 500;
}

.webcam-card-link:hover {
    text-decoration: underline;
}

/* Webcam Responsive */
@media (max-width: 480px) {
    .webcam-card-image img {
        height: 160px;
    }
}
