/**
 * Smart Dental Assistant — floating widget + dedicated chat page styles.
 *
 * Isolation strategy: every component rule is scoped under `.sda-chat-ui`
 * (or `#sda-root` for the fixed shell), so host themes cannot leak borders,
 * backgrounds or typography into the chat. The visitor input carries
 * targeted `!important` guards on border/background/outline because themes
 * frequently ship `input[type="text"]` rules (sometimes with `!important`)
 * — that was the reported "red border" bug.
 */

/* ---------- Shared reset inside the chat UI ---------- */

#sda-root,
.sda-chatpage {
        line-height: 1.6;
        -webkit-text-size-adjust: 100%;
}

.sda-chat-ui,
.sda-chat-ui * {
        box-sizing: border-box;
        -webkit-tap-highlight-color: transparent;
}

/* Neutralize common theme leaks for every control inside the chat UI. */
.sda-chat-ui button,
.sda-chat-ui input,
.sda-chat-ui textarea {
        font-family: inherit;
        margin: 0;
        text-transform: none;
        letter-spacing: normal;
        box-shadow: none;
        appearance: none;
        -webkit-appearance: none;
        border-radius: 12px;
}

.sda-chat-ui button {
        border: none !important;
        background: none;
        cursor: pointer;
        line-height: 1.2;
        text-shadow: none;
        min-width: 0;
        min-height: 0;
        padding: 0;
}

.sda-chat-ui button:focus-visible {
        outline: 2px solid var(--sda-ring);
        outline-offset: 2px;
}

.sda-chat-ui a {
        text-shadow: none;
}

/* The hidden attribute must always win over any display rule. */
.sda-chat-ui [hidden],
#sda-root [hidden] {
        display: none !important;
}

/* ---------- Theme variables (overridden inline by PHP settings) ---------- */

:root {
        --sda-color: #0d9488;
        --sda-color-deep: #0f766e;
        --sda-color-soft: rgba(13, 148, 136, 0.10);
        --sda-ring: rgba(13, 148, 136, 0.28);
        --sda-shadow: rgba(13, 148, 136, 0.32);
        --sda-header-text: #ffffff;
        --sda-ink: #1f2937;
        --sda-ink-soft: #6b7280;
        --sda-line: #e5e9f0;
        --sda-surface: #f6f8fb;
}

/* =========================================================
 * Floating widget shell (launcher, teaser, panel)
 * ======================================================= */

#sda-root {
        position: fixed;
        bottom: 20px;
        z-index: 99999;
        font-family: inherit;
}

body.sda-chat-open {
        overflow: hidden;
        overscroll-behavior: none;
}

#sda-root.sda-right {
        right: 20px;
}

#sda-root.sda-left {
        left: 20px;
}

/*
 * Physical anchoring: the panel, teaser and badge always open toward the
 * screen center based on the WIDGET side, never on the site direction.
 */
#sda-root.sda-right .sda-panel,
#sda-root.sda-right .sda-teaser {
        right: 0;
}

#sda-root.sda-left .sda-panel,
#sda-root.sda-left .sda-teaser {
        left: 0;
}

#sda-root.sda-right .sda-teaser-close {
        right: 8px;
}

#sda-root.sda-left .sda-teaser-close {
        left: 8px;
}

#sda-root.sda-right .sda-badge {
        right: 2px;
}

#sda-root.sda-left .sda-badge {
        left: 2px;
}

/* ---------- Launcher button ---------- */

.sda-launcher {
        position: relative;
        width: 62px;
        height: 62px;
        border-radius: 50% !important;
        background: linear-gradient(145deg, #14b8a6 0%, var(--sda-color) 55%, var(--sda-color-deep) 100%) !important;
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 10px 28px var(--sda-shadow), 0 2px 8px rgba(15, 23, 42, 0.14);
        transition: transform 0.18s ease, box-shadow 0.18s ease;
        animation: sda-pop 0.45s ease both;
}

.sda-launcher:hover {
        transform: scale(1.07);
        box-shadow: 0 12px 32px var(--sda-shadow), 0 2px 8px rgba(15, 23, 42, 0.14);
}

.sda-launcher:focus-visible {
        outline: 3px solid var(--sda-ring);
        outline-offset: 2px;
}

.sda-launcher-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        transition: opacity 0.15s ease;
}

.sda-launcher .sda-icon-close {
        position: absolute;
        opacity: 0;
}

/*
 * Bulletproof launcher icon (ID + !important guards).
 *
 * The host theme (aramehr) ships aggressive button/svg rules that painted
 * the icon red and shrank it. These guards fix the size and force the
 * white color; no theme rule can win against the ID specificity.
 */
