/* ==========================================================================
   Akıllı Asistan penceresi
   Masaüstünde sağ altta açılır pencere, mobilde tam ekran sayfa.
   ========================================================================== */

.ai-panel {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    visibility: hidden;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity var(--duration) var(--ease-out),
                transform var(--duration) var(--ease-out),
                visibility var(--duration);
}

.ai-panel[data-open="true"] {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

/* --- Başlık --- */
.ai-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: linear-gradient(135deg, var(--primary-700), var(--primary-900));
    color: #fff;
    flex-shrink: 0;
}

.ai-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.15);
    font-size: 1.3rem;
    flex-shrink: 0;
}

.ai-title { flex: 1; min-width: 0; line-height: 1.25; }

.ai-title strong {
    display: block;
    font-size: var(--text-base);
    font-weight: var(--weight-bold);
}

.ai-title span {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.75);
}

.ai-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

.ai-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--duration-fast) var(--ease-out);
}

.ai-close:hover { background: rgba(255, 255, 255, 0.24); }

/* --- Mesaj akışı --- */
.ai-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-5);
    background: var(--surface-sunken);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    scroll-behavior: smooth;
}

.ai-msg {
    display: flex;
    max-width: 88%;
    animation: ag-msg-in var(--duration) var(--ease-out);
}

.ai-msg-bubble {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ai-msg.is-assistant { align-self: flex-start; }

.ai-msg.is-assistant .ai-msg-bubble {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: var(--radius-xs);
    color: var(--ink-800);
    box-shadow: var(--shadow-xs);
}

.ai-msg.is-user { align-self: flex-end; }

.ai-msg.is-user .ai-msg-bubble {
    background: var(--primary-600);
    border-bottom-right-radius: var(--radius-xs);
    color: #fff;
}

.ai-msg.is-emergency { max-width: 100%; }

.ai-msg.is-emergency .ai-msg-bubble {
    background: var(--danger-100);
    border: 1.5px solid var(--danger-600);
    color: #7f1a14;
    font-weight: var(--weight-medium);
}

@keyframes ag-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Yazıyor göstergesi --- */
.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-xs);
    align-self: flex-start;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ink-300);
    animation: ag-typing 1.3s ease-in-out infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.18s; }
.ai-typing span:nth-child(3) { animation-delay: 0.36s; }

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

/* --- Seçenek kartları --- */
.ai-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    align-self: flex-start;
    width: 100%;
    max-width: 92%;
}

/* Doktortakvimi modunda randevu sayfasına yönlendiren düğme. */
.ai-booking-link {
    align-self: flex-start;
    width: auto;
    max-width: 92%;
}

.ai-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-800);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    text-align: left;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.ai-option:hover:not(:disabled) {
    border-color: var(--primary-400);
    background: var(--primary-050);
    color: var(--primary-800);
    transform: translateX(2px);
}

.ai-option:disabled { opacity: 0.5; cursor: not-allowed; }

.ai-option small {
    display: block;
    margin-top: 2px;
    font-weight: var(--weight-regular);
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.ai-option i { color: var(--primary-500); flex-shrink: 0; }

/* Tarih ve saat ızgarası */
.ai-chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--space-2);
    align-self: flex-start;
    width: 100%;
    max-width: 92%;
}

.ai-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--space-3) var(--space-2);
    min-height: 56px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-800);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.ai-chip:hover:not(:disabled) {
    border-color: var(--primary-500);
    background: var(--primary-050);
    color: var(--primary-800);
}

.ai-chip.is-selected {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: #fff;
}

.ai-chip small {
    font-size: var(--text-2xs);
    font-weight: var(--weight-regular);
    color: var(--text-muted);
}

.ai-chip.is-selected small { color: rgba(255, 255, 255, 0.8); }

.ai-chip:disabled { opacity: 0.45; cursor: not-allowed; }

/* --- Gömülü form (hasta bilgileri) --- */
.ai-form {
    align-self: stretch;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.ai-form .form-group { margin-bottom: var(--space-3); }
.ai-form .form-label { font-size: var(--text-xs); }
.ai-form .form-control { min-height: 44px; font-size: var(--text-sm); padding: 0.6rem 0.85rem; }
.ai-form textarea.form-control { min-height: 76px; }

/* --- Randevu özeti --- */
.ai-summary {
    align-self: stretch;
    padding: var(--space-5);
    background: var(--surface);
    border: 1.5px solid var(--primary-300);
    border-radius: var(--radius-md);
}

.ai-summary h4 {
    margin-bottom: var(--space-4);
    font-size: var(--text-base);
    color: var(--primary-800);
}

.ai-summary-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: 1px dashed var(--border);
    font-size: var(--text-sm);
}

