/*
 * Trợ lý gia phả – giao diện thích ứng điện thoại và bàn phím ảo.
 * Tách riêng để cập nhật mà không làm index.php dài thêm.
 */
:root {
    --gp-ai-brown: #4B1607;
    --gp-ai-brown-2: #65250F;
    --gp-ai-gold: #E6C06A;
    --gp-ai-paper: #FFF8EE;
    --gp-ai-text: #28150E;
    --gp-ai-muted: #6E6156;
    --gp-ai-line: #BBA58F;
    --gp-ai-green: #23897F;
    --gp-ai-danger: #A33B32;
    --gp-ai-viewport-height: 100vh;
    --gp-ai-viewport-top: 0px;
}

html.gp-ai-lock-scroll,
html.gp-ai-lock-scroll body {
    overscroll-behavior: none;
}

.gp-ai-launcher {
    position: fixed;
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(18px, env(safe-area-inset-bottom, 0px));
    z-index: 3200;
    width: 58px;
    height: 58px;
    padding: 0;
    border: 1px solid rgba(75,22,7,.24);
    border-radius: 50%;
    background: radial-gradient(circle at 42% 35%, #FFFCF5 0 34%, #F2E4CE 74%, #D8C1A2 100%);
    color: var(--gp-ai-brown);
    box-shadow: 0 10px 28px rgba(40,21,14,.24), inset 0 0 0 4px rgba(255,255,255,.65);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.gp-ai-launcher:active { transform: scale(.96); }
.gp-ai-launcher:focus-visible { outline: 3px solid rgba(230,192,106,.82); outline-offset: 3px; }
.gp-ai-launcher svg { width: 35px; height: 35px; display: block; margin: auto; }

.gp-ai-launcher-badge {
    position: absolute;
    top: -4px;
    right: -3px;
    min-width: 24px;
    height: 24px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--gp-ai-paper);
    border-radius: 13px;
    background: var(--gp-ai-brown-2);
    color: var(--gp-ai-gold);
    font: 800 10px/1 Arial, sans-serif;
}

.gp-ai-launcher-dot {
    position: absolute;
    right: 3px;
    bottom: 4px;
    width: 8px;
    height: 8px;
    border: 1.5px solid var(--gp-ai-paper);
    border-radius: 50%;
    background: var(--gp-ai-green);
}

.gp-ai-backdrop {
    position: fixed;
    inset: 0;
    z-index: 3300;
    display: none;
    background: rgba(22,13,9,.46);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.gp-ai-backdrop.open { display: block; }

.gp-ai-panel {
    position: fixed;
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
    z-index: 3400;
    width: min(460px, calc(100vw - 28px));
    height: min(720px, calc(100vh - 28px));
    height: min(720px, calc(100dvh - 28px));
    min-height: 440px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(140,103,67,.55);
    border-radius: 18px;
    background: var(--gp-ai-paper);
    color: var(--gp-ai-text);
    box-shadow: 0 22px 60px rgba(30,16,10,.35);
    opacity: 0;
    visibility: hidden;
    transform: translateY(18px) scale(.985);
    transform-origin: right bottom;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
}
.gp-ai-panel.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.gp-ai-header {
    position: relative;
    flex: 0 0 auto;
    min-height: 78px;
    padding: 14px 52px 12px 66px;
    background: linear-gradient(180deg, rgba(101,37,15,.99), rgba(75,22,7,.99));
    color: #FFF8EE;
    border-bottom: 2px solid rgba(230,192,106,.74);
}

.gp-ai-header-emblem {
    position: absolute;
    left: 14px;
    top: 13px;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(230,192,106,.72);
    border-radius: 50%;
    background: rgba(255,248,238,.08);
    color: var(--gp-ai-gold);
}
.gp-ai-header-emblem svg { width: 27px; height: 27px; }
.gp-ai-title { margin: 0; color: var(--gp-ai-gold); font-size: 20px; font-weight: 600; line-height: 1.2; }
.gp-ai-subtitle { margin: 4px 0 0; color: rgba(255,248,238,.8); font-size: 12px; line-height: 1.3; }

.gp-ai-close {
    position: absolute;
    top: 10px;
    right: 8px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #FFF8EE;
    font: 400 28px/1 Arial, sans-serif;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.gp-ai-close:focus-visible { outline: 2px solid var(--gp-ai-gold); outline-offset: -3px; }

.gp-ai-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px 14px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    background: linear-gradient(rgba(255,248,238,.95), rgba(255,248,238,.95)),
                repeating-linear-gradient(0deg, transparent 0 25px, rgba(140,103,67,.045) 25px 26px);
}

.gp-ai-message {
    max-width: 90%;
    margin: 0 0 12px;
    padding: 11px 13px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.52;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.gp-ai-message.bot { margin-right: auto; border: 1px solid rgba(187,165,143,.66); border-top-left-radius: 4px; background: rgba(245,234,216,.78); }
.gp-ai-message.user { margin-left: auto; border: 1px solid rgba(75,22,7,.18); border-top-right-radius: 4px; background: var(--gp-ai-brown); color: #FFF8EE; }
.gp-ai-message.error { border-color: rgba(163,59,50,.35); background: #FBE8E5; color: #6F231D; }
.gp-ai-message.selection { background: #F4E7D3; color: var(--gp-ai-brown); font-size: 13px; }

.gp-ai-quick {
    display: flex;
    gap: 8px;
    margin: 2px 0 14px;
    padding: 0 1px 2px;
    overflow-x: auto;
    scrollbar-width: none;
}
.gp-ai-quick::-webkit-scrollbar { display: none; }
.gp-ai-chip {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 9px 15px;
    border: 1px solid rgba(187,165,143,.86);
    border-radius: 999px;
    background: #FFFDF8;
    color: var(--gp-ai-brown);
    font: 500 13px/1.2 "Arial Narrow", Arial, sans-serif;
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.gp-ai-chip.active { border-color: var(--gp-ai-brown); background: #F0DDC2; box-shadow: inset 0 0 0 1px rgba(75,22,7,.08); }
.gp-ai-chip:focus-visible { outline: 2px solid var(--gp-ai-gold); outline-offset: 2px; }

.gp-ai-thinking { display: inline-flex; gap: 4px; align-items: center; min-width: 54px; }
.gp-ai-thinking i { width: 6px; height: 6px; display: block; border-radius: 50%; background: var(--gp-ai-line); animation: gp-ai-dot 1.1s infinite ease-in-out; }
.gp-ai-thinking i:nth-child(2) { animation-delay: .14s; }
.gp-ai-thinking i:nth-child(3) { animation-delay: .28s; }
@keyframes gp-ai-dot { 0%,65%,100% { transform: translateY(0); opacity: .42; } 32% { transform: translateY(-4px); opacity: 1; } }

.gp-ai-choices { display: grid; gap: 8px; margin: -2px 0 14px; }
.gp-ai-choice {
    width: 100%;
    min-height: 56px;
    padding: 10px 12px;
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 8px;
    align-items: center;
    border: 1px solid rgba(187,165,143,.74);
    border-radius: 11px;
    background: #FFFDF8;
    color: var(--gp-ai-text);
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.gp-ai-choice:hover, .gp-ai-choice:focus-visible { border-color: var(--gp-ai-brown); background: #F4E7D3; outline: none; }
.gp-ai-choice-name { display: block; color: var(--gp-ai-brown); font-size: 15px; font-weight: 600; }
.gp-ai-choice-context { display: block; margin-top: 3px; color: var(--gp-ai-muted); font-size: 12px; line-height: 1.35; }
.gp-ai-choice-action { color: var(--gp-ai-brown); font-size: 12px; font-weight: 600; white-space: nowrap; }

.gp-ai-sources { max-width: 96%; margin: -3px 0 14px; display: grid; gap: 7px; }
.gp-ai-source { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border: 1px solid rgba(187,165,143,.58); border-radius: 10px; background: rgba(255,255,255,.55); }
.gp-ai-source-text { min-width: 0; color: var(--gp-ai-text); font-size: 12px; line-height: 1.35; }
.gp-ai-source-text strong { display: block; color: var(--gp-ai-brown); font-size: 13px; font-weight: 600; }
.gp-ai-view-button { flex: 0 0 auto; min-height: 38px; padding: 8px 10px; border: 1px solid rgba(75,22,7,.25); border-radius: 19px; background: var(--gp-ai-paper); color: var(--gp-ai-brown); font: 600 12px/1 "Arial Narrow", Arial, sans-serif; cursor: pointer; }

.gp-ai-composer {
    flex: 0 0 auto;
    padding: 9px 10px max(10px, env(safe-area-inset-bottom, 0px));
    display: grid;
    grid-template-columns: minmax(0,1fr) 50px;
    gap: 8px;
    align-items: end;
    border-top: 1px solid rgba(187,165,143,.55);
    background: var(--gp-ai-paper);
}
.gp-ai-input {
    width: 100%;
    min-height: 50px;
    max-height: 124px;
    resize: none;
    overflow-y: auto;
    padding: 13px 15px;
    border: 1.5px solid var(--gp-ai-brown-2);
    border-radius: 18px;
    background: #FFFDF8;
    color: var(--gp-ai-text);
    font: 400 16px/1.42 "Arial Narrow", "Liberation Sans Narrow", Arial, sans-serif;
    outline: none;
}
.gp-ai-input:focus { box-shadow: 0 0 0 3px rgba(101,37,15,.09); }
.gp-ai-send { width: 50px; height: 50px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--gp-ai-brown); color: var(--gp-ai-gold); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.gp-ai-send svg { width: 23px; height: 23px; }
.gp-ai-send:disabled { cursor: wait; opacity: .55; }
.gp-ai-panel[aria-busy="true"] .gp-ai-input { opacity: .78; }

.gp-ai-footnote { flex: 0 0 auto; margin: 0; padding: 0 12px 9px; color: var(--gp-ai-muted); background: var(--gp-ai-paper); font-size: 10px; line-height: 1.35; text-align: center; }
.gp-ai-footnote a { color: var(--gp-ai-brown); }

.member-card.gp-ai-highlight { z-index: 30 !important; box-shadow: 0 0 0 3px rgba(230,192,106,.9), 0 0 0 7px rgba(75,22,7,.2), 0 8px 18px rgba(75,22,7,.25) !important; animation: gp-ai-highlight 1.1s ease 2; }
@keyframes gp-ai-highlight { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }

@media (max-width: 768px) {
    .gp-ai-launcher { right: max(12px, env(safe-area-inset-right, 0px)); bottom: max(14px, env(safe-area-inset-bottom, 0px)); width: 54px; height: 54px; }
    .gp-ai-launcher svg { width: 32px; height: 32px; }

    .gp-ai-panel {
        left: 0;
        right: auto;
        top: var(--gp-ai-viewport-top, 0px);
        bottom: auto;
        width: 100%;
        height: var(--gp-ai-viewport-height, 100vh);
        min-height: 0;
        max-height: none;
        border: 0;
        border-radius: 0;
        transform: translateY(24px);
        transform-origin: center bottom;
    }
    .gp-ai-panel.open { transform: translateY(0); }
    .gp-ai-header { min-height: 74px; padding: 12px 52px 10px 64px; }
    .gp-ai-header-emblem { left: 13px; top: 12px; width: 42px; height: 42px; }
    .gp-ai-title { font-size: 20px; }
    .gp-ai-subtitle { font-size: 12px; }
    .gp-ai-messages { padding: 14px 16px 12px; }
    .gp-ai-message { max-width: 94%; font-size: 16px; }
    .gp-ai-quick { margin-bottom: 12px; }
    .gp-ai-chip { min-height: 44px; font-size: 14px; }
    .gp-ai-composer { padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
    .gp-ai-footnote { padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }

    .gp-ai-panel.gp-ai-keyboard .gp-ai-header { min-height: 62px; padding-top: 9px; padding-bottom: 7px; }
    .gp-ai-panel.gp-ai-keyboard .gp-ai-header-emblem { top: 9px; width: 38px; height: 38px; }
    .gp-ai-panel.gp-ai-keyboard .gp-ai-subtitle { display: none; }
    .gp-ai-panel.gp-ai-keyboard .gp-ai-footnote { display: none; }
    .gp-ai-panel.gp-ai-keyboard .gp-ai-messages { padding-top: 10px; }
}

@media (max-width: 390px) {
    .gp-ai-header { padding-left: 58px; }
    .gp-ai-header-emblem { left: 10px; }
    .gp-ai-title { font-size: 18px; }
    .gp-ai-subtitle { font-size: 11px; }
    .gp-ai-messages { padding-left: 12px; padding-right: 12px; }
    .gp-ai-message { font-size: 15px; }
    .gp-ai-chip { font-size: 13px; padding-inline: 13px; }
    .gp-ai-choice { grid-template-columns: 1fr; }
    .gp-ai-choice-action { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
    .gp-ai-panel, .gp-ai-messages { transition: none !important; scroll-behavior: auto !important; }
    .gp-ai-thinking i, .member-card.gp-ai-highlight { animation: none !important; }
}

@media print {
    .gp-ai-launcher, .gp-ai-backdrop, .gp-ai-panel { display: none !important; }
}
