/* ==========================================================================
   Pagadian City — Hybrid AI Chat Widget
   --------------------------------------------------------------------------
   Brand-aligned: Sangguniang Panlungsod navy (#1e3a5f / #0f2744) + gold
   (#d4a017). Display headline uses Playfair Display (already loaded by the
   public landing). Body Poppins (already loaded).

   Design principles applied:
   - NOT a generic round purple bot. Launcher is a "civic seal pill" that
     reads as official, with a small gold ribbon and the city's monogram.
   - NO emoji-as-icon. NO trust-gradient (purple→blue). NO Inter on display.
   - One accent (gold) used twice max per panel.
   - Glassmorphism scoped to header only — body keeps high contrast.
   - Dark theme is the public-portal default; widget bg is a deep navy
     #0f2744-derived plate so it doesn't fight the homepage backdrop.
   ========================================================================== */

:root {
    --aichat-navy: #1e3a5f;
    --aichat-navy-deep: #0f2744;
    --aichat-navy-darker: #0a1c33;
    --aichat-gold: #d4a017;
    --aichat-gold-soft: #f6c744;
    --aichat-pearl: #f8fafc;
    --aichat-text: #e8eef5;
    --aichat-text-muted: #94a3b8;
    --aichat-bubble-bot: rgba(15, 39, 68, 0.92);
    --aichat-bubble-user: var(--aichat-gold);
    --aichat-bubble-user-text: #1a1a1a;
    --aichat-border: rgba(212, 160, 23, 0.22);
    --aichat-border-soft: rgba(255, 255, 255, 0.08);
    --aichat-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(212, 160, 23, 0.12);
    --aichat-radius-lg: 18px;
    --aichat-radius-md: 12px;
    --aichat-radius-sm: 8px;
    --aichat-font-display: 'Playfair Display', 'Times New Roman', Georgia, serif;
    --aichat-font-body: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ============================================================
   LAUNCHER (HIDDEN by default per user feedback "no floating icon")
   --------------------------------------------------------------
   The panel and JS API stay alive — call window.PagadianAIChat.open()
   from a navbar button or any element to launch the assistant.
   To re-enable the floating launcher, override with:
     .aichat-launcher { display: inline-flex !important; }
   ============================================================ */
.aichat-launcher {
    display: none !important;
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 99990;
    align-items: center;
    gap: 12px;
    padding: 12px 22px 12px 14px;
    background: linear-gradient(135deg, var(--aichat-navy-deep) 0%, var(--aichat-navy) 100%);
    color: var(--aichat-pearl);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--aichat-font-body);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.01em;
    box-shadow: 0 18px 32px -10px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--aichat-border);
    transition: transform .25s cubic-bezier(.4,0,.2,1), box-shadow .25s, background .25s;
    -webkit-tap-highlight-color: transparent;
}

.aichat-launcher:hover,
.aichat-launcher:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 22px 40px -10px rgba(0, 0, 0, 0.6), 0 0 0 2px var(--aichat-gold);
    outline: none;
}

.aichat-launcher__seal {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, var(--aichat-gold-soft) 0%, var(--aichat-gold) 70%, #a87b0a 100%);
    color: var(--aichat-navy-deep);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--aichat-font-display);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.02em;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18), 0 2px 6px rgba(0,0,0,0.4);
    flex-shrink: 0;
}

.aichat-launcher__label {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: left;
}

