/* ═══════════════════════════════════════════════════════════════════════════
   Mind Psychology – Floating Chat Widget Styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* ---------- CSS Variables (theming) ---------- */
:root {
    --mp-primary: #2E7A8C;
    --mp-primary-dark: #245F6D;
    --mp-primary-light: #E6F3F7;
    --mp-primary-tint: rgba(61, 139, 158, 0.08);
    --mp-accent: #5BAD8A;
    --mp-text: #1E2D3D;
    --mp-text-light: #566A78;
    --mp-bg: #FFFFFF;
    --mp-bg-light: #F5F8F9;
    --mp-border: #DDE5E8;
    --mp-shadow: rgba(0, 0, 0, 0.08);
    --mp-radius: 16px;
    --mp-widget-size: 60px;
    --mp-chat-width: 440px;
    --mp-chat-height: 640px;
}

/* ---------- Font family on widget root ---------- */
#mp-chat-wrapper,
#mp-chat-wrapper * {
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
}

/* ---------- Floating toggle button ---------- */
#mp-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--mp-widget-size);
    height: var(--mp-widget-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--mp-primary), var(--mp-primary-dark));
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--mp-shadow);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#mp-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.18);
}

#mp-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: #fff;
    stroke-width: 1.75;
    transition: opacity 0.25s ease;
}

#mp-chat-toggle .mp-close-icon { display: none; }
#mp-chat-toggle.active .mp-chat-icon { display: none; }
#mp-chat-toggle.active .mp-close-icon { display: block; }

/* Pulse animation for attention */
#mp-chat-toggle::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--mp-primary);
    opacity: 0;
    animation: mp-pulse 2.5s ease-out infinite;
}

#mp-chat-toggle.active::after { animation: none; opacity: 0; }

@keyframes mp-pulse {
    0%   { transform: scale(1);   opacity: 0.6; }
    100% { transform: scale(1.4); opacity: 0; }
}

/* ---------- Chat window ---------- */
#mp-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: var(--mp-chat-width);
    height: var(--mp-chat-height);
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
    background: var(--mp-bg);
    border-radius: var(--mp-radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mp-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ---------- Header ---------- */
.mp-chat-header {
    background: linear-gradient(135deg, #3D8B9E, #2E6F82);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Header action buttons (restart + home) */
#mp-restart-btn,
#mp-back-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.9);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s;
}

#mp-restart-btn { margin-left: auto; }

#mp-restart-btn:hover,
#mp-back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.mp-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.mp-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.mp-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #5BAD8A;
    border: 1.5px solid #2E6F82;
    animation: mp-status-pulse 3s ease-in-out infinite;
}

.mp-header-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.mp-header-info p {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.8;
}

/* ---------- Messages area ---------- */
.mp-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--mp-bg-light);
}

.mp-chat-messages::-webkit-scrollbar { width: 5px; }
.mp-chat-messages::-webkit-scrollbar-thumb { background: var(--mp-border); border-radius: 3px; }

/* ---------- Message bubbles ---------- */
.mp-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: mp-fadeIn 0.3s ease;
}

/* Bot messages with tables go full-width */
.mp-msg.bot.has-table {
    max-width: 100%;
}

@keyframes mp-fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.mp-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: var(--mp-text);
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border-radius: 16px;
    border-bottom-left-radius: 6px;
}

.mp-msg.user {
    align-self: flex-end;
    background: var(--mp-primary);
    color: #fff;
    border-radius: 16px;
    border-bottom-right-radius: 6px;
}

/* Bullet points inside bot messages */
.mp-msg.bot .mp-bullet {
    padding-left: 14px;
    margin: 0;
    line-height: 1.7;
}

/* Links inside bot messages */
.mp-msg.bot a {
    color: var(--mp-primary);
    text-decoration: underline;
    word-break: break-all;
}
.mp-msg.bot a:hover {
    text-decoration: none;
}

/* ---------- Tables inside bot messages ---------- */
.mp-msg.bot .mp-table-wrap {
    overflow-x: auto;
    margin: 4px 0 8px;
    border-radius: 8px;
    border: 1px solid var(--mp-border);
}

/* Section title above a table (e.g. "Clinical Psychologist") */
.mp-msg.bot .mp-table-wrap ~ strong,
.mp-msg.bot > strong:has(+ .mp-table-wrap) {
    display: block;
    margin-top: 10px;
    font-size: 13px;
    color: var(--mp-primary-dark);
}

.mp-msg.bot .mp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    min-width: 320px;
}

.mp-msg.bot .mp-table thead tr {
    background: linear-gradient(135deg, var(--mp-primary), var(--mp-primary-dark));
    color: #fff;
}

