/* Kalibrasyon Cüzdanı — AI sayfaları mobil/PWA katmanı */
:root {
    --kc-ai-mobile-vh: 100dvh;
    --kc-ai-safe-bottom: env(safe-area-inset-bottom, 0px);
    --kc-ai-safe-top: env(safe-area-inset-top, 0px);
}

html.kc-ai-page,
body.kc-ai-page {
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
}

body.kc-ai-page .fi-main,
body.kc-ai-page .fi-main-ctn,
body.kc-ai-page .fi-page,
body.kc-ai-page .cw-main,
body.kc-ai-page .cw-content {
    min-width: 0;
    max-width: 100%;
}

body.kc-ai-page .kc-ai-wrap,
body.kc-ai-page .kc-aiq-wrap,
body.kc-ai-page .kc-aiu-wrap,
body.kc-ai-page .kc-audit-wrap {
    min-width: 0;
    max-width: 100%;
}

body.kc-ai-page .kc-ai-card,
body.kc-ai-page .kc-aiq-section,
body.kc-ai-page .kc-aiu-section,
body.kc-ai-page .kc-audit-card {
    min-width: 0;
}

body.kc-ai-page .kc-ai-preview-value,
body.kc-ai-page .kc-ai-history-title,
body.kc-ai-page .kc-ai-text,
body.kc-ai-page td,
body.kc-ai-page pre,
body.kc-ai-page code {
    overflow-wrap: anywhere;
    word-break: break-word;
}

body.kc-ai-page .kc-ai-markdown img,
body.kc-ai-page .kc-ai-attachment img {
    max-width: 100%;
    height: auto;
}

body.kc-ai-page .kc-ai-table-wrap,
body.kc-ai-page .kc-aiq-table-wrap,
body.kc-ai-page .kc-aiu-table-wrap {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
}

body.kc-ai-page .kc-ai-mobile-history-toggle {
    display: none;
    width: 100%;
    min-height: 44px;
    margin: 0 0 10px;
    padding: 10px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
    color: #0f172a;
    font: inherit;
    font-size: 13px;
    font-weight: 850;
    cursor: pointer;
}

.dark body.kc-ai-page .kc-ai-mobile-history-toggle,
body.dark.kc-ai-page .kc-ai-mobile-history-toggle {
    border-color: #4b5563;
    background: #172033;
    color: #f8fafc;
}

body.kc-ai-page .kc-ai-submit-loading {
    opacity: .72;
    pointer-events: none;
}

body.kc-ai-page .kc-ai-submit-loading::after {
    content: "…";
    margin-inline-start: 5px;
}

body.kc-ai-page .kc-pwa-install {
    transition: opacity .16s ease, transform .16s ease;
}

body.kc-ai-page .kc-pwa-install.kc-pwa-install--ai-inline {
    position: static !important;
    inset: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 10px !important;
    transform: none !important;
    box-shadow: 0 10px 24px rgba(0, 68, 148, .18);
}

body.kc-ai-page .kc-pwa-install.kc-pwa-install--ai-inline[data-visible="true"] {
    display: flex !important;
}

body.kc-ai-page.kc-ai-keyboard-open .kc-pwa-install,
body.kc-ai-page.kc-ai-keyboard-open .kc-pwa-toast {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(10px) !important;
}

@media (display-mode: standalone) {
    html.kc-ai-page,
    body.kc-ai-page {
        min-height: var(--kc-ai-mobile-vh);
    }

    body.kc-ai-page .fi-topbar,
    body.kc-ai-page .cw-topbar {
        padding-top: var(--kc-ai-safe-top);
    }
}