.aichat-launcher__label-top {
    font-family: var(--aichat-font-display);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.aichat-launcher__label-sub {
    font-size: 11px;
    color: var(--aichat-gold-soft);
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.aichat-launcher__pulse {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    border: 2px solid var(--aichat-gold);
    opacity: 0;
    animation: aichat-pulse 2.6s ease-out infinite;
    pointer-events: none;
}

@keyframes aichat-pulse {
    0%   { opacity: 0.55; transform: scale(1); }
    80%  { opacity: 0;    transform: scale(1.25); }
    100% { opacity: 0;    transform: scale(1.25); }
}

/* hide pulse after first interaction (set on .aichat-launcher) */
.aichat-launcher.is-engaged .aichat-launcher__pulse { display: none; }

/* ============================================================
   PANEL (expanded state)
   ============================================================ */
.aichat-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 99991;
    width: min(420px, calc(100vw - 32px));
    height: min(640px, calc(100vh - 40px));
    max-height: min(640px, calc(100vh - 40px));
    background: linear-gradient(180deg, var(--aichat-navy-deep) 0%, var(--aichat-navy-darker) 100%);
    color: var(--aichat-text);
    border-radius: var(--aichat-radius-lg);
    box-shadow: var(--aichat-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--aichat-border-soft);
    font-family: var(--aichat-font-body);
}

.aichat-panel.is-open {
    display: flex;
    animation: aichat-rise 0.32s cubic-bezier(.16,1,.3,1) both;
}

@keyframes aichat-rise {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ----- HEADER ---------------------------------------------- */
.aichat-header {
    position: relative;
    padding: 18px 18px 16px 18px;
    background:
      linear-gradient(135deg, rgba(212, 160, 23, 0.08), transparent 60%),
      linear-gradient(180deg, rgba(255,255,255,0.03), transparent),
      var(--aichat-navy);
    border-bottom: 2px solid var(--aichat-gold);
    display: flex;
    align-items: center;
    gap: 14px;
}

.aichat-header__seal {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, var(--aichat-gold-soft) 0%, var(--aichat-gold) 70%, #a87b0a 100%);
    color: var(--aichat-navy-deep);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--aichat-font-display);
    font-weight: 700;
    font-size: 19px;
    letter-spacing: -0.02em;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2), 0 2px 6px rgba(0,0,0,0.45);
    flex-shrink: 0;
    position: relative;
}
/* Tiny gold sparkle dot on the seal — emphasizes "AI hybrid" identity. */
.aichat-header__seal::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: var(--aichat-gold-soft);
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--aichat-navy-deep), 0 0 10px rgba(246, 199, 68, 0.85);
    background-image:
        radial-gradient(circle at 50% 50%, #fff 0%, #fff 18%, var(--aichat-gold-soft) 22%, transparent 60%);
    animation: aichatSealSpark 2.2s ease-in-out infinite;
}
@keyframes aichatSealSpark {
    0%, 100% { transform: scale(0.85); opacity: 0.75; }
    50%      { transform: scale(1.05); opacity: 1; }
}

.aichat-header__title {
    flex: 1;
    min-width: 0;
}

.aichat-header__name {
    font-family: var(--aichat-font-display);
    font-size: 19px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin: 0;
    color: #fff;
}

