/* v2 live chat widget — self-contained, doesn't require .v2-theme wrapper.
   The widget DOM is injected by /js/v2/v2-chat-widget.js so every v2 page
   that loads head-common automatically gets the bubble. */

.v2-chat {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #fff;
}

/* ── Bubble ─────────────────────────────────────────────────────── */
.v2-chat__bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid #222;
    background: #0f0f0f;
    color: #ff7a1a;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 122, 26, .25);
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
    display: grid;
    place-items: center;
}
.v2-chat__bubble:hover {
    background: #141414;
    transform: translateY(-2px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, .65), 0 0 0 1px rgba(255, 122, 26, .45);
}
.v2-chat__bubble[aria-expanded="true"] { display: none; }

.v2-chat__bubble-dot {
    position: absolute;
    top: 8px; right: 8px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #2bd66f;
    box-shadow: 0 0 0 2px #0f0f0f;
}

/* ── Panel ──────────────────────────────────────────────────────── */
.v2-chat__panel {
    position: absolute;
    right: 0;
    bottom: 0;
    width: min(380px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 40px));
    background: #0a0a0a;
    border: 1px solid #1a1a1a;
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .7);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: v2ChatIn .18s ease-out;
}
.v2-chat[data-open="true"] .v2-chat__panel { display: flex; }
@keyframes v2ChatIn {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ── Header ─────────────────────────────────────────────────────── */
.v2-chat__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid #1a1a1a;
    background: #0d0d0d;
}
.v2-chat__head-icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff7a1a 0%, #ff5500 100%);
    display: grid; place-items: center;
    font-weight: 600;
    color: #0a0a0a;
    font-size: 14px;
}
.v2-chat__head-meta { flex: 1; min-width: 0; }
.v2-chat__head-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: #ff7a1a;
    letter-spacing: .08em;
    text-transform: uppercase;
    display: block;
}
.v2-chat__head-title {
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    margin: 2px 0 0;
    line-height: 1.2;
}
.v2-chat__head-status {
    font-size: 11px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.v2-chat__head-status::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #2bd66f;
    box-shadow: 0 0 6px rgba(43, 214, 111, .55);
}
.v2-chat__close {
    appearance: none;
    border: 0; background: transparent;
    color: #888;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}
.v2-chat__close:hover { color: #fff; background: #141414; }

/* ── Pre-chat form ──────────────────────────────────────────────── */
.v2-chat__pre {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}
.v2-chat__pre[hidden] { display: none; }
.v2-chat__pre-lead {
    font-size: 13px;
    color: #aaa;
    line-height: 1.5;
    margin: 0 0 2px;
}
.v2-chat__field { display: flex; flex-direction: column; gap: 4px; }
.v2-chat__label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: #888;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.v2-chat__input {
    appearance: none;
    background: #0f0f0f;
    border: 1px solid #222;
    border-radius: 8px;
    padding: 10px 12px;
    color: #fff;
    font: inherit;
    font-size: 13px;
    transition: border-color .15s ease;
    width: 100%;
}
.v2-chat__input:focus {
    outline: none;
    border-color: #ff7a1a;
}
.v2-chat__pre altcha-widget { display: block; margin-top: 4px; }
.v2-chat__submit {
    appearance: none;
    margin-top: 6px;
    border: 1px solid #ff7a1a;
    background: #ff7a1a;
    color: #0a0a0a;
    font-weight: 600;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: filter .15s ease;
}
.v2-chat__submit:hover:not(:disabled) { filter: brightness(1.08); }
.v2-chat__submit:disabled { opacity: .55; cursor: progress; }

.v2-chat__error {
    color: #ff6464;
    font-size: 12px;
    margin: 4px 0 0;
}

/* ── Log ────────────────────────────────────────────────────────── */
.v2-chat__log {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #0a0a0a;
}
.v2-chat__log::-webkit-scrollbar { width: 8px; }
.v2-chat__log::-webkit-scrollbar-thumb { background: #1a1a1a; border-radius: 4px; }

.v2-chat__msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.v2-chat__msg-body {
    /* keep-as-default; allows the .v2-chat__msg padding to host time and author */
}
.v2-chat__msg-author {
    font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
    font-size: 10px;
    color: #ff7a1a;
    letter-spacing: .04em;
    margin-bottom: 3px;
    text-transform: none;
    line-height: 1.2;
}
.v2-chat__msg--in {
    align-self: flex-end;
    background: #ff7a1a;
    color: #0a0a0a;
    border-bottom-right-radius: 3px;
}
.v2-chat__msg--out {
    align-self: flex-start;
    background: #141414;
    color: #ddd;
    border: 1px solid #1a1a1a;
    border-bottom-left-radius: 3px;
}
.v2-chat__msg--system {
    align-self: center;
    background: transparent;
    color: #666;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    text-align: center;
}
.v2-chat__msg-time {
    font-size: 10px;
    color: #888;
    margin-top: 2px;
    font-family: 'JetBrains Mono', monospace;
}

/* ── Compose ────────────────────────────────────────────────────── */
.v2-chat__compose {
    padding: 10px 12px;
    border-top: 1px solid #1a1a1a;
    background: #0d0d0d;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.v2-chat__compose textarea {
    flex: 1;
    appearance: none;
    background: #0a0a0a;
    border: 1px solid #222;
    border-radius: 8px;
    padding: 8px 10px;
    color: #fff;
    font: inherit;
    font-size: 13px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}
.v2-chat__compose textarea:focus { outline: none; border-color: #ff7a1a; }

.v2-chat__send {
    appearance: none;
    border: 1px solid #ff7a1a;
    background: #ff7a1a;
    color: #0a0a0a;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s ease;
}
.v2-chat__send:hover:not(:disabled) { filter: brightness(1.08); }
.v2-chat__send:disabled { opacity: .55; cursor: not-allowed; }

/* ────────────────────────────  Mobile  ──────────────────────────────── */
@media (max-width: 640px) {
    /* Bubble: a touch up from the bottom edge so it doesn't collide with iOS
       home indicator. */
    .v2-chat {
        right: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    }

    /* Open panel: edge-to-edge fullscreen takeover. Avoids any background
       scroll bleed-through and removes the "small floating window" feel. */
    .v2-chat[data-open="true"] {
        position: fixed;
        inset: 0;
        right: 0; bottom: 0; left: 0; top: 0;
    }
    .v2-chat[data-open="true"] .v2-chat__panel {
        position: relative;
        width: 100vw;
        height: 100vh;
        height: 100dvh;          /* dynamic vh — shrinks when keyboard opens */
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        animation: none;          /* no slide-in on mobile */
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Inputs MUST be at least 16px or iOS Safari auto-zooms on focus and
       refuses to zoom back out. */
    .v2-chat__input,
    .v2-chat__compose textarea {
        font-size: 16px;
        line-height: 1.45;
    }

    /* Bigger touch targets and roomier padding for thumbs */
    .v2-chat__input { padding: 12px 14px; }
    .v2-chat__submit { padding: 14px 16px; font-size: 14px; }
    .v2-chat__send { padding: 12px 18px; font-size: 16px; }
    .v2-chat__close {
        font-size: 28px;
        padding: 8px 12px;
    }
    .v2-chat__head { padding: 14px 14px 12px; }

    /* Make the log fill all available space and capture touches reliably on
       iOS (the property is non-standard but has no effect when ignored). */
    .v2-chat__log {
        flex: 1 1 auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Bigger speech bubbles read better on a phone */
    .v2-chat__msg {
        max-width: 88%;
        font-size: 14px;
        padding: 9px 13px;
    }
}
