/*
 * Chat widget - Παγκρήτιο Ωδείο
 *
 * Everything is namespaced under .po-chat. The widget is injected into pages
 * that already load Materialize, so no bare element selectors and no reliance
 * on inherited typography.
 */

.po-chat {
    /* Sampled from the Nota logo: the teal of the speech bubble and the gold of
       the notes. Gold is reserved for the "working" indicators, which is where
       it appears in the artwork. */
    --po-accent: #034d67;
    --po-accent-light: #0a6d8f;
    --po-accent-soft: #e3eff4;
    --po-gold: #ba924e;
    --po-surface: #ffffff;
    --po-surface-2: #f6f9fa;
    --po-text: #16202c;
    --po-muted: #6b7a8c;
    --po-border: #e2eaee;
    --po-radius: 18px;
    --po-shadow: 0 18px 48px -12px rgba(16, 32, 54, .28), 0 4px 12px rgba(16, 32, 54, .08);

    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--po-text);
}

.po-chat *, .po-chat *::before, .po-chat *::after { box-sizing: border-box; }

/* ---------------------------------------------------------------- launcher */

.po-chat__launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 68px;
    height: 68px;
    margin-left: auto;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--po-accent-light), var(--po-accent));
    box-shadow: 0 10px 26px -6px rgba(3, 77, 103, .38);
    transition: transform .22s cubic-bezier(.34, 1.56, .64, 1), box-shadow .22s ease;
}

.po-chat__launcher:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 16px 32px -8px rgba(3, 77, 103, .45); }
.po-chat__launcher:active { transform: translateY(-1px) scale(.98); }
.po-chat__launcher:focus-visible { outline: 3px solid var(--po-accent-soft); outline-offset: 3px; }

.po-chat__launcher-icon,
.po-chat__launcher-close {
    grid-area: 1 / 1;
    display: grid;
    place-items: center;
    transition: opacity .2s ease, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}

.po-chat__launcher-close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.po-chat.is-open .po-chat__launcher-icon { opacity: 0; transform: rotate(90deg) scale(.6); }
.po-chat.is-open .po-chat__launcher-close { opacity: 1; transform: none; }

/* Attention ping, retired once the widget has been opened. */
.po-chat__ping {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--po-accent);
    animation: po-ping 2.6s cubic-bezier(0, 0, .2, 1) infinite;
}
.po-chat.is-open .po-chat__ping,
.po-chat.is-seen .po-chat__ping { display: none; }

@keyframes po-ping {
    0%   { transform: scale(1);   opacity: .7; }
    70%  { transform: scale(1.7); opacity: 0; }
    100% { transform: scale(1.7); opacity: 0; }
}

/* ------------------------------------------------------------------- panel */

.po-chat__panel {
    position: absolute;
    right: 0;
    bottom: 84px;
    display: flex;
    flex-direction: column;
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    overflow: hidden;
    background: var(--po-surface);
    border: 1px solid var(--po-border);
    border-radius: var(--po-radius);
    box-shadow: var(--po-shadow);
    transform-origin: bottom right;
    animation: po-panel-in .28s cubic-bezier(.16, 1, .3, 1);
}

.po-chat__panel[hidden] { display: none; }
.po-chat__panel.is-closing { animation: po-panel-out .18s ease forwards; }

@keyframes po-panel-in {
    from { opacity: 0; transform: translateY(14px) scale(.94); }
    to   { opacity: 1; transform: none; }
}
@keyframes po-panel-out {
    to { opacity: 0; transform: translateY(10px) scale(.96); }
}

/* ------------------------------------------------------------------ header */

.po-chat__header {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 13px 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--po-accent-light), var(--po-accent));
}

.po-chat__avatar {
    position: relative;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
}

.po-chat__avatar-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #64ffa0;
    box-shadow: 0 0 0 0 rgba(100, 255, 160, .7);
    animation: po-pulse 2.4s ease-out infinite;
}

@keyframes po-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(100, 255, 160, .7); }
    70%  { box-shadow: 0 0 0 9px rgba(100, 255, 160, 0); }
    100% { box-shadow: 0 0 0 0 rgba(100, 255, 160, 0); }
}