.aichat-header__sub {
    font-size: 11.5px;
    color: rgba(248, 250, 252, 0.72);
    margin-top: 2px;
    letter-spacing: 0.02em;
    /* Single-line clamp */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aichat-header__actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.aichat-header__close,
.aichat-header__btn--min {
    background: transparent;
    border: 1px solid var(--aichat-border-soft);
    color: var(--aichat-text);
    border-radius: 8px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    transition: background .2s, border-color .2s;
    font-family: inherit;
    padding: 0;
}
.aichat-header__close:hover,
.aichat-header__close:focus-visible,
.aichat-header__btn--min:hover,
.aichat-header__btn--min:focus-visible {
    background: rgba(255,255,255,0.06);
    border-color: var(--aichat-gold);
    outline: none;
}
/* En-dash glyph for minimize, up-triangle when restored. */
.aichat-header__btn--min::before { content: '\2013'; font-weight: 700; }
.aichat-panel.is-minimized .aichat-header__btn--min::before { content: '\25B2'; font-size: 10px; }

/* Minimized panel: header strip only, body+chips+input hidden. */
.aichat-panel.is-minimized {
    height: auto !important;
    max-height: 64px;
}
.aichat-panel.is-minimized .aichat-body,
.aichat-panel.is-minimized .aichat-quickbar,
.aichat-panel.is-minimized .aichat-form,
.aichat-panel.is-minimized .aichat-footnote { display: none !important; }
.aichat-panel.is-minimized .aichat-header { cursor: pointer; }
.aichat-panel.is-minimized .aichat-header__provider-pill { display: none; }

.aichat-header__provider-pill {
    position: absolute;
    bottom: -10px;
    left: 18px;
    font-size: 9.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: var(--aichat-navy-deep);
    color: var(--aichat-gold-soft);
    border: 1px solid var(--aichat-gold);
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 600;
}

/* ----- BODY (messages) ------------------------------------- */
.aichat-body {
    flex: 1;
    overflow-y: auto;
    padding: 22px 16px 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
.aichat-body::-webkit-scrollbar { width: 6px; }
.aichat-body::-webkit-scrollbar-track { background: transparent; }
.aichat-body::-webkit-scrollbar-thumb {
    background: rgba(212,160,23,0.25);
    border-radius: 3px;
}

/* ----- MESSAGE BUBBLES ------------------------------------- */
.aichat-msg {
    max-width: 86%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: aichat-fade .25s ease-out both;
}
@keyframes aichat-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.aichat-msg__bubble {
    padding: 11px 14px;
    border-radius: var(--aichat-radius-md);
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.aichat-msg__meta {
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--aichat-text-muted);
    padding: 0 4px;
}

.aichat-msg--bot {
    align-self: flex-start;
}
.aichat-msg--bot .aichat-msg__bubble {
    background: var(--aichat-bubble-bot);
    border: 1px solid var(--aichat-border-soft);
    border-top-left-radius: 4px;
    color: var(--aichat-text);
}
.aichat-msg--bot .aichat-msg__bubble a {
    color: var(--aichat-gold-soft);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.aichat-msg--user {
    align-self: flex-end;
}
.aichat-msg--user .aichat-msg__bubble {
    background: var(--aichat-bubble-user);
    color: var(--aichat-bubble-user-text);
    border-top-right-radius: 4px;
    font-weight: 500;
}

.aichat-msg--blocked .aichat-msg__bubble {
    border-color: rgba(196, 30, 58, 0.45);
    background: rgba(196, 30, 58, 0.18);
}

.aichat-msg--system {
    align-self: center;
    max-width: 100%;
}
.aichat-msg--system .aichat-msg__bubble {
    background: transparent;
    border: 1px dashed var(--aichat-border-soft);
    color: var(--aichat-text-muted);
    font-size: 12.5px;
    text-align: center;
    padding: 8px 12px;
}

/* ----- TYPING INDICATOR ------------------------------------ */
.aichat-typing {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    background: var(--aichat-bubble-bot);
    border: 1px solid var(--aichat-border-soft);
    border-radius: var(--aichat-radius-md);
    border-top-left-radius: 4px;
}
.aichat-typing__dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--aichat-gold);
    opacity: 0.4;
    animation: aichat-blink 1.2s infinite ease-in-out;
}
.aichat-typing__dot:nth-child(2) { animation-delay: .15s; }
.aichat-typing__dot:nth-child(3) { animation-delay: .30s; }
@keyframes aichat-blink { 0%,80%,100% { opacity: 0.3; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1); } }

/* ----- QUICK QUESTION CHIPS — header-anchored popover --------
   No longer takes any vertical space inside the panel body. The
   suggestion list now opens as a small popover anchored to a tiny
   icon button in the header. The answer area gets the full panel. */
.aichat-quickbar {
    position: absolute;
    top: 56px;
    right: 14px;
    z-index: 5;
    width: min(280px, calc(100% - 28px));
    background: linear-gradient(180deg, var(--aichat-navy-deep) 0%, var(--aichat-navy-darker) 100%);
    border: 1px solid var(--aichat-border);
    border-radius: 12px;
    box-shadow: 0 16px 28px -10px rgba(0,0,0,0.55);
    padding: 10px 12px;
    display: none;
}
.aichat-quickbar.is-open { display: block; }
.aichat-quickbar.is-spent { display: none !important; }

.aichat-quickbar__toggle {
    background: transparent;
    border: 1px solid var(--aichat-border-soft);
    color: var(--aichat-text-muted);
    width: 28px;
    height: 28px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color .2s, border-color .2s, background .2s;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    font-family: inherit;
}
.aichat-quickbar__toggle::before {
    content: '?';
    font-weight: 700;
    font-style: italic;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 14px;
    transition: transform .2s ease;
}
.aichat-quickbar__toggle.is-open::before { transform: rotate(180deg); }
.aichat-quickbar__toggle:hover,
.aichat-quickbar__toggle:focus-visible,
.aichat-quickbar__toggle.is-open {
    color: var(--aichat-gold);
    border-color: var(--aichat-gold);
    background: rgba(212,160,23,0.08);
    outline: none;
}

