/* Mia Floating Chat — Stylesheet v3
 * Flydende chat-widget der følger med på alle sider.
 * Design matcher v3 designsystem (mørk #141B24, blå accent #5B9BD5).
 *
 * VIGTIGT: JS røres IKKE — alle element IDs og mia-fc-* klasser bevares.
 * Kun farver, baggrunde, og HTML struktur via PHP opdateres.
 */

/* ════ Design tokens (matcher tema style.css v3) ═══ */
#mia-floating-chat {
    --fc-bg: #141B24;
    --fc-bg-alt: #1A2330;
    --fc-surface: #222E3E;
    --fc-surface-2: #2A3A4E;
    --fc-border: #3A4D66;
    --fc-border-soft: #2A3A4E;
    --fc-text: #E8EDF5;
    --fc-text-muted: #9CA8B8;
    --fc-text-dim: #6B7B92;
    --fc-accent: #5B9BD5;
    --fc-accent-h: #6BAEE0;
    --fc-green: #34D399;
    --fc-radius-lg: 16px;
    --fc-shadow: 0 4px 24px rgba(0,0,0,0.4);
    --fc-shadow-lg: 0 8px 40px rgba(0,0,0,0.45);
}

/* ═══ Hide theme's awake-indicator when plugin is active ═══ */
.awake-indicator {
    display: none !important;
}

/* ═══ Root container ═══ */
#mia-floating-chat {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 99998;
    pointer-events: none;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#mia-floating-chat * {
    box-sizing: border-box;
}

/* ═══ Tooltip (dukker op efter 3 sek, kan lukkes) ═══ */
.mia-fc-tooltip {
    pointer-events: auto;
    position: fixed;
    bottom: 92px;
    right: 28px;
    z-index: 99997;
    max-width: 280px;
    padding: 16px 18px;
    background: var(--fc-surface);
    border: 1px solid var(--fc-border);
    border-radius: 14px 14px 14px 4px;
    box-shadow: var(--fc-shadow-lg);
    font-size: 14px;
    color: var(--fc-text);
    line-height: 1.55;
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.mia-fc-tooltip.show {
    display: block;
    opacity: 1;
    transform: translateY(0);
}
.mia-fc-tooltip.hide {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}
.mia-fc-tooltip-close {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--fc-text-dim);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    border-radius: 4px;
    transition: color 0.2s;
}
.mia-fc-tooltip-close:hover { color: var(--fc-text); }
.mia-fc-tooltip-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    float: left;
    margin-right: 10px;
    background-size: cover;
    background-position: center 20%;
    border: 1.5px solid var(--fc-accent);
    flex-shrink: 0;
}
.mia-fc-tooltip strong { color: var(--fc-accent); }

/* ═══ Floating bubble (lukket tilstand — med avatar, puls, badge) ═══ */
.mia-fc-bubble {
    pointer-events: auto;
    position: fixed;
    bottom: 28px;
    right: 28px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 10px 10px;
    border-radius: 50px;
    background: linear-gradient(135deg, #222E3E 0%, #2A3A4E 100%);
    border: 1px solid var(--fc-border);
    font-size: 14px;
    color: var(--fc-text-muted);
    cursor: pointer;
    user-select: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--fc-shadow);
    animation: mia-fc-bubble-in 0.4s ease, mia-fc-bubble-pulse 3s ease-in-out infinite;
}

.mia-fc-bubble:hover {
    border-color: var(--fc-accent);
    transform: translateY(-3px);
    box-shadow: var(--fc-shadow-lg), 0 0 0 8px rgba(91,155,213,0.1);
    background: linear-gradient(135deg, #2A3A4E 0%, #324860 100%);
}

@keyframes mia-fc-bubble-pulse {
    0%, 100% { box-shadow: var(--fc-shadow), 0 0 0 0 rgba(91,155,213,0.25); }
    50% { box-shadow: var(--fc-shadow), 0 0 0 12px rgba(91,155,213,0); }
}

@keyframes mia-fc-bubble-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Avatar i boblen — Mia's ansigt */
.mia-fc-bubble-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    flex-shrink: 0;
    background-size: cover;
    background-position: center 20%;
    border: 2px solid var(--fc-accent);
    box-shadow: 0 2px 10px rgba(91,155,213,0.25);
    position: relative;
}
.mia-fc-bubble-avatar::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--fc-green);
    border: 2px solid #222E3E;
    box-shadow: 0 0 6px rgba(52,211,153,0.6);
    animation: mia-fc-awake-pulse 2s infinite;
}