.po-chat__heading { flex: 1 1 auto; min-width: 0; }
.po-chat__title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .1px; }
.po-chat__subtitle {
    margin: 1px 0 0;
    font-size: 11.5px;
    opacity: .82;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.po-chat__tools { display: flex; gap: 2px; }
.po-chat__tool {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: transparent;
    cursor: pointer;
    opacity: .85;
    transition: background .16s ease, opacity .16s ease, transform .16s ease;
}
.po-chat__tool:hover { background: rgba(255, 255, 255, .18); opacity: 1; transform: translateY(-1px); }
.po-chat__tool:disabled { opacity: .35; cursor: default; transform: none; background: transparent; }

/* --------------------------------------------------------------- transcript */

.po-chat__log {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 6px;
    background: var(--po-surface-2);
    scroll-behavior: smooth;
}

.po-chat__log::-webkit-scrollbar { width: 8px; }
.po-chat__log::-webkit-scrollbar-thumb { background: #c3d5dc; border-radius: 99px; }
.po-chat__log::-webkit-scrollbar-track { background: transparent; }

.po-chat__msg {
    display: flex;
    margin-bottom: 10px;
    animation: po-msg-in .32s cubic-bezier(.16, 1, .3, 1) both;
}
.po-chat__msg--user { justify-content: flex-end; }

@keyframes po-msg-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.po-chat__bubble {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.po-chat__msg--bot .po-chat__bubble {
    background: var(--po-surface);
    border: 1px solid var(--po-border);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(16, 32, 54, .05);
}

.po-chat__msg--user .po-chat__bubble {
    color: #fff;
    background: linear-gradient(135deg, var(--po-accent-light), var(--po-accent));
    border-bottom-right-radius: 5px;
}

.po-chat__msg--error .po-chat__bubble {
    color: #8a1c1c;
    background: #fdecec;
    border: 1px solid #f6c9c9;
}

.po-chat__time {
    display: block;
    margin-top: 4px;
    font-size: 10.5px;
    opacity: .55;
}

/* ------------------------------------------------- the hopping dots, waiting */

.po-chat__typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 15px;
}

.po-chat__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--po-gold);
    opacity: .55;
    animation: po-hop 1.25s ease-in-out infinite;
}
.po-chat__dot:nth-child(2) { animation-delay: .16s; }
.po-chat__dot:nth-child(3) { animation-delay: .32s; }

@keyframes po-hop {
    0%, 60%, 100% { transform: translateY(0);    opacity: .45; }
    30%           { transform: translateY(-7px); opacity: 1; }
}

/* Thin progress line across the top of the composer while a reply is pending. */
.po-chat__panel.is-busy .po-chat__composer::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 2px;
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--po-accent), transparent);
    animation: po-sweep 1.1s ease-in-out infinite;
}

@keyframes po-sweep {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* -------------------------------------------------------------- suggestions */

.po-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 10px;
    background: var(--po-surface-2);
}
.po-chat__suggestions:empty { display: none; }

.po-chat__chip {
    padding: 6px 11px;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--po-accent);
    background: var(--po-surface);
    border: 1px solid #bcd7e1;
    border-radius: 99px;
    cursor: pointer;
    animation: po-msg-in .3s ease both;
    transition: background .16s ease, transform .16s ease, border-color .16s ease;
}
.po-chat__chip:hover { background: var(--po-accent-soft); border-color: #8fbccb; transform: translateY(-1px); }

/* ---------------------------------------------------------------- composer */

.po-chat__composer {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    background: var(--po-surface);
    border-top: 1px solid var(--po-border);
}

.po-chat__input-wrap { position: relative; flex: 1 1 auto; }

.po-chat__input {
    display: block;
    width: 100%;
    /* A floor, so the box can never collapse even if a measurement is missed. */
    min-height: 41px;
    max-height: 116px;
    padding: 10px 46px 10px 13px;
    font: inherit;
    color: var(--po-text);
    background: var(--po-surface-2);
    border: 1px solid var(--po-border);
    border-radius: 14px;
    resize: none;
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.po-chat__input:focus {
    background: var(--po-surface);
    border-color: #8fbccb;
    box-shadow: 0 0 0 3px rgba(3, 77, 103, .13);
}

.po-chat__counter {
    position: absolute;
    right: 11px;
    bottom: 8px;
    font-size: 10.5px;
    color: var(--po-muted);
    opacity: 0;
    transition: opacity .16s ease;
}
.po-chat__input:focus + .po-chat__counter { opacity: .75; }
.po-chat__counter.is-near { color: #c62828; opacity: 1; }

.po-chat__send {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--po-accent-light), var(--po-accent));
    cursor: pointer;
    transition: transform .18s cubic-bezier(.34, 1.56, .64, 1), opacity .18s ease;
}
.po-chat__send:hover:not(:disabled) { transform: scale(1.07); }
.po-chat__send:disabled { opacity: .4; cursor: default; }

.po-chat__send-icon { transition: opacity .16s ease, transform .16s ease; }
.po-chat__send-stop {
    position: absolute;
    width: 13px;
    height: 13px;
    border-radius: 3px;
    background: #fff;
    opacity: 0;
    transform: scale(.5);
    transition: opacity .16s ease, transform .16s ease;
}
.po-chat__panel.is-busy .po-chat__send-icon { opacity: 0; transform: scale(.5); }
.po-chat__panel.is-busy .po-chat__send-stop { opacity: 1; transform: none; }

.po-chat__footnote {
    margin: 0;
    padding: 0 14px 10px;
    font-size: 10.5px;
    color: var(--po-muted);
    text-align: center;
    background: var(--po-surface);
}

/* ------------------------------------------------------------- small screens */

@media (max-width: 560px) {
    .po-chat { right: 14px; bottom: 14px; }
    .po-chat__panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
    }
}