.aichat-quickbar__heading {
    font-size: 9.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--aichat-gold-soft);
    font-weight: 600;
    margin: 0 0 8px 0;
}

.aichat-quickbar__list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* List-row variant inside the popover — full-width tap target. */
.aichat-chip {
    background: rgba(255,255,255,0.03);
    color: var(--aichat-text);
    border: 1px solid var(--aichat-border-soft);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .2s, background .2s, color .2s;
    line-height: 1.3;
    text-align: left;
    width: 100%;
}
.aichat-chip:hover,
.aichat-chip:focus-visible {
    border-color: var(--aichat-gold);
    background: rgba(212,160,23,0.08);
    color: #fff;
    outline: none;
}

/* ----- INPUT ROW ------------------------------------------- */
.aichat-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px 14px 14px;
    border-top: 1px solid var(--aichat-border-soft);
    background: rgba(0, 0, 0, 0.18);
}

.aichat-input {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 110px;
    border-radius: var(--aichat-radius-md);
    border: 1px solid var(--aichat-border-soft);
    background: rgba(255,255,255,0.03);
    color: var(--aichat-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    padding: 10px 12px;
    transition: border-color .2s, background .2s;
}
.aichat-input::placeholder { color: rgba(148, 163, 184, 0.7); }
.aichat-input:focus {
    outline: none;
    border-color: var(--aichat-gold);
    background: rgba(255,255,255,0.06);
}

.aichat-send {
    background: linear-gradient(135deg, var(--aichat-gold) 0%, var(--aichat-gold-soft) 100%);
    color: var(--aichat-navy-deep);
    border: none;
    width: 44px;
    height: 44px;
    align-self: flex-end;
    border-radius: var(--aichat-radius-md);
    font-size: 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, box-shadow .2s;
    flex-shrink: 0;
}
.aichat-send:hover:not([disabled]) {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px -4px rgba(212,160,23,0.55);
}
.aichat-send[disabled] { opacity: 0.4; cursor: not-allowed; }

.aichat-send__icon {
    width: 18px; height: 18px;
    fill: currentColor;
}

/* ----- FOOTER MICROCOPY ------------------------------------ */
.aichat-footnote {
    padding: 0 16px 10px 16px;
    font-size: 10.5px;
    color: var(--aichat-text-muted);
    text-align: center;
    line-height: 1.4;
    letter-spacing: 0.02em;
}
.aichat-footnote a {
    color: var(--aichat-gold-soft);
    text-decoration: none;
    border-bottom: 1px dotted rgba(212,160,23,0.4);
}
.aichat-footnote a:hover { border-bottom-style: solid; }

/* ----- FEEDBACK BUTTONS ------------------------------------ */
.aichat-msg__actions {
    display: inline-flex;
    gap: 4px;
    padding: 0 4px;
    margin-top: 2px;
}
.aichat-feedback-btn {
    background: transparent;
    border: 1px solid var(--aichat-border-soft);
    color: var(--aichat-text-muted);
    width: 26px; height: 26px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: color .2s, border-color .2s, background .2s;
}
.aichat-feedback-btn:hover { color: var(--aichat-gold); border-color: var(--aichat-gold); }
.aichat-feedback-btn[data-active="up"]   { color: #10b981; border-color: rgba(16,185,129,0.5); background: rgba(16,185,129,0.08); }
.aichat-feedback-btn[data-active="down"] { color: #ef4444; border-color: rgba(239,68,68,0.5);  background: rgba(239,68,68,0.08); }

/* ============================================================
   MOBILE — full sheet
   ============================================================ */
@media (max-width: 600px) {
    .aichat-panel {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100vw;
        max-height: 92vh;
        border-radius: var(--aichat-radius-lg) var(--aichat-radius-lg) 0 0;
    }
    .aichat-launcher {
        right: 14px;
        bottom: 14px;
        padding: 10px 18px 10px 12px;
    }
    .aichat-launcher__label-top { font-size: 14px; }
    .aichat-launcher__label-sub { font-size: 10px; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .aichat-launcher__pulse,
    .aichat-typing__dot { animation: none; }
    .aichat-panel.is-open,
    .aichat-msg { animation: none; }
}

/* ============================================================
   PRINT — hide
   ============================================================ */
@media print {
    .aichat-launcher, .aichat-panel { display: none !important; }
}