/* Original dot — skjules, bevares for JS kompatibilitet */
.mia-fc-bubble-dot {
    display: none;
}

@keyframes mia-fc-awake-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.5; }
}

.mia-fc-bubble-text {
    font-size: 14px;
    color: var(--fc-text-muted);
    white-space: nowrap;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.mia-fc-bubble-text strong {
    color: var(--fc-text);
    font-weight: 600;
}

.mia-fc-bubble-status {
    font-size: 12px;
    color: var(--fc-green);
    display: flex;
    align-items: center;
    gap: 5px;
}
.mia-fc-bubble-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--fc-green);
    box-shadow: 0 0 5px var(--fc-green);
}

/* Notification badge */
.mia-fc-bubble-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--fc-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--fc-bg);
    box-shadow: 0 2px 8px rgba(91,155,213,0.4);
    animation: mia-fc-badge-bounce 0.6s ease;
}
@keyframes mia-fc-badge-bounce {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.25); }
    100% { transform: scale(1); opacity: 1; }
}

/* ═══ Chat panel (åben tilstand) ═══ */
.mia-fc-panel {
    pointer-events: auto;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 48px);
    flex-direction: column;
    background: var(--fc-surface);
    border: 1px solid var(--fc-border);
    border-radius: var(--fc-radius-lg);
    overflow: hidden;
    box-shadow: var(--fc-shadow-lg);
    animation: mia-fc-panel-in 0.3s ease;
}

@keyframes mia-fc-panel-in {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ═══ Chat header (140px — Mia baggrundsbillede + avatar) ═══ */
.mia-fc-header {
    position: relative;
    height: 140px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
}

.mia-fc-header-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 30%;
    z-index: 0;
}

.mia-fc-header-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(20,27,36,0.3) 0%, rgba(30,40,56,0.85) 100%);
    z-index: 1;
}

.mia-fc-header-avatar {
    position: relative;
    z-index: 2;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid var(--fc-accent);
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.mia-fc-header-info {
    position: relative;
    z-index: 2;
    flex: 1;
    min-width: 0;
}

.mia-fc-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mia-fc-title .mia-fc-title-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--fc-green);
    box-shadow: 0 0 6px var(--fc-green);
    animation: mia-fc-awake-pulse 2s infinite;
    flex-shrink: 0;
}

.mia-fc-status {
    font-size: 13px;
    color: var(--fc-text-muted);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mia-fc-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--fc-green);
    box-shadow: 0 0 6px var(--fc-green);
    display: inline-block;
    flex-shrink: 0;
}

/* ═══ Close / minimize button ═══ */
.mia-fc-minimize {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 3;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.mia-fc-minimize:hover {
    background: rgba(0,0,0,0.6);
}

.mia-fc-minimize:active {
    background: rgba(0,0,0,0.7);
}

/* ═══ Messages area ═══ */
.mia-fc-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    background: var(--fc-bg);
}

.mia-fc-messages::-webkit-scrollbar {
    width: 5px;
}

.mia-fc-messages::-webkit-scrollbar-track {
    background: transparent;
}

.mia-fc-messages::-webkit-scrollbar-thumb {
    background: var(--fc-border-soft);
    border-radius: 3px;
}

/* ═══ Chat bubbles (beskeder) ═══ */
.mia-fc-bubble-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
    animation: mia-fc-msg-in 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes mia-fc-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.mia-fc-mia {
    align-self: flex-start;
    background: var(--fc-surface-2);
    color: var(--fc-text);
    border-bottom-left-radius: 4px;
}

.mia-fc-user {
    align-self: flex-end;
    background: var(--fc-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.mia-fc-sender {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    opacity: 0.7;
}

.mia-fc-mia .mia-fc-sender {
    color: var(--fc-accent);
}

.mia-fc-user .mia-fc-sender {
    color: rgba(255,255,255,0.7);
}

.mia-fc-text {
    font-size: 15px;
    line-height: 1.6;
    color: inherit;
}

.mia-fc-user .mia-fc-text {
    color: #fff;
}

/* ═══ Thinking indicator ═══ */
.mia-fc-thinking {
    opacity: 0.9;
}

.mia-fc-dots {
    display: inline-flex;
    gap: 4px;
    margin-right: 8px;
    vertical-align: middle;
}

.mia-fc-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--fc-text-dim);
    animation: mia-fc-dot-bounce 1.4s infinite;
}