/* Motion is decoration here; the widget works identically without it. */
@media (prefers-reduced-motion: reduce) {
    .po-chat *, .po-chat *::before, .po-chat *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
    .po-chat__log { scroll-behavior: auto; }
}

/* ------------------------------------------------- rendered model Markdown */

.po-chat__body > *:first-child { margin-top: 0; }
.po-chat__body > *:last-child  { margin-bottom: 0; }

.po-chat__body p { margin: 0 0 8px; }
.po-chat__body h3, .po-chat__body h4, .po-chat__body h5, .po-chat__body h6 {
    margin: 12px 0 6px;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.35;
}
.po-chat__body strong { font-weight: 700; }
.po-chat__body em { font-style: italic; }
.po-chat__body del { opacity: .7; }

.po-chat__body ul, .po-chat__body ol { margin: 6px 0 9px; padding-left: 20px; }
.po-chat__body li { margin: 3px 0; }
.po-chat__body ul { list-style: disc; }
.po-chat__body ol { list-style: decimal; }

.po-chat__body a { color: var(--po-accent); text-decoration: underline; overflow-wrap: anywhere; }
.po-chat__msg--user .po-chat__body a { color: #fff; }

.po-chat__body code {
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    background: rgba(16, 32, 54, .07);
    border-radius: 5px;
}
.po-chat__body pre {
    margin: 8px 0;
    padding: 10px 12px;
    overflow-x: auto;
    background: #10203608;
    border: 1px solid var(--po-border);
    border-radius: 10px;
}
.po-chat__body pre code { padding: 0; background: none; font-size: 12px; line-height: 1.5; }

.po-chat__body blockquote {
    margin: 8px 0;
    padding: 4px 0 4px 11px;
    border-left: 3px solid #cfe0f5;
    color: var(--po-muted);
}
.po-chat__body hr { margin: 10px 0; border: 0; border-top: 1px solid var(--po-border); }

/* Tables scroll inside the bubble rather than stretching the panel. */
.po-md-table {
    margin: 8px 0;
    overflow-x: auto;
    border: 1px solid var(--po-border);
    border-radius: 10px;
}
.po-md-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.po-md-table th, .po-md-table td {
    padding: 7px 10px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--po-border);
}
.po-md-table th { background: var(--po-surface-2); font-weight: 600; }
.po-md-table tr:last-child td { border-bottom: 0; }

/* Caret that blinks while tokens are still arriving. */
.po-chat__body.is-streaming > *:last-child::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--po-accent);
    animation: po-caret 1s steps(2, start) infinite;
}

@keyframes po-caret { to { opacity: 0; } }

/* The bubble keeps pre-wrap so a visitor's own line breaks survive; a rendered
   Markdown reply must not, or the newlines in the generated HTML double every
   gap between block elements. */
.po-chat__msg--bot .po-chat__body { white-space: normal; }

/* ------------------------------------------- "working on it" inside a bubble */

.po-chat__activity {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 1px 0;
}

/* An orb that breathes and sweeps, rather than a spinner: the wait is a
   lookup with no measurable progress, and a spinner implies there is some. */
