/* GEOBEK Global Floating Assistant Styles */

:root {
    --geobek-primary: #10b981;
    --geobek-secondary: #059669;
    --geobek-accent: #8b5cf6;
    --geobek-bg: rgba(255, 255, 255, 0.95); /* Light glassmorphism */
    --geobek-glass: rgba(0, 0, 0, 0.05); /* Soft transparent dark for light mode bubbles/inputs */
    --geobek-border: rgba(0, 0, 0, 0.1);
    --geobek-text: #0f172a;
    --geobek-muted: #64748b;
    --geobek-surface: rgba(255, 255, 255, 0.72);
    --geobek-control: rgba(15, 23, 42, 0.055);
    --geobek-shadow: 0 24px 70px rgba(15, 23, 42, 0.18), 0 6px 20px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
    --geobek-bg: rgba(15, 23, 42, 0.85); /* Slightly transparent dark */
    --geobek-glass: rgba(255, 255, 255, 0.08);
    --geobek-border: rgba(255, 255, 255, 0.15);
    --geobek-text: #f8fafc;
    --geobek-muted: #cbd5e1;
    --geobek-surface: rgba(30, 41, 59, 0.72);
    --geobek-control: rgba(255, 255, 255, 0.065);
    --geobek-shadow: 0 28px 80px rgba(2, 6, 23, 0.58), 0 8px 24px rgba(2, 6, 23, 0.32);
}

/* Launcher Button */
.geobek-launcher {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--geobek-primary) 0%, var(--geobek-secondary) 100%);
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4), var(--geobek-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    z-index: 10000;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    border: 2px solid var(--geobek-border);
    padding: 0;
    appearance: none;
    touch-action: none;
}

.geobek-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(16, 185, 129, 0.6), var(--geobek-shadow);
}

.geobek-launcher:active {
    cursor: grabbing;
}

.geobek-launcher i {
    color: white;
    font-size: 28px;
    pointer-events: none;
}

/* Pulse animation for the launcher */
.geobek-launcher::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--geobek-primary);
    opacity: 0.2;
    z-index: -1;
    animation: geobek-pulse 2s infinite;
}

@keyframes geobek-pulse {
    0% { transform: scale(1); opacity: 0.4; }
    70% { transform: scale(1.4); opacity: 0; }
    100% { transform: scale(1.4); opacity: 0; }
}