.mp-msg.bot .mp-table th {
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11.5px;
    white-space: nowrap;
}

.mp-msg.bot .mp-table td {
    padding: 7px 10px;
    border-top: 1px solid var(--mp-border);
    font-size: 12.5px;
    white-space: nowrap;
}

.mp-msg.bot .mp-table tbody tr:nth-child(even) {
    background: var(--mp-bg-light);
}

.mp-msg.bot .mp-table tbody tr:hover {
    background: var(--mp-primary-light);
}

/* ---------- FAQ follow-up chips ---------- */
.mp-faq-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
    animation: mp-fadeIn 0.3s ease;
}

.mp-faq-chip {
    background: var(--mp-primary-tint);
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--mp-primary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
    font-family: inherit;
}

.mp-faq-chip:hover {
    border-color: var(--mp-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(61, 139, 158, 0.15);
}

/* ---------- Typing indicator ---------- */
.mp-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #fff;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.mp-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mp-primary);
    opacity: 0.4;
    animation: mp-bounce 1.4s infinite ease-in-out;
}

.mp-typing span:nth-child(2) { animation-delay: 0.16s; }
.mp-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes mp-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

@keyframes mp-status-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(91, 173, 138, 0.5); }
    50%      { box-shadow: 0 0 0 4px rgba(91, 173, 138, 0); }
}

/* ---------- Quick actions ---------- */
.mp-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px 12px;
    background: var(--mp-bg-light);
}

.mp-quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--mp-primary-tint);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--mp-text);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
    font-family: inherit;
    text-align: left;
}

.mp-quick-btn:hover {
    border-color: var(--mp-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(61, 139, 158, 0.15);
}

.mp-quick-btn:active {
    transform: scale(0.97);
}

.mp-quick-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    color: var(--mp-primary);
    flex-shrink: 0;
}

.mp-quick-icon svg {
    width: 16px;
    height: 16px;
}

/* ---------- Compact quick actions (after first message) ---------- */
.mp-quick-actions.mp-compact {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 4px 8px;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.mp-quick-actions.mp-compact::-webkit-scrollbar { display: none; }
.mp-quick-actions.mp-compact .mp-quick-btn {
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 6px;
}
.mp-quick-actions.mp-compact .mp-quick-icon { display: none; }

/* ---------- Input area ---------- */
.mp-chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--mp-border);
    background: #fff;
    flex-shrink: 0;
}

.mp-chat-input input {
    flex: 1;
    border: 1px solid var(--mp-border);
    border-radius: 14px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.mp-chat-input input:focus {
    border-color: var(--mp-primary);
    box-shadow: 0 0 0 3px rgba(61, 139, 158, 0.1);
}

.mp-chat-input input::placeholder {
    color: var(--mp-text-light);
}

.mp-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--mp-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.mp-send-btn:hover { background: var(--mp-primary-dark); }
.mp-send-btn:disabled { background: var(--mp-border); cursor: not-allowed; }

.mp-send-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: #fff;
    stroke-width: 1.75;
}

/* ---------- Powered-by footer ---------- */
.mp-powered {
    text-align: center;
    font-size: 10px;
    color: var(--mp-text-light);
    padding: 4px 0 8px;
    background: #fff;
}

.mp-powered a {
    color: var(--mp-primary);
    text-decoration: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 440px) {
    #mp-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 120px);
        height: calc(100dvh - 120px);
        right: 8px;
        bottom: 88px;
        border-radius: 12px;
    }
    .mp-quick-actions {
        padding: 4px 8px;
    }
}