#sda-root .sda-launcher {
        color: #fff !important;
}

#sda-root .sda-launcher .sda-launcher-icon svg {
        display: block !important;
        width: 32px !important;
        height: 32px !important;
        color: #fff !important;
        max-width: none !important;
        max-height: none !important;
}

/* Fill-based icons (tooth, chat). */
#sda-root .sda-launcher .sda-icon-open svg {
        fill: #fff !important;
        stroke: none !important;
}

/* Stroke-based icon (smile). */
#sda-root[data-icon='smile'] .sda-launcher .sda-icon-open svg {
        fill: none !important;
        stroke: #fff !important;
}

/* Close (X) icon. */
#sda-root .sda-launcher .sda-icon-close svg {
        width: 26px !important;
        height: 26px !important;
        fill: none !important;
        stroke: #fff !important;
}

#sda-root.sda-open .sda-icon-open {
        opacity: 0;
}

#sda-root.sda-open .sda-icon-close {
        opacity: 1;
}

.sda-badge {
        position: absolute;
        top: 3px;
        width: 12px;
        height: 12px;
        border-radius: 50%;
        background: #34d399;
        border: 2px solid #fff !important;
        opacity: 1;
        transition: opacity 0.2s ease;
}

#sda-root.sda-open .sda-badge {
        opacity: 0;
}

/* ---------- Teaser bubble ---------- */

.sda-teaser {
        position: absolute;
        bottom: 74px;
        max-width: 240px;
        background: #fff;
        color: var(--sda-ink);
        border-radius: 14px;
        padding: 10px 30px 10px 14px;
        font-size: 13px;
        box-shadow: 0 8px 26px rgba(15, 23, 42, 0.16);
        border: 1px solid var(--sda-line) !important;
        animation: sda-fade-up 0.4s ease both;
        cursor: default;
}

#sda-root.sda-left .sda-teaser {
        padding: 10px 14px 10px 30px;
}

.sda-teaser-text {
        word-wrap: break-word;
}

.sda-teaser-close {
        position: absolute;
        top: 4px;
        font-size: 15px;
        line-height: 1;
        color: #9ca3af;
        padding: 2px !important;
        border-radius: 8px !important;
}

.sda-teaser-close:hover {
        color: #4b5563;
}

/* ---------- Panel ---------- */

.sda-panel {
        position: absolute;
        bottom: 84px;
        width: 380px;
        max-width: calc(100vw - 32px);
        height: 580px;
        max-height: calc(100vh - 120px);
        background: var(--sda-surface);
        border-radius: 20px;
        box-shadow:
                0 24px 70px rgba(15, 23, 42, 0.24),
                0 4px 14px rgba(15, 23, 42, 0.08);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        animation: sda-fade-up 0.25s ease both;
        border: 1px solid rgba(255, 255, 255, 0.6) !important;
}

/* =========================================================
 * Shared chat UI components (widget panel + chat page)
 * ======================================================= */

/* ---------- Header ---------- */

.sda-chat-ui .sda-header {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 14px 16px;
        background: linear-gradient(135deg, var(--sda-color-deep) 0%, var(--sda-color) 100%);
        color: var(--sda-header-text);
        flex-shrink: 0;
        position: relative;
        overflow: hidden;
}

.sda-chat-ui .sda-header::after {
        content: "";
        position: absolute;
        inset: 0;
        background: radial-gradient(120px 60px at 85% -10%, rgba(255, 255, 255, 0.18), transparent);
        pointer-events: none;
}

.sda-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50% !important;
        background: rgba(255, 255, 255, 0.2);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
}

/* Header avatar guard: same theme-proofing as the launcher icon. */
.sda-chat-ui .sda-avatar svg {
        width: 22px !important;
        height: 22px !important;
        fill: currentColor !important;
        color: var(--sda-header-text) !important;
}

.sda-header-meta {
        flex: 1;
        min-width: 0;
        position: relative;
        z-index: 1;
}

.sda-header-name {
        display: block;
        font-size: 15px;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
}

.sda-status {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        font-size: 11px;
        opacity: 0.94;
}

.sda-dot {
        width: 7px;
        height: 7px;
        border-radius: 50% !important;
        background: #6ee7b7;
        display: inline-block;
        box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.25);
}

.sda-header-actions {
        display: flex;
        align-items: center;
        gap: 4px;
        position: relative;
        z-index: 1;
}