.ai-summary-row:last-of-type { border-bottom: 0; }

.ai-summary-row dt { color: var(--text-muted); flex-shrink: 0; }

.ai-summary-row dd {
    margin: 0;
    font-weight: var(--weight-semibold);
    color: var(--ink-800);
    text-align: right;
}

/* --- Başarı kartı --- */
.ai-success {
    align-self: stretch;
    padding: var(--space-6);
    background: var(--success-100);
    border: 1.5px solid var(--success-600);
    border-radius: var(--radius-md);
    text-align: center;
}

.ai-success .number {
    display: inline-block;
    margin: var(--space-3) 0;
    padding: var(--space-3) var(--space-5);
    background: var(--surface);
    border: 1px dashed var(--success-600);
    border-radius: var(--radius);
    font-family: ui-monospace, monospace;
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    letter-spacing: 0.06em;
    color: var(--success-600);
}

/* --- Hızlı eylemler --- */
.ai-quick {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: var(--surface);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    overflow-x: auto;
}

.ai-quick-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    color: var(--ink-700);
    font-family: inherit;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.ai-quick-btn:hover {
    border-color: var(--primary-400);
    background: var(--primary-050);
    color: var(--primary-800);
}

/* --- Girdi alanı --- */
.ai-input-area {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    /* Mobil tarayıcı çubuğunun altında kalmasın */
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
}

.ai-input {
    flex: 1;
    min-height: 46px;
    max-height: 120px;
    padding: 0.7rem 1rem;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface);
    font-family: inherit;
    font-size: var(--text-base);
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
}

.ai-input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-100);
    outline: none;
}

.ai-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 50%;
    background: var(--primary-600);
    color: #fff;
    font-size: 1.15rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--duration-fast) var(--ease-out);
}

.ai-send:hover:not(:disabled) { background: var(--primary-700); }
.ai-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* --- Yasal not --- */
.ai-legal {
    padding: var(--space-2) var(--space-5) var(--space-3);
    background: var(--surface);
    font-size: var(--text-2xs);
    line-height: 1.45;
    color: var(--text-muted);
    text-align: center;
    flex-shrink: 0;
}

/* ==========================================================================
   Masaüstü: sağ altta açılır pencere
   ========================================================================== */

@media (min-width: 576px) {
    .ai-panel {
        inset: auto;
        right: clamp(0.875rem, 3vw, 1.5rem);
        bottom: calc(clamp(0.875rem, 3vw, 1.5rem) + 68px);
        width: 400px;
        height: min(620px, calc(100vh - 140px));
        border-radius: var(--radius-lg);
        border: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
        overflow: hidden;
    }

    body[data-cookie-banner="visible"] .ai-panel {
        transform: translateY(calc(-1 * var(--cookie-banner-height, 0px)));
    }

    body[data-cookie-banner="visible"] .ai-panel[data-open="true"] {
        transform: translateY(calc(-1 * var(--cookie-banner-height, 0px)));
    }
}

@media (min-width: 992px) {
    .ai-panel { width: 430px; height: min(680px, calc(100vh - 150px)); }
}

/* Mobilde panel açıkken arka planın kaymasını engelle */
body.ai-open { overflow: hidden; }

@media (min-width: 576px) {
    body.ai-open { overflow: auto; }
}

/* Yanıtın altındaki görselli bilgi kartı (ör. vajinoplasti rehberi şeması). */
.ai-visual {
    align-self: flex-start;
    max-width: 92%;
    margin: 0;
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.ai-visual img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: calc(var(--radius) - 2px);
}

.ai-visual figcaption {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-1) var(--space-1);
    color: var(--ink-700);
    font-size: var(--text-xs);
    line-height: 1.45;
}

.ai-visual-link {
    color: var(--primary-700);
    font-weight: var(--weight-bold);
    text-decoration: underline;
    text-underline-offset: 2px;
}