@media (max-width: 1100px) {
    body.kc-ai-page .kc-ai-wrap {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 12px !important;
    }

    body.kc-ai-page .kc-ai-side {
        position: static !important;
        top: auto !important;
        order: -1 !important;
        padding: 12px !important;
    }

    body.kc-ai-page .kc-ai-main {
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    body.kc-ai-page .kc-ai-history {
        max-height: none !important;
        min-width: 0;
    }

    body.kc-ai-page .kc-ai-preview {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body.kc-ai-page .kc-ai-bubble {
        max-width: 92% !important;
    }
}

@media (max-width: 767px) {
    body.kc-ai-page .fi-page-header,
    body.kc-ai-page .cw-page-header {
        margin-bottom: 12px;
    }

    body.kc-ai-page .fi-main,
    body.kc-ai-page .fi-main-ctn,
    body.kc-ai-page .fi-page,
    body.kc-ai-page .cw-content {
        padding-inline: 10px !important;
    }

    body.kc-ai-page .kc-ai-wrap,
    body.kc-ai-page .kc-aiq-wrap,
    body.kc-ai-page .kc-aiu-wrap,
    body.kc-ai-page .kc-audit-wrap {
        gap: 12px !important;
    }

    body.kc-ai-page .kc-ai-card,
    body.kc-ai-page .kc-aiq-card,
    body.kc-ai-page .kc-aiq-section,
    body.kc-ai-page .kc-aiu-card,
    body.kc-ai-page .kc-aiu-section,
    body.kc-ai-page .kc-audit-card,
    body.kc-ai-page [style*="border-radius:16px"],
    body.kc-ai-page [style*="border-radius: 16px"] {
        border-radius: 14px !important;
    }

    body.kc-ai-page .kc-ai-head,
    body.kc-ai-page .kc-ai-composer,
    body.kc-ai-page .kc-aiq-section-head,
    body.kc-ai-page .kc-aiq-section-body,
    body.kc-ai-page .kc-aiu-head,
    body.kc-ai-page .kc-aiu-body,
    body.kc-ai-page .kc-audit-card {
        padding: 12px !important;
    }

    body.kc-ai-page .kc-ai-title,
    body.kc-ai-page h2[style*="font-size:24px"],
    body.kc-ai-page h2[style*="font-size: 24px"],
    body.kc-ai-page h2[style*="font-size:22px"],
    body.kc-ai-page h2[style*="font-size: 22px"] {
        font-size: 19px !important;
        line-height: 1.25 !important;
    }

    body.kc-ai-page .kc-ai-info,
    body.kc-ai-page .kc-ai-alert,
    body.kc-ai-page .kc-ai-desc,
    body.kc-ai-page .kc-aiq-note,
    body.kc-ai-page .kc-aiu-note,
    body.kc-ai-page .kc-audit-muted {
        font-size: 12.5px !important;
        line-height: 1.5 !important;
    }

    body.kc-ai-page .kc-ai-main {
        min-height: calc(var(--kc-ai-mobile-vh) - 132px) !important;
    }

    body.kc-ai-page .kc-ai-messages {
        flex: 1 1 auto !important;
        width: 100% !important;
        min-height: 42dvh !important;
        max-height: 56dvh !important;
        padding: 12px !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }

    body.kc-ai-page .kc-ai-row {
        margin-bottom: 12px !important;
    }

    body.kc-ai-page .kc-ai-bubble {
        width: auto !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 11px 12px !important;
        border-radius: 15px !important;
    }

    body.kc-ai-page .kc-ai-meta {
        flex-wrap: wrap !important;
        gap: 5px !important;
        font-size: 9.5px !important;
        letter-spacing: .035em !important;
    }

    body.kc-ai-page .kc-ai-text,
    body.kc-ai-page .kc-ai-markdown {
        font-size: 13.5px !important;
        line-height: 1.62 !important;
    }

    body.kc-ai-page .kc-ai-markdown h2 {
        font-size: 16px !important;
    }

    body.kc-ai-page .kc-ai-markdown h3 {
        font-size: 14px !important;
    }

    body.kc-ai-page .kc-ai-markdown ul,
    body.kc-ai-page .kc-ai-markdown ol {
        margin-inline-start: 17px !important;
    }

    body.kc-ai-page .kc-ai-markdown table {
        min-width: 540px !important;
    }

    body.kc-ai-page .kc-ai-pending {
        margin: 10px 10px 0 !important;
        padding: 11px !important;
        border-radius: 14px !important;
    }

    body.kc-ai-page .kc-ai-pending-card {
        padding: 11px !important;
        border-radius: 13px !important;
    }

    body.kc-ai-page .kc-ai-action-row {
        position: static !important;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 8px !important;
        padding-top: 10px !important;
    }

    body.kc-ai-page .kc-ai-action-row form,
    body.kc-ai-page .kc-ai-action-row .kc-ai-btn {
        width: 100% !important;
    }

    body.kc-ai-page .kc-ai-btn,
    body.kc-ai-page .kc-ai-send,
    body.kc-ai-page .kc-aiq-button,
    body.kc-ai-page .kc-audit-button {
        min-height: 44px !important;
        touch-action: manipulation;
    }

    body.kc-ai-page .kc-ai-composer {
        position: sticky !important;
        bottom: 0 !important;
        z-index: 45 !important;
        padding-bottom: calc(12px + var(--kc-ai-safe-bottom)) !important;
        box-shadow: 0 -10px 30px rgba(15, 23, 42, .08);
    }

    body.kc-ai-page .kc-ai-textarea {
        min-height: 72px !important;
        max-height: 32dvh !important;
        padding: 11px 12px !important;
        font-size: 16px !important; /* iOS odak yakınlaştırmasını engeller */
        resize: none !important;
    }

    body.kc-ai-page .kc-ai-chips {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 7px !important;
        margin: 9px -2px !important;
        padding: 2px 2px 7px !important;
        overflow-x: auto !important;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    body.kc-ai-page .kc-ai-chips::-webkit-scrollbar {
        display: none;
    }

    body.kc-ai-page .kc-ai-chip {
        flex: 0 0 auto !important;
        min-height: 38px !important;
        scroll-snap-align: start;
        white-space: nowrap;
    }

    body.kc-ai-page .kc-ai-composer-bottom {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    body.kc-ai-page .kc-ai-file,
    body.kc-ai-page .kc-ai-file input,
    body.kc-ai-page .kc-ai-send {
        width: 100% !important;
        max-width: 100% !important;
    }

    body.kc-ai-page .kc-ai-send {
        min-height: 48px !important;
        font-size: 14px !important;
    }

    body.kc-ai-page .kc-ai-attachments {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
    }

    body.kc-ai-page .kc-ai-attachment,
    body.kc-ai-page .kc-ai-attachment img,
    body.kc-ai-page .kc-ai-attachment-name {
        width: 100% !important;
        max-width: 100% !important;
    }

    body.kc-ai-page .kc-ai-attachment img {
        aspect-ratio: 4 / 3;
        object-fit: cover;
    }

    body.kc-ai-page .kc-ai-side {
        padding: 10px !important;
    }

    body.kc-ai-page .kc-ai-mobile-history-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    body.kc-ai-page .kc-ai-history[data-mobile-collapsed="true"] {
        display: none !important;
    }

    body.kc-ai-page .kc-ai-history[data-mobile-collapsed="false"] {
        display: grid !important;
        grid-auto-flow: column;
        grid-auto-columns: minmax(220px, 82vw);
        gap: 8px !important;
        max-height: none !important;
        padding: 2px 0 7px;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    body.kc-ai-page .kc-ai-history-item {
        scroll-snap-align: start;
    }

    body.kc-ai-page .kc-ai-help {
        display: none !important;
    }

    body.kc-ai-page .kc-aiq-metrics,
    body.kc-ai-page .kc-aiu-card-grid,
    body.kc-ai-page .kc-audit-grid,
    body.kc-ai-page .kc-audit-two,
    body.kc-ai-page .kc-aiu-two,
    body.kc-ai-page .kc-aiq-command {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 10px !important;
    }

    body.kc-ai-page .kc-aiq-card,
    body.kc-ai-page .kc-aiu-card,
    body.kc-ai-page .kc-audit-stat {
        min-height: 0 !important;
        padding: 14px !important;
    }

    body.kc-ai-page .kc-aiq-card-value,
    body.kc-ai-page .kc-aiu-value,
    body.kc-ai-page .kc-audit-value {
        font-size: 25px !important;
    }

    body.kc-ai-page .kc-aiq-extra {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border: 0 !important;
        overflow: visible !important;
        background: transparent !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table thead {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0 0 0 0) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table tbody,
    body.kc-ai-page table.kc-ai-mobile-table tr,
    body.kc-ai-page table.kc-ai-mobile-table td {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table tr {
        margin: 0 0 10px !important;
        padding: 5px 10px !important;
        border: 1px solid #dbe4f0 !important;
        border-radius: 13px !important;
        background: #fff !important;
        box-shadow: 0 3px 12px rgba(15, 23, 42, .04);
    }

    body.dark.kc-ai-page table.kc-ai-mobile-table tr,
    .dark body.kc-ai-page table.kc-ai-mobile-table tr {
        border-color: #374151 !important;
        background: #111827 !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table td {
        display: grid !important;
        grid-template-columns: minmax(90px, 34%) minmax(0, 1fr) !important;
        gap: 9px !important;
        align-items: start !important;
        padding: 9px 0 !important;
        border: 0 !important;
        border-bottom: 1px solid #eef2f7 !important;
        background: transparent !important;
        font-size: 12.5px !important;
        white-space: normal !important;
    }

    body.dark.kc-ai-page table.kc-ai-mobile-table td,
    .dark body.kc-ai-page table.kc-ai-mobile-table td {
        border-bottom-color: #273449 !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table td:last-child {
        border-bottom: 0 !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table td::before {
        content: attr(data-label);
        color: #64748b;
        font-size: 10.5px;
        font-weight: 900;
        line-height: 1.35;
        text-transform: uppercase;
        letter-spacing: .035em;
    }

    body.kc-ai-page table.kc-ai-mobile-table td[colspan] {
        display: block !important;
        text-align: center;
    }

    body.kc-ai-page table.kc-ai-mobile-table td[colspan]::before {
        display: none;
    }

    body.kc-ai-page pre {
        max-width: 100% !important;
        padding: 10px !important;
        overflow-x: auto !important;
        white-space: pre-wrap !important;
        font-size: 11.5px !important;
    }

    body.kc-ai-page [style*="minmax(320px"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body.kc-ai-page .kc-pwa-install {
        right: 10px;
        bottom: max(84px, calc(var(--kc-ai-safe-bottom) + 84px));
        min-width: 44px;
        max-width: calc(100vw - 20px);
    }

    body.kc-ai-page .kc-pwa-toast {
        top: max(72px, calc(var(--kc-ai-safe-top) + 72px));
        right: 10px;
        bottom: auto;
        width: calc(100vw - 20px);
    }
}

@media (max-width: 390px) {
    body.kc-ai-page .kc-ai-attachments {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body.kc-ai-page table.kc-ai-mobile-table td {
        grid-template-columns: minmax(78px, 32%) minmax(0, 1fr) !important;
        gap: 7px !important;
    }
}

@media print {
    body.kc-ai-page .kc-ai-mobile-history-toggle {
        display: none !important;
    }
}
