/* ===========================================================================
   PUBLIC CHAT WIDGET — WINDOWS 11 FLUENT DESIGN
   Matches marketing.css theme tokens (light + dark via [data-theme])
   =========================================================================== */

/* ---------------------------------------------------------------------------
   1. CHAT SECTION LAYOUT
   --------------------------------------------------------------------------- */
.chat-section {
    padding: var(--section-gap) 0;
    background: linear-gradient(135deg, var(--bg-alt) 0%, rgba(234,131,56,0.08) 40%, rgba(180,180,180,0.04) 100%);
    position: relative;
    overflow: hidden;
}
[data-theme="dark"] .chat-section {
    background: linear-gradient(135deg, var(--bg-alt) 0%, rgba(234,131,56,0.12) 40%, rgba(200,200,200,0.06) 100%);
}
/* Constellation dot grid behind chat */
.chat-section::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle, rgba(234,131,56,0.3) 1.5px, transparent 2px),
        radial-gradient(circle, rgba(180,180,180,0.18) 1px, transparent 1.5px);
    background-size: 30px 30px, 45px 45px;
    background-position: 0 0, 15px 15px;
    mask-image: radial-gradient(ellipse 65% 55% at 50% 40%, black 5%, transparent 50%);
    -webkit-mask-image: radial-gradient(ellipse 65% 55% at 50% 40%, black 5%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}
[data-theme="dark"] .chat-section::before {
    background-image:
        radial-gradient(circle, rgba(234,131,56,0.35) 1.5px, transparent 2px),
        radial-gradient(circle, rgba(200,200,200,0.22) 1px, transparent 1.5px);
}
.chat-section > * {
    position: relative;
    z-index: 1;
}

.chat-section .section-head {
    text-align: center;
    margin-bottom: 40px;
}

.chat-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    max-width: 900px;
    margin: 0 auto;
}

.chat-layout.has-images {
    grid-template-columns: 1fr 280px;
}

@media (max-width: 768px) {
    .chat-layout,
    .chat-layout.has-images {
        grid-template-columns: 1fr;
    }
}

/* ---------------------------------------------------------------------------
   2. CHAT WIDGET CONTAINER
   --------------------------------------------------------------------------- */
#chat-widget {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    min-height: 420px;
    max-height: 560px;
}

/* ---------------------------------------------------------------------------
   3. CHAT HEADER
   --------------------------------------------------------------------------- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--stroke);
    background: var(--surface-alt);
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-icon {
    font-size: 20px;
    color: var(--accent);
}

.chat-header-text {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.chat-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.chat-subtitle {
    font-size: 11px;
    color: var(--text-tertiary);
}

.chat-quota {
    font-size: 11px;
    color: var(--text-tertiary);
    transition: color 0.2s ease;
}

.chat-quota-warn {
    color: var(--accent);
}

.chat-quota-low {
    color: var(--red);
    font-weight: 600;
}

/* Status dots */
.chat-status-dots {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 10px;
}

.chat-status-dot {
    position: relative;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: default;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.chat-status-dot.online {
    background: #4caf50;
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.55);
}

.chat-status-dot.offline {
    background: #b0b0b0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .chat-status-dot.offline {
    background: #666;
}

/* Tooltip popup */
.chat-status-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: -8px;
    width: 210px;
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 10px 12px;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--text);
    z-index: 200;
    pointer-events: none;
    text-align: left;
    white-space: normal;
}

.chat-status-tooltip::after {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 10px;
    border: 6px solid transparent;
    border-bottom-color: var(--stroke);
}

.chat-status-tooltip::before {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 11px;
    border: 5px solid transparent;
    border-bottom-color: var(--surface);
    z-index: 1;
}

.chat-status-dot:hover .chat-status-tooltip {
    display: block;
}

.chat-status-tooltip strong {
    font-size: 12px;
    color: var(--text);
}

.chat-status-label {
    font-weight: 600;
}

.chat-status-dot.online .chat-status-label {
    color: #4caf50;
}

.chat-status-dot.offline .chat-status-label {
    color: var(--red, #e53935);
}

.chat-status-desc {
    color: var(--text-secondary);
    font-size: 11px;
}

/* ---------------------------------------------------------------------------
   4. CHAT MESSAGES AREA
   --------------------------------------------------------------------------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--stroke-strong);
    border-radius: 3px;
}

/* ---------------------------------------------------------------------------
   5. WELCOME / SUGGESTIONS
   --------------------------------------------------------------------------- */
.chat-welcome {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.chat-welcome strong {
    color: var(--text);
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

.chat-suggestion {
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid transparent;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-family: var(--font-body);
}

.chat-suggestion:hover {
    background: var(--accent-bg);
    border-color: var(--accent);
}

/* ---------------------------------------------------------------------------
   6. MESSAGE BUBBLES
   --------------------------------------------------------------------------- */
.chat-msg {
    display: flex;
}

.chat-msg-user {
    justify-content: flex-end;
}

.chat-msg-assistant {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: 13.5px;
    line-height: 1.65;
    word-break: break-word;
}

.chat-bubble-user {
    background: var(--accent);
    color: var(--text-on-accent);
    border-bottom-right-radius: var(--radius-sm);
}

.chat-bubble-assistant {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--stroke);
    border-bottom-left-radius: var(--radius-sm);
}

.chat-bubble-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}

[data-theme="dark"] .chat-bubble-content code {
    background: rgba(255, 255, 255, 0.1);
}

.chat-bubble-content a {
    color: var(--blue);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.chat-bubble-content strong {
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   7. TYPING INDICATOR
   --------------------------------------------------------------------------- */
.chat-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
    align-items: center;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: chat-bounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------------------------------------------------------------------------
   8. INPUT BAR
   --------------------------------------------------------------------------- */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--stroke);
    background: var(--surface);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--stroke);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 13.5px;
    color: var(--text);
    outline: none;
    font-family: var(--font-body);
    transition: border-color 0.15s ease;
    min-width: 0;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-input:disabled {
    opacity: 0.5;
}

.chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--text-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
    font-size: 15px;
}