.mia-fc-dots span:nth-child(2) { animation-delay: 0.2s; }
.mia-fc-dots span:nth-child(3) { animation-delay: 0.4s; }

.mia-fc-thinking-text {
    font-size: 13px;
    color: var(--fc-text-dim);
}

@keyframes mia-fc-dot-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ═══ Input form ═══ */
.mia-fc-form {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 16px 20px;
    border-top: 1px solid var(--fc-border-soft);
    flex-shrink: 0;
    background: var(--fc-bg);
}

.mia-fc-input {
    flex: 1;
    background: var(--fc-bg);
    border: 1px solid var(--fc-border-soft);
    border-radius: 24px;
    padding: 10px 16px;
    color: var(--fc-text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    overflow-y: hidden;
    max-height: 100px;
    line-height: 1.5;
    display: block;
}

.mia-fc-input:focus {
    border-color: var(--fc-accent);
}

.mia-fc-input::placeholder {
    color: var(--fc-text-dim);
}

.mia-fc-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--fc-accent);
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
}

.mia-fc-send:hover {
    background: var(--fc-accent-h);
    transform: scale(1.05);
}

.mia-fc-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ═══ Chat footer ═══ */
.mia-fc-footer {
    padding: 8px 20px 12px;
    text-align: center;
    font-size: 12px;
    color: var(--fc-text-dim);
    flex-shrink: 0;
    border-top: 1px solid var(--fc-border-soft);
    background: var(--fc-bg);
}

.mia-fc-footer a {
    color: var(--fc-accent);
}

/* ═══ Responsive — Tablet (≤1024px) ═══ */
@media (max-width: 1024px) {
    .mia-fc-panel {
        width: 380px;
    }
}

/* ═══ Responsive — Mobile (≤768px) ═══ */
@media (max-width: 768px) {
    .mia-fc-bubble {
        bottom: 16px;
        right: 16px;
        padding: 8px 18px 8px 8px;
    }
    .mia-fc-bubble-avatar {
        width: 34px;
        height: 34px;
    }
    .mia-fc-tooltip {
        right: 16px;
        bottom: 80px;
        max-width: calc(100vw - 32px);
    }

    /* Full screen panel using dynamic viewport height */
    .mia-fc-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    /* Fallback for browsers without dvh support */
    @supports not (height: 100dvh) {
        .mia-fc-panel {
            height: 100vh;
            max-height: 100vh;
        }
    }

    /* Compact header on mobile */
    .mia-fc-header {
        height: 110px;
        padding: 12px 14px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .mia-fc-header-avatar {
        width: 44px;
        height: 44px;
    }

    .mia-fc-title {
        font-size: 15px;
    }

    .mia-fc-status {
        font-size: 12px;
    }

    /* Big, obvious ✕ close button on mobile */
    .mia-fc-minimize {
        width: 44px;
        height: 44px;
        font-size: 20px;
        border-radius: 50%;
        background: rgba(0,0,0,0.5);
        color: rgba(255,255,255,0.9);
    }

    .mia-fc-minimize:hover {
        background: rgba(0,0,0,0.7);
    }

    .mia-fc-messages {
        padding: 16px 14px;
        gap: 12px;
    }

    .mia-fc-bubble-msg {
        max-width: 92%;
        padding: 12px 14px;
    }

    .mia-fc-text {
        font-size: 14px;
    }

    .mia-fc-form {
        padding: 12px 14px;
        gap: 8px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .mia-fc-input {
        font-size: 16px;
        padding: 10px 14px;
    }

    .mia-fc-send {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

/* ═══ Responsive — Small mobile (≤480px) ═══ */
@media (max-width: 480px) {
    .mia-fc-bubble {
        bottom: 12px;
        right: 12px;
        padding: 6px 14px 6px 6px;
    }
    .mia-fc-bubble-avatar {
        width: 32px;
        height: 32px;
    }
    .mia-fc-bubble-text {
        font-size: 12px;
    }
    .mia-fc-bubble-status {
        font-size: 11px;
    }

    .mia-fc-messages {
        padding: 14px 12px;
        gap: 10px;
    }

    .mia-fc-bubble-msg {
        max-width: 95%;
        padding: 10px 12px;
    }

    .mia-fc-text {
        font-size: 13px;
    }
}