/* Chat Panel */
.geobek-panel {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 420px;
    height: 620px;
    max-height: calc(100vh - 150px);
    background: var(--geobek-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--geobek-border);
    border-radius: 22px;
    box-shadow: var(--geobek-shadow);
    display: flex;
    flex-direction: column;
    z-index: 20000;
    overflow: hidden;
    transform: scale(0.8);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.geobek-panel.active {
    transform: scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Header */
.geobek-header {
    position: relative;
    min-height: 82px;
    padding: 16px 18px;
    gap: 14px;
    background:
        radial-gradient(circle at 12% 0%, rgba(16, 185, 129, 0.17), transparent 38%),
        linear-gradient(120deg, var(--geobek-surface), rgba(255, 255, 255, 0.02));
    border-bottom: 1px solid var(--geobek-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

.geobek-header-info {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.geobek-logo-box {
    position: relative;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--geobek-primary) 0%, var(--geobek-secondary) 100%);
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 7px 18px rgba(5, 150, 105, 0.2), 0 0 0 3px rgba(16, 185, 129, 0.07);
}

.geobek-logo-box::after {
    content: '';
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 9px;
    height: 9px;
    border: 2px solid var(--geobek-bg);
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.13);
}

.geobek-header-copy {
    min-width: 0;
}

.geobek-header-title {
    font-weight: 800;
    font-size: 1rem;
    color: var(--geobek-text);
    letter-spacing: 0.055em;
    line-height: 1.2;
}

.geobek-header-subtitle {
    margin-top: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--geobek-muted);
    line-height: 1.2;
    white-space: nowrap;
}

.geobek-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.geobek-window-controls {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--geobek-border);
    border-radius: 12px;
    background: var(--geobek-control);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

.geobek-action-btn {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--geobek-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.95rem;
    transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.geobek-action-btn:hover {
    background: var(--geobek-surface);
    color: var(--geobek-text);
    border-color: var(--geobek-border);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
}

.geobek-action-btn:active {
    transform: translateY(0) scale(0.96);
}

.geobek-action-btn:focus-visible,
.geobek-send-btn:focus-visible,
.geobek-launcher:focus-visible {
    outline: 2px solid var(--geobek-primary);
    outline-offset: 2px;
}

.geobek-action-btn--expand:hover {
    border-color: rgba(16, 185, 129, 0.26);
    background: rgba(16, 185, 129, 0.11);
    color: #059669;
}

.geobek-action-btn--reset:hover {
    border-color: rgba(245, 158, 11, 0.28);
    background: rgba(245, 158, 11, 0.11);
    color: #d97706;
}

.geobek-action-btn--close:hover {
    border-color: rgba(244, 63, 94, 0.27);
    background: rgba(244, 63, 94, 0.11);
    color: #e11d48;
}

[data-theme="dark"] .geobek-action-btn--expand:hover { color: #34d399; }
[data-theme="dark"] .geobek-action-btn--reset:hover { color: #fbbf24; }
[data-theme="dark"] .geobek-action-btn--close:hover { color: #fb7185; }

/* Chat Messages */
.geobek-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--geobek-border) transparent;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.018), transparent 24%);
}

.geobek-messages::-webkit-scrollbar { width: 5px; }
.geobek-messages::-webkit-scrollbar-thumb { background: var(--geobek-border); border-radius: 10px; }

.geobek-msg {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: geobek-fade-in 0.3s ease-out forwards;
}

@keyframes geobek-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.geobek-msg-ai { 
    align-self: flex-start; 
    flex-direction: row; 
    gap: 12px;
}

.geobek-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--geobek-border);
    background: linear-gradient(135deg, var(--geobek-bg) 0%, var(--geobek-glass) 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.geobek-msg-user { 
    align-self: flex-end; 
    align-items: flex-end; 
}

.geobek-msg-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.geobek-msg-ai .geobek-msg-bubble {
    background: var(--geobek-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--geobek-border);
    border-top-left-radius: 4px;
    color: var(--geobek-text);
}

.geobek-msg-user .geobek-msg-bubble {
    background: linear-gradient(135deg, var(--geobek-primary) 0%, var(--geobek-secondary) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

.geobek-msg-img {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 4px;
    border: 1px solid var(--geobek-border);
}

/* Input Area */
.geobek-input-area {
    padding: 14px 16px 16px;
    background: linear-gradient(180deg, var(--geobek-surface), var(--geobek-bg));
    border-top: 1px solid var(--geobek-border);
}

.geobek-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--geobek-control);
    border: 1px solid var(--geobek-border);
    border-radius: 17px;
    padding: 7px 8px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}

.geobek-input-wrapper:hover {
    border-color: rgba(16, 185, 129, 0.26);
}

.geobek-input-wrapper:focus-within {
    border-color: var(--geobek-primary);
    background: var(--geobek-surface);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.11), 0 8px 22px rgba(15, 23, 42, 0.07);
}

.geobek-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--geobek-text);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 8px 6px;
    resize: none;
    max-height: 120px;
    min-height: 24px;
}

.geobek-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: none;
    background: var(--geobek-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 6px 14px rgba(16, 185, 129, 0.22);
}

.geobek-send-btn:hover {
    background: var(--geobek-accent);
    transform: translateY(-1px);
}

.geobek-send-btn:disabled {
    background: var(--geobek-muted);
    opacity: 0.3;
    cursor: not-allowed;
    box-shadow: none;
}

.geobek-attach-btn {
    background: var(--geobek-surface);
    border-color: var(--geobek-border);
}

/* Image Preview */
.geobek-img-preview {
    display: none;
    position: relative;
    padding: 10px;
    background: var(--geobek-glass);
    border-bottom: 1px solid var(--geobek-border);
}

.geobek-img-preview img {
    height: 80px;
    border-radius: 8px;
    border: 1px solid var(--geobek-border);
}