.chat-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

.chat-send:active:not(:disabled) {
    background: var(--accent-active);
    transform: scale(0.95);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
   8b. CITY SELECTOR (in input bar)
   --------------------------------------------------------------------------- */
.chat-city-selector {
    position: relative;
    flex-shrink: 0;
}

.chat-city-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--surface-alt);
    border: 1px solid var(--stroke);
    border-radius: 20px;
    padding: 7px 12px;
    font-size: 12.5px;
    color: var(--text-tertiary);
    cursor: pointer;
    font-family: var(--font-body);
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
    white-space: nowrap;
    max-width: 160px;
}

.chat-city-btn:hover {
    border-color: var(--accent);
    color: var(--text-secondary);
}

.chat-city-btn.has-city {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.chat-city-btn .bi-geo-alt {
    font-size: 13px;
    color: var(--accent);
    flex-shrink: 0;
}

.chat-city-btn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.chat-city-chevron {
    font-size: 10px;
    opacity: 0.5;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.chat-city-dropdown.open ~ .chat-city-btn .chat-city-chevron,
.chat-city-btn:focus .chat-city-chevron {
    transform: rotate(180deg);
}

/* Dropdown panel */
.chat-city-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    width: 240px;
    max-height: 320px;
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    z-index: 100;
    flex-direction: column;
    overflow: hidden;
}

.chat-city-dropdown.open {
    display: flex;
}

.chat-city-filter-wrap {
    padding: 8px;
    border-bottom: 1px solid var(--stroke);
    flex-shrink: 0;
}

.chat-city-filter {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 12.5px;
    color: var(--text);
    outline: none;
    font-family: var(--font-body);
    box-sizing: border-box;
}

.chat-city-filter::placeholder {
    color: var(--text-tertiary);
}

.chat-city-filter:focus {
    border-color: var(--accent);
}

.chat-city-list {
    overflow-y: auto;
    flex: 1;
}

.chat-city-list::-webkit-scrollbar {
    width: 5px;
}

.chat-city-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-city-list::-webkit-scrollbar-thumb {
    background: var(--stroke-strong);
    border-radius: 3px;
}

.chat-city-province {
    padding: 6px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    background: var(--surface-alt);
    border-bottom: 1px solid var(--stroke);
    position: sticky;
    top: 0;
    z-index: 1;
}

.chat-city-item {
    padding: 7px 12px;
    font-size: 12.5px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s ease;
}

.chat-city-item:hover {
    background: var(--accent-soft);
}

.chat-city-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.chat-city-item.kb-focus {
    background: var(--accent-soft);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.chat-city-clear {
    color: var(--text-tertiary);
    font-size: 12px;
    border-bottom: 1px solid var(--stroke);
}

.chat-city-clear:hover {
    color: var(--text);
    background: var(--surface-alt);
}

.chat-city-clear .bi-x-circle {
    font-size: 11px;
}

/* ---------------------------------------------------------------------------
   9. CITY BANNER IMAGE
   --------------------------------------------------------------------------- */
.chat-city-banner {
    max-width: 900px;
    margin: 0 auto 16px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    aspect-ratio: 21 / 9;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--stroke);
}

.chat-city-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-city-banner-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 24px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
    display: flex;
    align-items: flex-end;
}

.chat-city-banner-overlay span {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* ---------------------------------------------------------------------------
   10. IMAGE PANEL
   --------------------------------------------------------------------------- */
#chat-images {
    display: none;
}

#chat-images.has-images {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-img-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--stroke);
    aspect-ratio: 16 / 10;
}

.chat-img-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.chat-img-card:hover img {
    transform: scale(1.03);
}

.chat-img-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-img-desc {
    font-size: 11px;
    color: #fff;
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-img-location {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.8);
}

.chat-img-location i {
    font-size: 9px;
}

/* ---------------------------------------------------------------------------
   11. RESPONSIVE
   --------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-city-banner {
        aspect-ratio: 16 / 9;
    }

    .chat-city-banner-overlay span {
        font-size: 16px;
    }
}

@media (max-width: 600px) {
    #chat-widget {
        min-height: 360px;
        max-height: 480px;
    }

    .chat-bubble {
        max-width: 90%;
        font-size: 13px;
    }

    .chat-input {
        font-size: 13px;
        padding: 8px 14px;
    }

    .chat-header {
        padding: 10px 14px;
    }

    .chat-input-bar {
        flex-wrap: wrap;
    }

    .chat-city-selector {
        width: 100%;
    }

    .chat-city-btn {
        width: 100%;
        justify-content: center;
        max-width: none;
    }

    .chat-city-dropdown {
        width: 100%;
    }

    .chat-city-btn-label {
        max-width: none;
    }
}
