/* ==========================================================================
   « Ask Ibtissem » — Chat widget styles (self-contained)
   Its own design tokens so it looks consistent on BOTH the dark portfolio
   (index.html) and the light "Sanctuary" page (hobbies.html).
   ========================================================================== */
#ik-chat-root {
    --ikc-bg:        rgba(16, 16, 24, 0.92);
    --ikc-surface:   rgba(255, 255, 255, 0.04);
    --ikc-border:    rgba(255, 255, 255, 0.10);
    --ikc-text:      #f0f0f5;
    --ikc-muted:     #a6a6b8;
    --ikc-accent:    #2575fc;
    --ikc-accent-2:  #00d2ff;
    --ikc-accent-1:  #6a11cb;
    --ikc-user-bg:   linear-gradient(135deg, #6a11cb, #2575fc);
    --ikc-glow:      rgba(37, 117, 252, 0.45);
    --ikc-radius:    18px;
    --ikc-font:      'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;

    position: fixed;
    right: clamp(16px, 3vw, 28px);
    /* keep the launcher clear of Android/iOS gesture bars */
    bottom: calc(clamp(16px, 3vw, 28px) + env(safe-area-inset-bottom, 0px));
    z-index: 2147483000; /* above everything */
    font-family: var(--ikc-font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent; /* no grey flash on tap (Android) */
}

#ik-chat-root *,
#ik-chat-root *::before,
#ik-chat-root *::after { box-sizing: border-box; }

/* ---- Floating launcher bubble ---- */
.ikc-launcher {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--ikc-user-bg);
    color: #fff;
    font-size: 1.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 22px var(--ikc-glow);
    transition: transform 0.25s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.25s ease;
    position: relative;
}
.ikc-launcher:hover { transform: scale(1.07); box-shadow: 0 14px 38px rgba(0,0,0,0.5), 0 0 30px var(--ikc-glow); }
.ikc-launcher:active { transform: scale(0.97); }
.ikc-launcher::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--ikc-accent-2);
    opacity: 0.5;
    animation: ikc-ping 2.6s ease-out infinite;
}
@keyframes ikc-ping {
    0%   { transform: scale(1);    opacity: 0.5; }
    70%  { transform: scale(1.35); opacity: 0;   }
    100% { transform: scale(1.35); opacity: 0;   }
}
/* Small "online" dot */
.ikc-launcher .ikc-dot {
    position: absolute; top: 6px; right: 6px;
    width: 12px; height: 12px; border-radius: 50%;
    background: #22c55e; border: 2px solid #0d0d14;
}

/* ---- Chat panel ---- */
.ikc-panel {
    position: absolute;
    right: 0;
    bottom: 78px;
    width: min(374px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 120px));
    background: var(--ikc-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--ikc-border);
    border-radius: var(--ikc-radius);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    /* hidden state */
    opacity: 0;
    transform: translateY(12px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.25, 1, 0.5, 1);
}
#ik-chat-root.ikc-open .ikc-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
#ik-chat-root.ikc-open .ikc-launcher { transform: scale(0.9); }

/* ---- Header ---- */
.ikc-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(106,17,203,0.35), rgba(37,117,252,0.30));
    border-bottom: 1px solid var(--ikc-border);
    flex-shrink: 0;
}
.ikc-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    object-fit: cover; border: 2px solid rgba(255,255,255,0.5);
    flex-shrink: 0;
}
.ikc-header-info { flex-grow: 1; min-width: 0; line-height: 1.25; }
.ikc-header-title { font-weight: 700; font-size: 0.98rem; color: #fff; }
.ikc-header-status {
    font-size: 0.72rem; color: rgba(255,255,255,0.85);
    display: flex; align-items: center; gap: 5px;
}
.ikc-header-status::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%;
    background: #22c55e; box-shadow: 0 0 8px #22c55e;
}
.ikc-close {
    background: rgba(255,255,255,0.12); border: none; color: #fff;
    width: 34px; height: 34px; min-width: 34px; border-radius: 50%;
    cursor: pointer; font-size: 1rem; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s ease;
}
.ikc-close:hover { background: rgba(255,255,255,0.24); }

/* ---- Messages ---- */
.ikc-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
}
.ikc-messages::-webkit-scrollbar { width: 7px; }
.ikc-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }

.ikc-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: ikc-pop 0.25s ease both;
}
@keyframes ikc-pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ikc-msg.ikc-bot {
    align-self: flex-start;
    background: var(--ikc-surface);
    border: 1px solid var(--ikc-border);
    color: var(--ikc-text);
    border-bottom-left-radius: 5px;
}
.ikc-msg.ikc-user {
    align-self: flex-end;
    background: var(--ikc-user-bg);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.ikc-msg a { color: var(--ikc-accent-2); text-decoration: underline; }
.ikc-msg.ikc-user a { color: #fff; }

/* Typing indicator */
.ikc-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.ikc-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--ikc-muted);
    animation: ikc-blink 1.2s infinite ease-in-out both;
}
.ikc-typing span:nth-child(2) { animation-delay: 0.18s; }
.ikc-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes ikc-blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---- Suggestions ---- */
.ikc-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 16px 10px;
    flex-shrink: 0;
}
.ikc-chip {
    background: var(--ikc-surface);
    border: 1px solid var(--ikc-border);
    color: var(--ikc-text);
    font-family: inherit;
    font-size: 0.78rem;
    padding: 7px 12px;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.ikc-chip:hover { background: rgba(37,117,252,0.18); border-color: var(--ikc-accent); transform: translateY(-1px); }

/* ---- Input ---- */
.ikc-inputbar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--ikc-border);
    background: rgba(0,0,0,0.25);
    flex-shrink: 0;
}
.ikc-input {
    flex-grow: 1;
    background: var(--ikc-surface);
    border: 1px solid var(--ikc-border);
    border-radius: 14px;
    color: var(--ikc-text);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 11px 14px;
    resize: none;
    max-height: 96px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s ease;
}
.ikc-input::placeholder { color: var(--ikc-muted); }
.ikc-input:focus { border-color: var(--ikc-accent); }
.ikc-send {
    width: 44px; height: 44px; min-width: 44px;
    border-radius: 12px; border: none; cursor: pointer;
    background: var(--ikc-user-bg); color: #fff; font-size: 1.05rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 14px var(--ikc-glow);
    transition: transform 0.15s ease, filter 0.2s ease;
}
.ikc-send:hover { filter: brightness(1.1); }
.ikc-send:active { transform: scale(0.92); }
.ikc-send:disabled { opacity: 0.5; cursor: default; filter: none; }

.ikc-footnote {
    text-align: center;
    font-size: 0.66rem;
    color: var(--ikc-muted);
    padding: 0 12px 8px;
    flex-shrink: 0;
}

/* ---- Mobile: full-screen sheet ---- */
@media (max-width: 480px) {
    #ik-chat-root { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
    .ikc-panel {
        position: fixed;
        right: 0; left: 0; bottom: 0; top: 0;
        width: 100%;          /* 100vw can add scrollbar-width overflow; 100% is safe with left/right:0 */
        height: 100vh;        /* fallback for older Android without dvh */
        height: 100dvh;
        border-radius: 0;
        border: none;
    }
    /* keep the input above the Android gesture bar */
    .ikc-inputbar { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
    #ik-chat-root.ikc-open .ikc-launcher { opacity: 0; pointer-events: none; }
}

/* ---- Accessibility: respect reduced-motion ---- */
@media (prefers-reduced-motion: reduce) {
    #ik-chat-root *,
    #ik-chat-root *::before,
    #ik-chat-root *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