.geobek-img-remove {
    position: absolute;
    top: 5px;
    left: 85px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
}

/* Typing Indicator */
.geobek-typing {
    display: none;
    padding: 12px 16px;
    background: var(--geobek-glass);
    border: 1px solid var(--geobek-border);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    gap: 4px;
    margin-left: 44px; /* Align with AI messages (32px avatar + 12px gap) */
}

.geobek-dot {
    width: 6px;
    height: 6px;
    background: var(--geobek-primary);
    border-radius: 50%;
    animation: geobek-typing 1.4s infinite ease-in-out both;
}

@keyframes geobek-typing {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Markdown Specifics */
.geobek-msg-bubble p, 
.geobek-msg-bubble span, 
.geobek-msg-bubble strong,
.geobek-msg-bubble em,
.geobek-msg-bubble li { 
    color: inherit; 
}
.geobek-msg-bubble p { margin-bottom: 8px; }
.geobek-msg-bubble p:last-child { margin-bottom: 0; }
.geobek-msg-bubble strong { color: inherit; font-weight: 700; }
.geobek-msg-ai .geobek-msg-bubble strong { 
    color: var(--geobek-primary); 
    text-shadow: 0 0 8px rgba(16, 185, 129, 0.4); 
}
.geobek-msg-bubble .markdown-body {
    overflow-x: auto;
}
.geobek-msg-bubble .markdown-body table {
    width: 100%;
    margin: 10px 0;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.55);
}
.geobek-msg-bubble .markdown-body th,
.geobek-msg-bubble .markdown-body td {
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
    border-right: 1px solid rgba(15, 23, 42, 0.1);
    border-bottom: 1px solid rgba(15, 23, 42, 0.1);
}
.geobek-msg-bubble .markdown-body th:last-child,
.geobek-msg-bubble .markdown-body td:last-child {
    border-right: none;
}
.geobek-msg-bubble .markdown-body tr:last-child td {
    border-bottom: none;
}
.geobek-msg-bubble .markdown-body thead th {
    background: rgba(16, 185, 129, 0.12);
    font-weight: 700;
}
.geobek-msg-bubble .markdown-body table:first-child,
.geobek-msg-bubble .markdown-body table:last-child {
    margin-top: 0;
    margin-bottom: 0;
}
[data-theme="dark"] .geobek-msg-bubble .markdown-body table {
    border-color: rgba(148, 163, 184, 0.24);
    background: rgba(15, 23, 42, 0.92);
}
[data-theme="dark"] .geobek-msg-bubble .markdown-body th,
[data-theme="dark"] .geobek-msg-bubble .markdown-body td {
    border-right-color: rgba(148, 163, 184, 0.18);
    border-bottom-color: rgba(148, 163, 184, 0.18);
    color: var(--text-primary);
}
[data-theme="dark"] .geobek-msg-bubble .markdown-body thead th {
    background: rgba(16, 185, 129, 0.18);
}
.geobek-msg-bubble code { background: rgba(0,0,0,0.3); padding: 2px 4px; border-radius: 4px; font-family: 'Courier New', Courier, monospace; }

/* Pin to Side Styles */
.geobek-pin-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: auto;
    padding: 0 4px;
    font-size: 0.85rem;
    color: var(--geobek-muted);
    cursor: pointer;
    user-select: none;
}

.geobek-pin-option input {
    cursor: pointer;
    width: 14px;
    height: 14px;
    accent-color: var(--geobek-primary);
}

.geobek-panel.geobek-pinned {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    width: 420px !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    transform: none !important;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1) !important;
    z-index: 99999 !important;
}

body.geobek-is-pinned {
    padding-right: 420px;
}

/* Mobile Adaptations */
@media (max-width: 480px) {
    .geobek-launcher {
        width: 56px;
        height: 56px;
        bottom: 20px;
        right: 20px;
    }
}