/* New client form inside chat bubble */
.mp-new-client-form {
    max-width: 92%;
    background: #fff;
    border: 1px solid var(--mp-border);
    padding: 14px;
    border-radius: 12px;
}
.mp-new-client-form .mp-form-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--mp-primary-dark);
    margin-bottom: 4px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--mp-primary-light);
}
.mp-new-client-form .mp-form-subtitle {
    font-size: 12px;
    color: var(--mp-text-light);
    margin-bottom: 12px;
    line-height: 1.5;
}
.mp-new-client-form .mp-form-section-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--mp-primary);
    margin: 12px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--mp-primary-light);
}
.mp-new-client-form .mp-form-row { margin: 8px 0; }
.mp-new-client-form label { display:block; font-size:13px; font-weight:600; color:var(--mp-text); margin-bottom:4px; }
.mp-new-client-form small { display:block; font-size:11px; color:var(--mp-text-light); margin-bottom:4px; line-height:1.4; }
.mp-new-client-form input,
.mp-new-client-form select,
.mp-new-client-form textarea {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1.5px solid var(--mp-border);
    font-size: 13px;
    font-family: inherit;
    color: var(--mp-text);
    background: #fff;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}
.mp-new-client-form input:focus,
.mp-new-client-form select:focus,
.mp-new-client-form textarea:focus {
    border-color: var(--mp-primary);
    box-shadow: 0 0 0 3px rgba(74,144,164,0.15);
}
.mp-new-client-form textarea { resize: vertical; min-height: 72px; }
.mp-new-client-form .mp-concern-row textarea {
    background: var(--mp-bg-light);
    border-style: solid;
    font-style: normal;
}
.mp-new-client-form .mp-concern-row textarea:focus {
    background: #fff;
    border-style: solid;
}
.mp-new-client-form input::placeholder,
.mp-new-client-form textarea::placeholder { color: #b0bec5; }
.mp-new-client-form .mp-optional { font-size: 11px; font-weight: 400; color: var(--mp-text-light); margin-left: 4px; }
.mp-new-client-form .mp-consent { padding-top:6px; }
.mp-new-client-form .mp-consent label {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    cursor: pointer;
    color: var(--mp-text);
}
.mp-new-client-form .mp-consent input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0;
    flex: 0 0 20px;
    accent-color: var(--mp-primary);
}
.mp-new-client-form .mp-form-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:8px; }
.mp-new-client-form .mp-form-submit { background:var(--mp-primary); color:#fff; border:none; padding:10px 16px; border-radius:8px; cursor:pointer; }
.mp-new-client-form .mp-form-cancel { background:#fff; border:1px solid var(--mp-border); padding:10px 16px; border-radius:8px; cursor:pointer; }

/* ---------- Crisis message (Phase 1) ---------- */
.mp-msg.bot.mp-crisis {
    border-left: 3px solid #D97706;
    background: #FFFBEB;
}

/* ---------- Privacy note (Phase 1) ---------- */
.mp-privacy-note {
    font-size: 10px;
    color: var(--mp-text-light);
    text-align: center;
    padding: 2px 0 4px;
    opacity: 0.7;
}
.mp-privacy-note a {
    color: var(--mp-primary);
    text-decoration: underline;
}

/* ---------- Form error (Phase 1) ---------- */
.mp-form-error {
    font-size: 11px;
    color: #B91C1C;
    padding: 4px 8px;
    background: #FEF2F2;
    border-radius: 6px;
    margin-top: 4px;
}

/* ---------- Per-field validation errors ---------- */
.mp-field-invalid {
    border-color: #DC2626 !important;
    box-shadow: 0 0 0 1px #DC2626 !important;
}
.mp-field-hint {
    display: block;
    font-size: 11px;
    color: #DC2626;
    margin-top: 2px;
}
/* Checkbox consent error — highlight the label text */
.mp-consent .mp-field-invalid + span,
.mp-consent label:has(.mp-field-invalid) {
    color: #DC2626;
}

/* ---------- Message timestamps (Phase 2) ---------- */
.mp-msg-time {
    font-size: 9px;
    color: var(--mp-text-light);
    opacity: 0.5;
    margin-top: 4px;
    display: block;
}
.mp-msg.user .mp-msg-time { text-align: right; }
.mp-msg.bot .mp-msg-time { text-align: left; }

/* ---------- Form submit spinner (Phase 2) ---------- */
.mp-btn-loading {
    position: relative;
}
.mp-btn-loading::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 6px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mp-spin 0.6s linear infinite;
    vertical-align: middle;
}
@keyframes mp-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Color contrast fixes (Phase 4) ---------- */
/* --mp-text-light #566A78 on white = ~5.0:1 — passes AA */
/* Input placeholder #b0bec5 on white = ~2.7:1 — FAILS, darken */
.mp-new-client-form input::placeholder,
.mp-new-client-form textarea::placeholder { color: #78909C; }
.mp-chat-input input::placeholder { color: #78909C; }
/* .mp-powered 10px text — darken slightly for small text AA */
.mp-powered { color: #4A5E6D; }

/* ---------- Focus-visible indicators (Phase 4) ---------- */
.mp-faq-chip:focus-visible,
.mp-quick-btn:focus-visible,
.mp-send-btn:focus-visible,
#mp-back-btn:focus-visible,
#mp-restart-btn:focus-visible {
    outline: 2px solid var(--mp-primary);
    outline-offset: 2px;
}

/* ---------- Tablet responsive breakpoint (Phase 4) ---------- */
@media (max-width: 768px) {
    #mp-chat-window {
        width: min(var(--mp-chat-width), calc(100vw - 24px));
    }
}

/* ---------- Safe-area-inset for notched phones (Phase 4) ---------- */
@supports (padding: env(safe-area-inset-bottom)) {
    #mp-chat-toggle {
        bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    }
    #mp-chat-window {
        bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    }
}

