﻿* { box-sizing: border-box; }
        body {
            margin: 0;
            font-family: 'Nunito', -apple-system, Segoe UI, Roboto, sans-serif;
            min-height: 100vh;
            background: linear-gradient(135deg, #0f3d2e 0%, #1f6b4a 45%, #2bb673 100%);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 18px;
        }

        /* Soft floating blobs in the background */
        body::before, body::after {
            content: '';
            position: fixed;
            border-radius: 50%;
            filter: blur(8px);
            opacity: 0.18;
            z-index: 0;
        }
        body::before { width: 320px; height: 320px; background: #c0d966; top: -80px; left: -60px; }
        body::after  { width: 280px; height: 280px; background: #66d998; bottom: -70px; right: -50px; }

        .pt-wrap { width: 100%; max-width: 820px; position: relative; z-index: 1; }

        .consult-banner { position: relative; width: 100%; max-height: 72px; overflow: hidden; }
        .consult-banner img { width: 100%; height: 72px; object-fit: cover; display: block; }
        .consult-banner-overlay {
            position: absolute; inset: 0;
            background: linear-gradient(180deg, rgba(15,61,46,0.15) 0%, rgba(15,61,46,0.55) 100%);
            display: flex; align-items: flex-end; padding: 12px 18px;
        }
        .consult-banner-overlay span {
            color: #fff; font-weight: 800; font-size: 14px; letter-spacing: 0.3px;
            text-shadow: 0 1px 4px rgba(0,0,0,0.4);
        }

        .pt-avatar-img, .chat-avatar-img {
            width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
        }
        .consent-logo { width: 72px; height: 72px; object-fit: contain; margin: 0 auto 14px; display: block; }

        .intake-progress {
            display: flex; gap: 6px; padding: 8px 14px;
            background: #f0faf4; border-bottom: 1px solid #d7efe3;
            overflow-x: auto;
        }
        .intake-step {
            flex: 1; min-width: 70px; text-align: center; font-size: 10px; font-weight: 700;
            padding: 6px 6px; border-radius: 8px; color: #8a978f;
            background: #fff; border: 1px solid #e2ebe6;
        }
        .intake-step i { display: block; font-size: 14px; margin-bottom: 3px; }
        .intake-step.active { background: #eafff3; color: #0f7a52; border-color: #2bb673; }
        .intake-step.done { background: #2bb673; color: #fff; border-color: #2bb673; }

        .pt-card {
            background: #fff;
            border-radius: 22px;
            box-shadow: 0 30px 70px rgba(8,40,28,0.45);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            max-height: min(88vh, 680px);
        }

        /* Header */
        .pt-header {
            background: linear-gradient(135deg, #0f7a52 0%, #2bb673 60%, #66d998 100%);
            color: #fff;
            padding: 14px 22px;
            display: flex;
            align-items: center;
            gap: 14px;
            flex-wrap: wrap;
        }
        .pt-avatar {
            position: relative;
            width: 52px; height: 52px;
            border-radius: 50%;
            background: rgba(255,255,255,0.18);
            border: 2px solid rgba(255,255,255,0.5);
            display: flex; align-items: center; justify-content: center;
            font-size: 24px; color: #fff; flex-shrink: 0;
        }
        .pt-online {
            position: absolute; right: 0; bottom: 0;
            width: 14px; height: 14px; border-radius: 50%;
            background: #36e07f; border: 2px solid #0f7a52;
            box-shadow: 0 0 0 0 rgba(54,224,127,0.7);
            animation: onlinePulse 1.8s infinite;
        }
        @keyframes onlinePulse {
            0% { box-shadow: 0 0 0 0 rgba(54,224,127,0.6); }
            70% { box-shadow: 0 0 0 8px rgba(54,224,127,0); }
            100% { box-shadow: 0 0 0 0 rgba(54,224,127,0); }
        }
        .pt-titles h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: 0.2px; }
        .pt-titles p { margin: 2px 0 0; font-size: 12.5px; opacity: 0.92; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

        .lang-toggle {
            display: flex;
            align-items: center;
            gap: 6px;
            flex-shrink: 0;
        }
        .lang-toggle-label {
            font-size: 11px;
            font-weight: 700;
            opacity: 0.9;
            margin-right: 2px;
        }
        .lang-toggle-btn {
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.2px;
            padding: 6px 12px;
            border-radius: 20px;
            border: 1px solid rgba(255,255,255,0.45);
            background: rgba(255,255,255,0.12);
            color: #fff;
            cursor: pointer;
            transition: background 0.15s ease, border-color 0.15s ease;
        }
        .lang-toggle-btn:hover {
            background: rgba(255,255,255,0.22);
        }
        .lang-toggle-btn.active {
            background: #fff;
            color: #0f7a52;
            border-color: #fff;
        }
        .consent-lang {
            justify-content: center;
            margin: 14px 0 4px;
        }
        .consent-lang .lang-toggle-label {
            color: #5a7a68;
            opacity: 1;
        }
        .consent-lang .lang-toggle-btn {
            border-color: #cfe9d8;
            background: #f3fbf6;
            color: #0f7a52;
        }
        .consent-lang .lang-toggle-btn.active {
            background: #0f7a52;
            color: #fff;
            border-color: #0f7a52;
        }
        .lang-new-btn {
            padding: 6px 10px !important;
            min-width: 36px;
        }

        .patient-ref-banner {
            background: #f0faf4;
            border-bottom: 1px solid #d7efe3;
            padding: 10px 18px;
        }
        .ref-main {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;
            gap: 14px;
            flex-wrap: wrap;
        }
        .ref-info { flex: 1; min-width: 160px; }
        .ref-qr-block {
            text-align: center;
            flex-shrink: 0;
        }
        .ref-qr-block canvas {
            display: block;
            border-radius: 8px;
            border: 1px solid #cfe9d8;
            background: #fff;
            padding: 4px;
        }
        .ref-qr-label {
            display: block;
            font-size: 10px;
            font-weight: 700;
            color: #5a7a68;
            margin-top: 4px;
            text-transform: uppercase;
            letter-spacing: 0.3px;
        }
        .patient-ref-banner .ref-label {
            display: block;
            font-size: 11px;
            font-weight: 700;
            color: #5a7a68;
            text-transform: uppercase;
            letter-spacing: 0.4px;
        }
        .patient-ref-banner .ref-code {
            display: block;
            font-size: 18px;
            font-weight: 800;
            color: #0f7a52;
            font-family: ui-monospace, Consolas, monospace;
            letter-spacing: 0.5px;
        }
        .patient-ref-banner .ref-hint {
            display: block;
            font-size: 11.5px;
            color: #7a9488;
            margin-top: 2px;
        }
        .ref-actions { display: flex; gap: 8px; flex-shrink: 0; margin-top: 10px; }
        .ref-sms-form {
            display: flex;
            gap: 8px;
            margin-top: 10px;
            align-items: center;
        }
        .ref-phone-input {
            flex: 1;
            height: 40px;
            border: 1.5px solid #cfe9d8;
            border-radius: 8px;
            padding: 0 12px;
            font-size: 14px;
            background: #fff;
            font-family: inherit;
        }
        .ref-phone-input:focus {
            outline: none;
            border-color: #2bb673;
            box-shadow: 0 0 0 3px rgba(43,182,115,0.12);
        }
        .ref-sms-btn {
            height: 40px;
            padding: 0 14px;
            border-radius: 8px;
            border: none;
            background: linear-gradient(135deg,#0f7a52,#2bb673);
            color: #fff;
            font-weight: 700;
            font-size: 12px;
            cursor: pointer;
            white-space: nowrap;
        }
        .ref-sms-btn:disabled { opacity: 0.6; cursor: not-allowed; }
        .ref-sms-error, .ref-sms-success {
            font-size: 12px;
            margin-top: 8px;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .ref-sms-error { color: #c0282f; }
        .ref-sms-success { color: #0f7a52; font-weight: 700; }

        /* History page (AJAX) */
        .hist-page { padding: 24px; max-width: 640px; margin: 0 auto; }
        .hist-title { color: #0f7a52; margin: 0 0 8px; font-size: 20px; }
        .hist-sub { color: #666; font-size: 14px; margin-bottom: 20px; }
        .hist-form { display: flex; gap: 10px; margin-bottom: 24px; }
        .hist-form input {
            flex: 1; height: 48px; border: 1.5px solid #e2e8e4; border-radius: 10px;
            padding: 0 14px; font-size: 15px;
        }
        .hist-form button {
            height: 48px; padding: 0 20px; background: #2bb673; color: #fff;
            border: none; border-radius: 10px; font-weight: 700; cursor: pointer;
        }
        .hist-form button:disabled { opacity: 0.65; }
        .hist-summary {
            background: #eafff3; border: 1px solid #cfe9d8; border-radius: 10px;
            padding: 14px; margin-bottom: 16px;
        }
        .hist-card {
            background: #fff; border: 1px solid #eef2ef; border-radius: 10px;
            padding: 14px; margin-bottom: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.04);
        }
        .hist-card-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
        .hist-card-head .risk-red { color: #e8404a; }
        .hist-card-head .risk-yellow { color: #f0ad4e; }
        .hist-card-head .risk-green { color: #2bb673; }
        .hist-card-head small { color: #888; }
        .hist-card-body { font-size: 14px; color: #333; }
        .hist-alert { padding: 12px; border-radius: 8px; margin-bottom: 16px; }
        .hist-alert-error { background: #fff5f5; border: 1px solid #f6c9cc; color: #c0282f; }
        .hist-empty { color: #888; }
        .hist-back { text-align: center; margin-top: 24px; }
        .hist-back a { color: #2bb673; font-weight: 700; }
        .ref-copy, .ref-history {
            font-size: 12px;
            font-weight: 700;
            padding: 7px 12px;
            border-radius: 8px;
            border: 1px solid #cfe9d8;
            background: #fff;
            color: #0f7a52;
            cursor: pointer;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 5px;
        }
        .ref-copy:hover, .ref-history:hover { background: #eafff3; }

        /* Chat window */
        .chat-window {
            background: #f3f7f4;
            padding: 14px 20px;
            flex: 1 1 auto;
            min-height: 180px;
            max-height: 300px;
            overflow-y: auto;
        }
        .chat-row { display: flex; align-items: flex-end; margin-bottom: 16px; }
        .chat-row.doctor { justify-content: flex-start; }
        .chat-row.patient { justify-content: flex-end; }
        .chat-avatar {
            width: 36px; height: 36px; border-radius: 50%;
            display: flex; align-items: center; justify-content: center;
            color: #fff; font-size: 15px; flex-shrink: 0;
        }
        .chat-avatar.doctor { background: linear-gradient(135deg,#2bb673,#66d998); margin-right: 10px; }
        .chat-avatar.patient { background: linear-gradient(135deg,#2f80ed,#56ccf2); margin-left: 10px; }
        .chat-bubble {
            max-width: 74%; padding: 12px 16px; border-radius: 16px;
            font-size: 14.5px; line-height: 1.55; box-shadow: 0 2px 6px rgba(0,0,0,0.06);
        }
        .chat-bubble.doctor { background: #fff; color: #1f2d28; border-bottom-left-radius: 5px; }
        .chat-bubble.patient { background: linear-gradient(135deg,#2bb673,#239e63); color: #fff; border-bottom-right-radius: 5px; }
        .chat-bubble.doctor.red { border: 2px solid #e8404a; background: #fff5f5; }
        .chat-bubble.doctor.yellow { border: 2px solid #f0ad4e; background: #fffaf0; }
        .risk-flag {
            background: #e8404a; color: #fff; font-weight: 700; font-size: 11.5px;
            padding: 4px 9px; border-radius: 6px; margin-bottom: 8px; display: inline-block;
        }
        .btn-speak {
            display: inline-flex; align-items: center; justify-content: center;
            width: 28px; height: 28px; border-radius: 50%;
            border: none; background: #2bb673; color: #fff; cursor: pointer;
            font-size: 11px; flex-shrink: 0;
        }
        .btn-speak:hover { background: #239e63; }

        .msg-voice {
            margin-top: 10px; padding-top: 10px;
            border-top: 1px dashed #d7ebe1;
        }
        .msg-voice-head {
            display: flex; align-items: center; justify-content: space-between;
            gap: 8px; margin-bottom: 6px;
        }
        .msg-voice-label {
            display: inline-flex; align-items: center; gap: 6px;
            font-size: 12px; font-weight: 700; color: #0f7a52;
        }
        .msg-voice .msg-audio {
            width: 100%; height: 36px; border-radius: 8px;
        }
        .msg-voice .msg-audio::-webkit-media-controls-panel {
            background: #f0faf5;
        }

        /* Speaking indicator */
        .speaking-indicator {
            display: none;
            align-items: center; gap: 8px;
            padding: 8px 16px; font-size: 13px; color: #0f7a52; font-weight: 700;
            background: #eafff3; border-top: 1px solid #d7f0e1;
        }
        .speaking-indicator.active { display: flex; }
        .sound-wave { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
        .sound-wave span {
            width: 3px; height: 100%; background: #2bb673; border-radius: 2px;
            animation: wave 1s infinite ease-in-out;
        }
        .sound-wave span:nth-child(2) { animation-delay: 0.15s; }
        .sound-wave span:nth-child(3) { animation-delay: 0.3s; }
        .sound-wave span:nth-child(4) { animation-delay: 0.45s; }
        @keyframes wave { 0%,100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }

        /* Input bar */
        .chat-input-area { padding: 12px 16px 14px; background: #fff; flex-shrink: 0; }
        .chat-input-bar { display: flex; gap: 10px; align-items: center; }
        .chat-input-bar .form-control {
            flex: 1; height: 46px; border: 1.5px solid #e2e8e4; border-radius: 25px;
            padding: 0 18px; font-size: 14.5px; background: #f6faf7; outline: none;
            transition: border-color 0.2s, background 0.2s; font-family: inherit;
        }
        .chat-input-bar .form-control:focus { border-color: #2bb673; background: #fff; box-shadow: 0 0 0 4px rgba(43,182,115,0.15); }
        .icon-btn {
            width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
            display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff;
            flex-shrink: 0; transition: transform 0.15s, filter 0.2s;
        }
        .icon-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
        .icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
        .btn-mic { background: #2bb673; }
        .btn-mic.listening { background: #e8404a; animation: micpulse 1s infinite; }
        .btn-send { background: linear-gradient(135deg,#0f7a52,#2bb673); }
        @keyframes micpulse {
            0% { box-shadow: 0 0 0 0 rgba(232,64,74,0.6); }
            70% { box-shadow: 0 0 0 14px rgba(232,64,74,0); }
            100% { box-shadow: 0 0 0 0 rgba(232,64,74,0); }
        }
        .mic-hint { font-size: 12px; color: #8a978f; margin: 8px 4px 0; text-align: center; }
        .mic-hint.active { color: #e8404a; font-weight: 700; }

        /* End Consultation button */
        .btn-end-consult {
            display: inline-flex; align-items: center; gap: 6px;
            padding: 0 14px; height: 34px; border-radius: 8px; border: none;
            background: linear-gradient(135deg, #c0392b, #e74c3c);
            color: #fff; font-size: 12.5px; font-weight: 700; font-family: inherit;
            cursor: pointer; white-space: nowrap;
            transition: filter 0.15s, transform 0.15s;
        }
        .btn-end-consult:hover { filter: brightness(1.08); transform: translateY(-1px); }
        .btn-end-consult:disabled { opacity: 0.6; cursor: wait; }

        /* Ended overlay */
        .ended-overlay {
            position: absolute; inset: 0; z-index: 60;
            display: flex; align-items: center; justify-content: center;
            padding: 20px; background: rgba(15, 61, 46, 0.55);
            backdrop-filter: blur(4px);
        }
        .ended-card {
            background: #fff; border-radius: 20px; max-width: 400px; width: 100%;
            padding: 32px 24px; box-shadow: 0 24px 60px rgba(0,0,0,0.25);
            text-align: center;
        }
        .ended-logo { width: 64px; height: 64px; object-fit: contain; margin-bottom: 16px; border-radius: 12px; }
        .ended-icon {
            width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%;
            background: linear-gradient(135deg, #eafff3, #cfe9d8);
            display: flex; align-items: center; justify-content: center;
            font-size: 30px; color: #0f7a52;
        }
        .ended-card h2 { margin: 0 0 12px; font-size: 20px; color: #0f7a52; font-weight: 800; }
        .ended-card p { margin: 0 0 18px; font-size: 13.5px; line-height: 1.6; color: #444; }
        .ended-ref {
            display: flex; flex-direction: column; gap: 4px; margin-bottom: 22px;
            background: #f0faf5; border: 1px solid #c5e8d4; border-radius: 10px; padding: 12px 16px;
        }
        .ended-ref-label { font-size: 11px; color: #6a9e82; text-transform: uppercase; letter-spacing: 0.5px; }
        .ended-ref-code { font-size: 20px; font-weight: 900; color: #0f7a52; letter-spacing: 2px; }
        .ended-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
        .ended-btn-history, .ended-btn-new {
            display: inline-flex; align-items: center; gap: 6px;
            padding: 0 18px; height: 42px; border-radius: 10px;
            font-size: 13.5px; font-weight: 700; font-family: inherit; cursor: pointer;
            transition: filter 0.15s, transform 0.15s; text-decoration: none;
        }
        .ended-btn-history:hover, .ended-btn-new:hover { filter: brightness(1.07); transform: translateY(-1px); }
        .ended-btn-history {
            background: #f0faf5; color: #0f7a52;
            border: 2px solid #2bb673;
        }
        .ended-btn-new {
            background: linear-gradient(135deg, #0f7a52, #2bb673);
            color: #fff; border: none;
        }

        .pt-foot { text-align: center; color: rgba(255,255,255,0.85); font-size: 12.5px; margin-top: 16px; }
        .pt-foot a { color: #eaffe9; font-weight: 700; text-decoration: underline; }

        .hist-back a { color: #2bb673; font-weight: 700; }

        /* Consent overlay */
        .consult-shell {
            position: relative;
            display: flex;
            flex-direction: column;
            flex: 1 1 auto;
            min-height: 0;
            overflow: hidden;
        }
        .consult-shell.consult-locked .pt-header,
        .consult-shell.consult-locked .patient-ref-banner,
        .consult-shell.consult-locked .chat-window,
        .consult-shell.consult-locked .speaking-indicator,
        .consult-shell.consult-locked .chat-input-area {
            filter: blur(3px);
            pointer-events: none;
            user-select: none;
        }
        .consent-overlay {
            position: absolute; inset: 0; z-index: 50;
            display: flex; align-items: center; justify-content: center;
            padding: 20px; background: rgba(15, 61, 46, 0.45);
        }
        .consent-card {
            background: #fff; border-radius: 16px; max-width: 420px; width: 100%;
            padding: 18px 22px; box-shadow: 0 20px 50px rgba(0,0,0,0.2);
            text-align: center;
        }
        .consent-icon {
            width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
            background: linear-gradient(135deg,#eafff3,#cfe9d8);
            display: flex; align-items: center; justify-content: center;
            font-size: 26px; color: #0f7a52;
        }
        .consent-card h2 { margin: 0 0 10px; font-size: 18px; color: #0f7a52; }
        .consent-card p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.55; color: #444; text-align: left; }
        .consent-desc { margin-bottom: 12px !important; }
        .consent-note { font-size: 12px !important; color: #666 !important; margin-bottom: 16px !important; font-style: italic; }
        .consent-btn {
            width: 100%; height: 44px; border: none; border-radius: 10px; cursor: pointer;
            background: linear-gradient(135deg,#0f7a52,#2bb673); color: #fff;
            font-weight: 800; font-size: 14px; font-family: inherit;
        }
        .consent-btn:disabled { opacity: 0.7; cursor: wait; }

        @media (max-width: 600px) {
            body { padding: 0; }
            .pt-card { border-radius: 0; min-height: 100vh; max-height: none; }
            .pt-wrap { max-width: 100%; }
            .chat-window { max-height: none; min-height: calc(100vh - 300px); }
            .chat-bubble { max-width: 82%; }
            .pt-foot { margin: 12px 0; }
        }