.po-chat__activity-orb {
    position: relative;
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 32%, #d9b779, var(--po-gold));
    animation: po-orb 1.5s ease-in-out infinite;
}
.po-chat__activity-orb::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid var(--po-gold);
    opacity: .35;
    animation: po-ping 1.8s cubic-bezier(0, 0, .2, 1) infinite;
}

@keyframes po-orb {
    0%, 100% { transform: scale(1);    opacity: .85; }
    50%      { transform: scale(1.16); opacity: 1; }
}

.po-chat__activity-label {
    position: relative;
    font-size: 13px;
    font-weight: 500;
    color: var(--po-muted);
    background: linear-gradient(90deg, var(--po-muted) 0%, var(--po-muted) 35%,
                                        var(--po-accent) 50%,
                                        var(--po-muted) 65%, var(--po-muted) 100%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: po-shimmer 1.9s linear infinite;
}

@keyframes po-shimmer {
    0%   { background-position: 120% 0; }
    100% { background-position: -20% 0; }
}

/* The caret belongs to prose, not to a status row. */
.po-chat__body.is-activity.is-streaming > *:last-child::after { content: none; }

/* Without background-clip support the label must still be readable. */
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
    .po-chat__activity-label {
        background: none;
        -webkit-text-fill-color: currentColor;
        color: var(--po-accent);
    }
}

/* ------------------------------------------------------------- Nota logo */

/* The artwork has a white ground, so the launcher is white rather than the
   blue gradient it used to be - a teal logo on a blue button read as a white
   square. The ring keeps it distinct from a pale page behind it. */
.po-chat__launcher {
    background: #fff;
    box-shadow: 0 10px 26px -6px rgba(3, 77, 103, .38), 0 0 0 1px rgba(3, 77, 103, .10);
}
.po-chat__launcher:hover { box-shadow: 0 16px 32px -8px rgba(3, 77, 103, .45), 0 0 0 1px rgba(3, 77, 103, .16); }
.po-chat__launcher-close { color: #034d67; }
.po-chat__ping { border-color: #034d67; }

.po-chat__logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Launcher: the artwork carries its own generous padding, so it is scaled up
   slightly and clipped to the circle rather than padded again. */
/* Barely any padding: the artwork already carries generous whitespace, so the
   button was showing a small mark inside a large white disc. */
.po-chat__launcher-icon {
    width: 100%;
    height: 100%;
    padding: 1px;
    border-radius: 50%;
    overflow: hidden;
}
.po-chat__launcher-icon .po-chat__logo { transform: scale(1.18); }

/* Header: white disc so the teal reads against the blue bar, with the online
   dot moved to the corner now that the centre is occupied. */
.po-chat__avatar {
    background: #fff;
    overflow: visible;
    padding: 3px;
}
.po-chat__avatar .po-chat__logo { border-radius: 50%; }

.po-chat__avatar-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 10px;
    height: 10px;
    border: 2px solid var(--po-accent);
}

/* ------------------------------------------------------------- expanded view */

.po-chat__panel {
    transition: width .24s cubic-bezier(.16, 1, .3, 1), height .24s cubic-bezier(.16, 1, .3, 1);
}

/* Wide enough for a twelve-row charges table with its links, which is the
   thing that actually needed the room. */
.po-chat__panel.is-expanded {
    width: min(920px, calc(100vw - 44px));
    height: min(780px, calc(100vh - 120px));
}

/* Only one of the two glyphs shows at a time. */
.po-chat__tool--expand { position: relative; }
.po-chat__icon-collapse { display: none; }
.po-chat.is-expanded .po-chat__icon-expand { display: none; }
.po-chat.is-expanded .po-chat__icon-collapse { display: block; }

/* Bubbles may stay narrow-ish for readability, but a table should use the room. */
.po-chat.is-expanded .po-chat__bubble { max-width: 92%; }
.po-chat.is-expanded .po-md-table th,
.po-chat.is-expanded .po-md-table td { white-space: normal; }

/* The panel is already full screen on a phone, so the control is pointless. */
@media (max-width: 560px) {
    .po-chat__tool--expand { display: none; }
    .po-chat__panel.is-expanded { width: 100vw; height: 100dvh; }
}

@media (prefers-reduced-motion: reduce) {
    .po-chat__panel { transition: none; }
}
