/**
 * PD AI Search — Frontend CSS
 * - Chat box pinned to viewport height minus header
 * - Stream scrolls, system bar fixed at bottom of wrapper
 * - User bubbles right/orange, assistant left/grey
 */

/* ---------- Root / page behavior ---------- */
:root {
    --pdai-header: 69px;
    --pdai-header-extra: 35px;
    --pdai-btn-h: 48px;
    --pdai-pill-radius: 9999px;
    --pdai-btn-padding-x: 22px;
}

html, body {
    height: auto;
    margin: 0;
    padding: 0;
    overflow: auto;
    background: inherit;
    color: inherit;
    font: inherit;
}

/* ---------- Shared search form container ---------- */
.search-form-container-ai {
    display: flex;
    justify-content: center;
    width: 100%;
    position: relative;
    z-index: 50;
    padding-top: 24px;
}

/* ---------- Shared form + chat box ---------- */
.pdai-chat-inputbar > .search-form-container-ai {
    padding-top: 0;
}

.search-form-ai,
.pdai-chat-box {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 700px;
    border: 1px solid #fff !important;
    border-radius: var(--pdai-pill-radius);
    overflow: hidden;
    background: #fff;
    min-height: var(--pdai-btn-h);
}

/* Input */
.search-form-ai .search-field-ai,
.pdai-chat-box .pdai-chat-input {
    flex: 1;
    border: none;
    height: var(--pdai-btn-h);
    padding: 0 14px;
    font-size: 14px;
    line-height: var(--pdai-btn-h);
    outline: none;
    background-color: #fff;
    box-shadow: none !important;
}

/* Counter */
.search-form-ai .pdai-char-counter,
.pdai-chat-box .pdai-char-counter {
    display: flex;
    align-items: center;
    height: var(--pdai-btn-h);
    padding: 0 8px 0 0;
    font-size: 12px;
    line-height: 1;
    color: #555;
    white-space: nowrap;
}

.pdai-char-counter.pdai-near { color: #b45309; font-weight: 600; }
.pdai-char-counter.pdai-over { color: #b91c1c; font-weight: 700; }

/* Button */
.search-form-ai .search-submit-ai,
.pdai-chat-box .pdai-chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--pdai-btn-h);
    padding: 0 var(--pdai-btn-padding-x);
    background: #e9812e;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--pdai-pill-radius);
    box-shadow: 0 0 0 2px #fff;
    cursor: pointer;
}
.search-form-ai .search-submit-ai:hover,
.pdai-chat-box .pdai-chat-send:hover { opacity: .85; }
.search-form-ai .search-submit-ai:active,
.pdai-chat-box .pdai-chat-send:active { transform: translateY(1px); }
.search-form-ai .search-submit-ai:focus-visible,
.pdai-chat-box .pdai-chat-send:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(233,129,46,.45);
}
.pdai-btn-stop {
    background: #111 !important;
    color: #fff !important;
}

/* Placeholder tone */
.search-form-ai .search-field-ai::placeholder,
.pdai-chat-box .pdai-chat-input::placeholder { color: #bdbdbd; }

/* ---------- Chat layout ---------- */
.pdai-chat-wrapper {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--pdai-header) - var(--pdai-header-extra));
    max-height: calc(100vh - var(--pdai-header) - var(--pdai-header-extra));
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 0;
    box-sizing: border-box;
}