.sda-header-actions button {
        color: var(--sda-header-text);
        opacity: 0.85;
        padding: 6px !important;
        border-radius: 8px !important;
        display: flex;
}

.sda-header-actions button:hover {
        opacity: 1;
        background: rgba(255, 255, 255, 0.16);
}

/* ---------- Messages ---------- */

.sda-chat-ui .sda-messages {
        flex: 1;
        overflow-y: auto;
        padding: 16px 14px;
        background:
                radial-gradient(320px 140px at 50% 0%, rgba(13, 148, 136, 0.05), transparent),
                var(--sda-surface);
        display: flex;
        flex-direction: column;
        gap: 10px;
        scroll-behavior: smooth;
        overscroll-behavior: contain;
}

.sda-msg {
        display: flex;
        max-width: 86%;
        animation: sda-fade-up 0.22s ease both;
}

.sda-msg-user {
        align-self: flex-start;
        flex-direction: row-reverse;
}

.sda-msg-assistant {
        align-self: flex-end;
}

.sda-chat-ui .sda-bubble {
        padding: 10px 14px;
        font-size: 13.5px;
        border-radius: 16px;
        white-space: pre-wrap;
        word-wrap: break-word;
        overflow-wrap: anywhere;
}

.sda-msg-user .sda-bubble {
        background: linear-gradient(135deg, var(--sda-color) 0%, var(--sda-color-deep) 100%);
        color: #fff;
        border-end-start-radius: 4px;
        box-shadow: 0 3px 10px var(--sda-shadow);
}

.sda-msg-assistant .sda-bubble {
        background: #fff;
        color: var(--sda-ink);
        border: 1px solid var(--sda-line) !important;
        border-end-end-radius: 4px;
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

/* In-message links: small pill, at most one per reply (enforced server-side). */
.sda-chat-ui .sda-bubble a {
        display: inline-block;
        max-width: 100%;
        font-size: 11.5px;
        line-height: 1.5;
        padding: 2px 10px;
        margin: 2px 0;
        border-radius: 999px !important;
        background: var(--sda-color-soft) !important;
        color: var(--sda-color) !important;
        text-decoration: none !important;
        border: 1px solid var(--sda-color-soft) !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: middle;
        transition: background 0.15s ease, color 0.15s ease;
}

.sda-chat-ui .sda-bubble a:hover {
        background: var(--sda-color) !important;
        color: #fff !important;
}

.sda-chat-ui .sda-bubble ul {
        margin: 6px 0;
        padding-inline-start: 18px;
}

.sda-chat-ui .sda-bubble li {
        margin: 2px 0;
}

/* Typing indicator */
.sda-chat-ui .sda-typing {
        display: inline-flex;
        gap: 4px;
        align-items: center;
        padding: 12px 14px;
}

.sda-chat-ui .sda-typing i {
        width: 7px;
        height: 7px;
        border-radius: 50% !important;
        background: var(--sda-color);
        opacity: 0.55;
        animation: sda-bounce 1.2s infinite ease-in-out;
}

.sda-chat-ui .sda-typing i:nth-child(2) {
        animation-delay: 0.15s;
}

.sda-chat-ui .sda-typing i:nth-child(3) {
        animation-delay: 0.3s;
}

/* ---------- Quick chips ---------- */

.sda-chat-ui .sda-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 7px;
        padding: 10px 14px 0;
        background: transparent;
        flex-shrink: 0;
}