@media (max-width: 640px) {
    /* True fullscreen chat: cover the whole viewport regardless of any
       inline positioning left over from the draggable launcher. */
    .geobek-panel,
    .geobek-panel.geobek-pinned {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        transform-origin: center bottom;
    }

    .geobek-panel.active {
        transform: none !important;
    }

    .geobek-pin-option {
        display: none !important; /* Pinning doesn't make sense on mobile full screen */
    }

    body.geobek-is-pinned {
        padding-right: 0;
    }

    /* Freeze the page behind the fullscreen chat */
    body.geobek-mobile-open {
        overflow: hidden;
    }

    .geobek-header {
        min-height: 64px;
        padding-right: 14px;
        padding-left: 14px;
        padding-top: max(14px, env(safe-area-inset-top, 0px));
    }

    .geobek-header-actions {
        gap: 7px;
    }

    .geobek-window-controls .geobek-action-btn {
        min-width: 38px;
        min-height: 38px;
        width: 38px;
        height: 38px;
    }

    .geobek-attach-btn,
    .geobek-send-btn,
    .geobek-img-remove {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }

    .geobek-input-area {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    }

    .geobek-input-wrapper {
        align-items: flex-end;
        gap: 8px;
    }

    .geobek-textarea {
        min-height: 44px;
        line-height: 1.35;
    }

    .geobek-launcher {
        right: max(16px, env(safe-area-inset-right, 0px));
        bottom: max(16px, env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 480px) {
    .geobek-header {
        gap: 8px;
    }

    .geobek-logo-box {
        width: 40px;
        height: 40px;
        border-radius: 13px;
    }

    .geobek-header-info {
        gap: 9px;
    }

    .geobek-header-title {
        font-size: 0.9rem;
    }

    .geobek-header-subtitle {
        font-size: 0.64rem;
    }

    .geobek-window-controls {
        padding: 2px;
    }

    .geobek-window-controls .geobek-action-btn {
        min-width: 36px;
        min-height: 36px;
        width: 36px;
        height: 36px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .geobek-launcher,
    .geobek-panel,
    .geobek-action-btn,
    .geobek-send-btn,
    .geobek-msg {
        transition: none;
        animation: none;
    }

    .geobek-launcher::after,
    .geobek-dot {
        animation: none;
    }
}
/* Dictionary grounding links returned by Geobek */
.geobek-dictionary-links {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(16, 185, 129, 0.2);
}
.geobek-dictionary-links__label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
    color: var(--geobek-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.geobek-dictionary-links__items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.geobek-dictionary-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 9px;
    border: 1px solid rgba(16, 185, 129, 0.24);
    border-radius: 8px;
    background: rgba(16, 185, 129, 0.08);
    color: var(--geobek-primary);
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    transition: transform 0.18s ease, background 0.18s ease;
}
.geobek-dictionary-link:hover {
    transform: translateY(-1px);
    background: rgba(16, 185, 129, 0.16);
}


/* ── Daily Geobek message budget badge ───────────────────────── */
.geobek-quota {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 10px;
    height: 30px;
    border-radius: 999px;
    border: 1px solid var(--geobek-border);
    background: var(--geobek-glass);
    color: var(--geobek-muted);
    font-size: 0.66rem;
    font-weight: 750;
    letter-spacing: 0.01em;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.geobek-quota::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--geobek-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.geobek-quota--low {
    border-color: rgba(217, 119, 6, 0.35);
    background: rgba(217, 119, 6, 0.12);
    color: #b45309;
}

.geobek-quota--low::before {
    background: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.12);
}

.geobek-quota--empty {
    border-color: rgba(220, 38, 38, 0.35);
    background: rgba(220, 38, 38, 0.12);
    color: #b91c1c;
}

.geobek-quota--empty::before {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

[data-theme="dark"] .geobek-quota--low {
    color: #fbbf24;
}

[data-theme="dark"] .geobek-quota--empty {
    color: #fca5a5;
}

.geobek-textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .geobek-quota {
        width: auto;
        min-width: 44px;
        padding: 0 7px;
        font-size: 0;
        justify-content: center;
    }

    .geobek-quota::before {
        display: none;
    }

    .geobek-quota::after {
        content: attr(data-compact-label);
        font-size: 0.63rem;
    }
}