.pdai-chat-stream-wrap {
    position: relative;
    flex: 1;
    border-radius: 30px;
    background: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Scrollable messages */
.pdai-chat-stream {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    padding-bottom: 48px; /* room for footer when visible */
    box-sizing: border-box;
}

/*.pdai-chat-stream {*/
/*    flex: 1;*/
/*    overflow-y: auto;*/
/*    overscroll-behavior: contain;*/
/*    padding: 16px;*/
/*    padding-bottom: 48px; !* room for system bar *!*/
/*    box-sizing: border-box;*/
/*}*/

/* Input bar */
.pdai-chat-inputbar {
    padding: 24px 0 0;
    background: transparent;
}
.pdai-chat-inputbar .search-form-ai,
.pdai-chat-inputbar .pdai-chat-box {
    max-width: none;
    width: 100%;
    margin: 0;
}

/* ---------- Bubbles ---------- */
.pdai-chat-content {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 8px;
    margin: 12px 0;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.pdai-chat-user { text-align: right; }
.pdai-chat-user .pdai-chat-content {
    background: #e9812e;
    color: #fff;
    border-top-right-radius: 4px;
    max-width: 60%;
}
.pdai-chat-assistant { text-align: left; }
.pdai-chat-assistant .pdai-chat-content {
    background: #f6f6f6;
    color: #000;
    border-top-left-radius: 4px;
    max-width: 100%;
}

/* ---------- System bar (pinned bottom) ---------- */

.pdai-chat-stream-wrap > .pdai-chat-system:not(#pdai-system-bar) { display: none !important; }

/* Sticky footer that lives *inside* .pdai-chat-stream */
.pdai-chat-system {
    position: sticky;      /* stick within the scroll container */
    bottom: 0;
    left: 0;
    width: 100%;
    min-height: 32px;
    line-height: 32px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    box-sizing: border-box;
    padding: 0 8px;
    z-index: 10;
    display: none;         /* hidden by default */
    border-top: 1px solid transparent;
}

/* Visibility toggle */
.pdai-chat-system.is-visible { display: block; }

/* Styles for info vs error */
.pdai-chat-system.info {
    background: #fff3cd;
    color: #664d03;
    border-top-color: #ffe69c;
}

.pdai-chat-system.error {
    background: #f8d7da;
    color: #721c24;
    border-top-color: #f5c6cb;
}

/* Neutralize bubble styling inside footer */
.pdai-chat-system .pdai-chat-content {
    display: inline !important;
    background: none !important;
    color: inherit !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
}

/* Hide the system footer entirely */
.pdai-chat-system {
    display: none !important;
}

/* Disclaimer text */
.pdai-chat-disclaimer {
    font-size: 0.75rem;
    color: #777;
    margin-top: 12px;
    text-align: center;
}

/*.pdai-chat-system {*/
/*    position: absolute;*/
/*    bottom: 0;*/
/*    left: 0;*/
/*    width: 100%;*/
/*    min-height: 32px;*/
/*    line-height: 32px;*/
/*    text-align: center;*/
/*    background: #f8d7da;*/
/*    color: #721c24;*/
/*    border-top: 1px solid #f5c6cb;*/
/*    font-size: 0.8rem;*/
/*    font-weight: 700;*/
/*    box-sizing: border-box;*/
/*    z-index: 10;*/
/*    padding: 0 8px;*/
/*    display: none;*/
/*}*/
/*.pdai-chat-system.error { display: block; }*/
/*.pdai-chat-system .pdai-chat-content {*/
/*    display: inline !important;*/
/*    background: none !important;*/
/*    color: inherit !important;*/
/*    border: none !important;*/
/*    border-radius: 0 !important;*/
/*    padding: 0 !important;*/
/*    margin: 0 !important;*/
/*    box-shadow: none !important;*/
/*}*/

/* ---------- Thinking spinner ---------- */
.pdai-thinking {
    display: inline-flex;
    align-items: center;
    margin-left: 0;
    font-size: 13px;
    color: #777;
    letter-spacing: .2px;
    animation: pdaiPulse 1.2s ease-in-out infinite;
}
@keyframes pdaiPulse {
    0% { opacity: .45; }
    50% { opacity: 1; }
    100% { opacity: .45; }
}

/*.pdai-spinner {*/
/*    display: inline-block;*/
/*    width: 14px;*/
/*    height: 14px;*/
/*    border: 2px solid #ccc;*/
/*    border-top-color: #333;*/
/*    border-radius: 50%;*/
/*    animation: pdai-spin 0.6s linear infinite;*/
/*    vertical-align: middle;*/
/*    margin-left: 0.25em; !* replaces the space you had before *!*/
/*}*/

/*@keyframes pdai-spin {*/
/*    to { transform: rotate(360deg); }*/
/*}*/

/*.pdai-eyes {*/
/*    display: inline-flex;*/
/*    gap: 6px;*/
/*    margin-left: 0; !* replaces the space you had before *!*/
/*}*/

/*.pdai-eyes .eye {*/
/*    width: 14px;*/
/*    height: 14px;*/
/*    background: #fff;*/
/*    border: 2px solid #333;*/
/*    border-radius: 50%;*/
/*    overflow: hidden;*/
/*    position: relative;*/
/*}*/

/*.pdai-eyes .pupil {*/
/*    width: 6px;*/
/*    height: 6px;*/
/*    background: #333;*/
/*    border-radius: 50%;*/
/*    position: absolute;*/
/*    top: 4px;*/
/*    left: 4px;*/
/*    animation: look-around 2s infinite;*/
/*}*/

/*@keyframes look-around {*/
/*    0%, 100%   { transform: translate(0, 0); }*/
/*    20%        { transform: translate(2px, -1px); }*/
/*    40%        { transform: translate(-2px, -1px); }*/
/*    60%        { transform: translate(-2px, 1px); }*/
/*    80%        { transform: translate(2px, 1px); }*/
/*}*/

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    :root {
        --pdai-btn-h: 44px;
        --pdai-btn-padding-x: 16px;
    }
    .search-form-ai .search-field-ai,
    .pdai-chat-box .pdai-chat-input { font-size: 16px; }
    .search-form-ai .pdai-char-counter,
    .pdai-chat-box .pdai-char-counter {
        font-size: 14px;
        padding-right: 6px;
    }
    .search-form-ai,
    .pdai-chat-box {
        max-width: none;
        width: 100%;
        margin: 0;
        border-radius: var(--pdai-pill-radius);
    }
    .search-form-container-ai {
        padding: 0 12px;
        box-sizing: border-box;
    }
}