.sda-chat-ui .sda-chip {
        font-size: 12px;
        padding: 7px 13px !important;
        border-radius: 999px !important;
        border: 1px solid var(--sda-ring) !important;
        background: #fff !important;
        color: var(--sda-color) !important;
        transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.sda-chat-ui .sda-chip:hover {
        background: var(--sda-color) !important;
        color: #fff !important;
}

.sda-chat-ui .sda-chip:active {
        transform: scale(0.96);
}

/* ---------- Lead (appointment) bar + form card ---------- */

.sda-lead-bar {
        display: flex;
        justify-content: center;
        padding: 8px 14px 0;
        flex-shrink: 0;
}

.sda-lead-open {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-size: 12.5px;
        font-weight: 600;
        padding: 7px 14px !important;
        border-radius: 999px !important;
        background: var(--sda-color-soft) !important;
        border: 1px dashed var(--sda-ring) !important;
        color: var(--sda-color-deep) !important;
        transition: background 0.15s ease, color 0.15s ease;
}

.sda-lead-open:hover {
        background: var(--sda-color) !important;
        border-color: var(--sda-color) !important;
        color: #fff !important;
}

.sda-lead-card {
        background: #fff;
        border: 1px solid var(--sda-ring) !important;
        border-radius: 14px;
        padding: 12px;
        font-size: 12.5px;
        color: var(--sda-ink);
        box-shadow: 0 6px 18px rgba(13, 148, 136, 0.12);
}

.sda-lead-title {
        font-weight: 700;
        font-size: 13.5px;
        margin-bottom: 3px;
        display: flex;
        align-items: center;
        gap: 6px;
        color: var(--sda-color-deep);
}

.sda-lead-desc {
        color: var(--sda-ink-soft);
        margin: 0 0 9px;
        line-height: 1.6;
}

.sda-lead-field {
        display: block;
        margin-bottom: 8px;
}

.sda-lead-field span {
        display: block;
        font-size: 11.5px;
        color: var(--sda-ink-soft);
        margin-bottom: 3px;
}

/* The lead inputs share the visitor input guards (theme-proof). */
.sda-chat-ui .sda-lead-input {
        width: 100%;
        display: block;
        border: 1.5px solid var(--sda-line) !important;
        background: var(--sda-surface) !important;
        color: var(--sda-ink) !important;
        border-radius: 10px !important;
        padding: 9px 12px !important;
        font-size: 13px !important;
        outline: none !important;
        box-shadow: none !important;
        transition: border-color 0.15s ease;
}

.sda-chat-ui .sda-lead-input:focus {
        border-color: var(--sda-color) !important;
        background: #fff !important;
}

.sda-lead-submit {
        width: 100%;
        margin-top: 2px;
        padding: 10px 12px !important;
        border-radius: 10px !important;
        background: linear-gradient(135deg, var(--sda-color) 0%, var(--sda-color-deep) 100%) !important;
        color: #fff !important;
        font-size: 13px;
        font-weight: 700;
        transition: opacity 0.15s ease, transform 0.1s ease;
}

.sda-lead-submit:hover {
        opacity: 0.93;
}

.sda-lead-submit:active {
        transform: scale(0.98);
}

.sda-lead-submit:disabled {
        opacity: 0.55;
        cursor: not-allowed;
}

.sda-lead-error {
        color: #dc2626;
        font-size: 11.5px;
        margin-top: 6px;
        min-height: 0;
}

.sda-lead-privacy {
        color: #9aa4b2;
        font-size: 10.5px;
        margin-top: 7px;
        line-height: 1.5;
}

.sda-lead-success {
        background: #f0fdf4;
        border: 1px solid #bbf7d0 !important;
        color: #166534;
        border-radius: 14px;
        padding: 10px 14px;
        font-size: 13px;
}

/* ---------- Footer ---------- */

.sda-chat-ui .sda-footer {
        padding: 10px 12px 12px;
        background: #fff;
        border-top: 1px solid var(--sda-line);
        flex-shrink: 0;
}

.sda-chat-ui .sda-form {
        display: flex;
        gap: 8px;
        align-items: center;
}

/* Visitor input — the reported bug lived here: theme CSS painted a red
   border on it. Every critical property carries an !important guard. */
.sda-chat-ui .sda-input {
        flex: 1;
        border: 1.5px solid var(--sda-line) !important;
        border-radius: 12px !important;
        padding: 10px 14px !important;
        font-size: 13.5px !important;
        font-family: inherit !important;
        background: var(--sda-surface) !important;
        color: var(--sda-ink) !important;
        outline: none !important;
        box-shadow: none !important;
        transition: border-color 0.15s ease;
        min-width: 0;
        height: auto;
        line-height: 1.5;
        margin: 0 !important;
}

.sda-chat-ui .sda-input::placeholder {
        color: #9aa4b2;
        opacity: 1;
}

.sda-chat-ui .sda-input:focus {
        border-color: var(--sda-color) !important;
        background: #fff !important;
        box-shadow: 0 0 0 3px var(--sda-color-soft) !important;
}

.sda-send {
        width: 42px;
        height: 42px;
        flex-shrink: 0;
        border-radius: 12px !important;
        background: linear-gradient(135deg, var(--sda-color) 0%, var(--sda-color-deep) 100%) !important;
        color: #fff !important;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: opacity 0.15s ease, transform 0.1s ease;
}

.sda-send:hover {
        opacity: 0.92;
}

.sda-send:active {
        transform: scale(0.94);
}

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

.sda-chat-ui .sda-disclaimer {
        margin: 7px 2px 0;
        font-size: 10.5px;
        color: #9aa4b2;
        line-height: 1.5;
}

/* Houmana credit */
.sda-chat-ui .sda-credit {
        display: block;
        margin: 5px 2px 0;
        text-align: center;
        font-size: 10px;
        color: #b3bac4;
        text-decoration: none !important;
        transition: color 0.15s ease;
}

.sda-chat-ui .sda-credit:hover {
        color: var(--sda-color);
}

/* =========================================================
 * Dedicated chat page ([sda_chat] shortcode)
 * ======================================================= */

.sda-chatpage {
        margin: 0 auto;
        padding: 18px 0 28px;
        max-width: 880px;
}

.sda-chatpage .sda-page-shell {
        height: calc(100vh - 170px);
        min-height: 520px;
        max-height: 900px;
        background: var(--sda-surface);
        border-radius: 22px;
        border: 1px solid rgba(255, 255, 255, 0.7) !important;
        box-shadow:
                0 24px 70px rgba(15, 23, 42, 0.16),
                0 4px 14px rgba(15, 23, 42, 0.06);
        display: flex;
        flex-direction: column;
        overflow: hidden;
}

.sda-chatpage .sda-messages {
        flex: 1;
}

.sda-chatpage .sda-chips,
.sda-chatpage .sda-lead-bar {
        background: var(--sda-surface);
}

@media (max-width: 640px) {
        .sda-chatpage {
                padding: 8px 0 16px;
        }

        .sda-chatpage .sda-page-shell {
                height: calc(100dvh - 150px);
                min-height: 440px;
                border-radius: 16px;
        }
}

/* ---------- Animations ---------- */

@keyframes sda-pop {
        from {
                opacity: 0;
                transform: scale(0.4);
        }
        to {
                opacity: 1;
                transform: scale(1);
        }
}

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

@keyframes sda-bounce {
        0%, 60%, 100% {
                transform: translateY(0);
        }
        30% {
                transform: translateY(-5px);
        }
}

@media (prefers-reduced-motion: reduce) {
        .sda-launcher,
        .sda-panel,
        .sda-teaser,
        .sda-msg {
                animation: none;
        }
}

/* ---------- Mobile (floating widget) ---------- */

@media (max-width: 480px) {
        #sda-root.sda-right {
                right: 14px;
                left: auto;
        }

        #sda-root.sda-left {
                left: 14px;
                right: auto;
        }

        #sda-root.sda-right,
        #sda-root.sda-left {
                bottom: 14px;
        }

        /* Same specificity as the anchoring rules above (and later in source
           order) so it wins on mobile where the panel becomes full-width. */
        #sda-root.sda-right .sda-panel,
        #sda-root.sda-left .sda-panel {
                position: fixed;
                left: 0;
                right: 0;
                bottom: 0;
                width: 100vw;
                height: 100dvh;
                max-height: none;
                border-radius: 0 !important;
                padding-bottom: env(safe-area-inset-bottom);
                animation: sda-mobile-in 0.2s ease both;
        }

        #sda-root.sda-open {
                inset: 0;
                width: 100%;
                height: 100%;
                pointer-events: none;
        }

        #sda-root.sda-open .sda-panel {
                pointer-events: auto;
        }

        #sda-root.sda-open .sda-launcher {
                display: none;
        }

        #sda-root .sda-header {
                padding-top: calc(14px + env(safe-area-inset-top));
        }

        #sda-root .sda-footer {
                padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }
}

@keyframes sda-mobile-in {
        from { opacity: 0; transform: translateY(12px); }
        to { opacity: 1; transform: translateY(0); }
}

/* Launcher: guard against host-theme button rules (oval bubble fix). */
#sda-root .sda-launcher {
        width: 62px !important;
        height: 62px !important;
        min-width: 62px !important;
        min-height: 62px !important;
        max-width: 62px !important;
        max-height: 62px !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        flex: none !important;
        aspect-ratio: 1 / 1 !important;
        border-radius: 50% !important;
        line-height: 0 !important;
}

/* Persistent label under the launcher (text from panel: teaser_text). */
#sda-root { display: flex !important; flex-direction: column; align-items: center; gap: 6px; }
#sda-root .sda-launcher-label {
        max-width: 120px; text-align: center; font-size: 11.5px; line-height: 1.45; font-weight: 600;
        color: var(--sda-ink, #1f2937); background: #fff; border: 1px solid var(--sda-line, #e5e7eb);
        border-radius: 10px; padding: 4px 9px; box-shadow: 0 4px 14px rgba(15,23,42,.12);
}
#sda-root #sda-launcher[aria-expanded="true"] + .sda-launcher-label { display: none; }
