/* ============================================================
   MyDoctor Greece — Chat Widget
   Scoped to #mdg-* IDs so it never conflicts with the template.
   ============================================================ */

/* ── Toggle button ─────────────────────────────────────────── */

#mdg-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0d9488 0%, #0369a1 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 4px 16px rgba(3, 105, 161, 0.45);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    padding: 0;
}

#mdg-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(3, 105, 161, 0.55);
}

#mdg-chat-toggle:focus-visible {
    outline: 3px solid #0369a1;
    outline-offset: 3px;
}

#mdg-chat-toggle svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Chat window ───────────────────────────────────────────── */

#mdg-chat-window {
    position: fixed;
    bottom: 94px;
    right: 24px;
    width: 340px;
    height: 500px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: none; /* JS sets to "flex" when open */
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: #1e293b;
    transition: height 0.2s ease, width 0.2s ease;
}

#mdg-chat-window.mdg-maximized {
    width: min(520px, calc(100vw - 16px));
    height: min(680px, calc(100vh - 110px));
}

/* Mobile: true fullscreen (≤768px) — like WhatsApp/Messenger */
@media (max-width: 768px) {
    #mdg-chat-window,
    #mdg-chat-window.mdg-maximized {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border-radius: 0;
        z-index: 10000;
    }
}

/* Scroll lock + hide launcher — mobile fullscreen chat only */
@media (max-width: 768px) {
    body.mdg-chat-open {
        overflow: hidden;
    }
    body.mdg-chat-open #mdg-chat-toggle {
        display: none !important;
    }
}

/* iPhone safe area — home indicator clearance */
@media (max-width: 768px) {
    #mdg-chat-input {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* ── Header ────────────────────────────────────────────────── */

#mdg-chat-header {
    background: linear-gradient(135deg, #0d9488 0%, #0369a1 100%);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 8px;
}

.mdg-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.mdg-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}

.mdg-chat-header-text {
    min-width: 0;
}

.mdg-chat-header-title {
    font-weight: 700;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mdg-chat-header-status {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}

.mdg-online-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
    animation: mdgPulse 2s infinite;
}

@keyframes mdgPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

.mdg-online-dot--offline {
    background: #9ca3af;
    animation: none;
}

.mdg-chat-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.mdg-chat-header-actions button {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}

.mdg-chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.32);
}

.mdg-chat-header-actions button:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 1px;
}

/* ── Messages area ─────────────────────────────────────────── */

#mdg-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

#mdg-chat-messages::-webkit-scrollbar {
    width: 4px;
}

#mdg-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#mdg-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* ── Message bubbles ───────────────────────────────────────── */

.mdg-msg {
    max-width: 84%;
    display: flex;
    flex-direction: column;
}

.mdg-msg p {
    margin: 0;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.55;
    font-size: 13.5px;
    word-break: break-word;
}

/* Bot message — left-aligned */
.mdg-msg--bot {
    align-self: flex-start;
}

.mdg-msg--bot p {
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Visitor message — right-aligned */
.mdg-msg--visitor {
    align-self: flex-end;
}

.mdg-msg--visitor p {
    background: linear-gradient(135deg, #0d9488 0%, #0369a1 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Doctor message — left-aligned, visually distinct from bot */
.mdg-msg--doctor {
    align-self: flex-start;
}

.mdg-msg--doctor p {
    background: #eff6ff;
    color: #1e3a5f;
    border: 1px solid #bfdbfe;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.mdg-msg--doctor::before {
    content: 'Doctor';
    font-size: 10.5px;
    font-weight: 600;
    color: #2563eb;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin-bottom: 3px;
    display: block;
}

/* ── Quick reply option buttons ────────────────────────────── */

.mdg-options {
    align-self: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.mdg-option-btn {
    background: #fff;
    border: 1.5px solid #0369a1;
    color: #0369a1;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12.5px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}

.mdg-option-btn:hover {
    background: #0369a1;
    color: #fff;
}

/* ── Countdown bubble ──────────────────────────────────────── */

.mdg-countdown p {
    font-style: italic;
    color: #64748b;
}

/* ── Typing indicator ──────────────────────────────────────── */

.mdg-msg--bot.mdg-typing p {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 14px 16px;
    min-width: 56px;
}

.mdg-typing span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    display: inline-block;
    animation: mdgBounce 1.2s infinite ease-in-out;
}

.mdg-typing span:nth-child(2) { animation-delay: 0.2s; }
.mdg-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes mdgBounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.5; }
    30%           { transform: translateY(-5px); opacity: 1;   }
}

/* ── Input area ────────────────────────────────────────────── */

#mdg-chat-input {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    gap: 8px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}

#mdg-chat-msg {
    flex: 1;
    border: 1.5px solid #cbd5e1;
    border-radius: 22px;
    padding: 9px 15px;
    font-size: 13.5px;
    outline: none;
    background: #f8fafc;
    color: #1e293b;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
    min-width: 0;
}

#mdg-chat-msg:focus {
    border-color: #0d9488;
    background: #fff;
}

#mdg-chat-msg:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#mdg-chat-send {
    background: linear-gradient(135deg, #0d9488 0%, #0369a1 100%);
    color: #fff;
    border: none;
    border-radius: 22px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

#mdg-chat-send:hover {
    opacity: 0.9;
}

#mdg-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
