/* ============================================================
   Konsultantka PUMCare — UI
   Layout: centered shell -> header / main (avatar + chat) / footer
   ============================================================ */

:root {
    --pum-navy: #002855;
    --pum-blue: #0a4a8a;
    --pum-accent: #c8102e;
    --bg: #eef1f7;
    --panel: #ffffff;
    --text: #1b2235;
    --muted: #6b7796;
    --border: #e3e8f1;
    --bubble-user: #0a4a8a;
    --bubble-assistant: #eef2f9;

    --header-h: 72px;
    --shell-w: 960px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* Defensive baseline: no image can ever exceed its container. */
img {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Centered application shell -------------------------------------------- */
.app-shell {
    width: 100%;
    max-width: var(--shell-w);
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

/* Header ---------------------------------------------------------------- */
.topbar {
    height: var(--header-h);
    flex: 0 0 var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 20px;
    background: var(--pum-navy);
    color: #fff;
    overflow: hidden;                 /* hard safety net */
}
.topbar-zone {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}
.topbar-zone.center {
    flex: 1 1 auto;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
}

/* Every logo: explicit height + hard ceiling, intrinsic width. */
.logo {
    width: auto;
    object-fit: contain;
    flex: 0 0 auto;
}
.logo-pum {
    height: 46px;
    max-height: 46px;
    background: #fff;
    border-radius: 8px;
    padding: 5px;
}
.logo-cid {
    height: 34px;
    max-height: 34px;
    background: #fff;
    border-radius: 6px;
    padding: 4px;
}

.app-title {
    margin: 0;
    font-size: clamp(16px, 2.4vw, 24px);
    font-weight: 800;
    letter-spacing: 0.5px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.lang-toggle { display: flex; gap: 4px; }
.lang-btn {
    background: transparent;
    color: #b9c6df;
    border: 1px solid #2a466e;
    padding: 5px 11px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}
.lang-btn.active {
    background: var(--pum-accent);
    color: #fff;
    border-color: var(--pum-accent);
}

/* Main: avatar on top, chat below, centered column ---------------------- */
.app {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
    min-height: 0;
}

/* Avatar / face --------------------------------------------------------- */
.avatar-pane {
    width: 100%;
    max-width: 420px;
    background: var(--panel);
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.avatar-frame {
    width: 340px;
    max-width: 100%;
    /* square: matches the orb's 400x400 viewBox */
    aspect-ratio: 1 / 1;
    background: linear-gradient(160deg, #dbe6f5, #c4d6ed);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-stage {
    position: absolute;
    inset: 0;
    display: block;
}
.avatar-stage svg {
    width: 100%;
    height: 100%;
    display: block;
}
/* The animation writes transforms every frame; keep the browser from
   promoting/repainting the whole card for each one. */
.avatar-stage svg #orb-blobs,
.avatar-stage svg #orb-glow {
    will-change: transform;
}
.avatar-caption { margin-top: 12px; text-align: center; }
/* The assistant has no given name; the role is the caption. */
.avatar-role { display: block; font-weight: 700; font-size: 16px; }

.status-line {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
    min-height: 18px;
    text-align: center;
}
.model-badge {
    margin-top: 8px;
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--muted);
    background: var(--bubble-assistant);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 10px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.model-badge { display: none; }
.status-line.thinking::after {
    content: "•••";
    display: inline-block;
    margin-left: 4px;
    animation: dots 1.2s steps(3, end) infinite;
    overflow: hidden;
    vertical-align: bottom;
    width: 1.2em;
}
@keyframes dots {
    0%   { width: 0;     }
    33%  { width: 0.4em; }
    66%  { width: 0.8em; }
    100% { width: 1.2em; }
}

/* Chat ------------------------------------------------------------------ */
.chat-pane {
    width: 100%;
    max-width: 720px;
    height: 440px;
    background: var(--panel);
    border-radius: 16px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.bubble.user {
    align-self: flex-end;
    background: var(--bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.bubble.assistant {
    align-self: flex-start;
    background: var(--bubble-assistant);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.bubble.intro { font-style: italic; opacity: 0.85; }

/* Retrieval sources. Deliberately outside the spoken reply: the answer text is
   read aloud, so URLs must never appear in it. */
.sources {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    line-height: 1.5;
}
.sources-label { color: var(--muted); }
.sources a {
    color: var(--pum-blue);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.sources a:hover { color: var(--pum-accent); }

.chat-form {
    display: flex;
    gap: 8px;
    padding: 14px;
    border-top: 1px solid var(--border);
    background: #fafbfe;
}
#chat-input {
    flex: 1;
    padding: 12px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.15s;
}
#chat-input:focus { border-color: var(--pum-blue); }
/* Microphone. Square, same height as the input, so the row reads as one
   control strip rather than three unrelated widgets. */
.mic-btn {
    flex: 0 0 auto;
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel);
    color: var(--pum-blue);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.mic-btn:hover:not(:disabled) {
    background: var(--bubble-assistant);
    border-color: var(--pum-blue);
}
.mic-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Recording. Red plus a pulse, because colour alone is not a state cue for
   anyone who cannot distinguish it — and a live microphone is exactly the
   thing nobody should be unsure about. */
.mic-btn.recording {
    background: var(--pum-accent);
    color: #fff;
    border-color: var(--pum-accent);
    animation: mic-pulse 1.3s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(200, 16, 46, 0.55); }
    50%      { box-shadow: 0 0 0 7px rgba(200, 16, 46, 0); }
}

/* Transcribing: busy, but not listening any more. */
.mic-btn.working {
    color: var(--muted);
    border-color: var(--border);
}
.mic-btn.working svg { animation: mic-spin 1s linear infinite; }
@keyframes mic-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .mic-btn.recording { animation: none; }
    .mic-btn.working svg { animation: none; }
}

#send-btn {
    padding: 0 20px;
    background: var(--pum-blue);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
#send-btn:hover:not(:disabled) { background: var(--pum-navy); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Footer ---------------------------------------------------------------- */
.footer {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
}
.footer-funding {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}
.footer-funding-img {
    height: 66px;
    max-height: 66px;
    width: auto;
    object-fit: contain;
}
.footer-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--pum-navy);
    color: #b9c6df;
    font-size: 12px;
}
.footer-logo {
    height: 28px;
    max-height: 28px;
    width: auto;
    object-fit: contain;
    background: #fff;
    border-radius: 5px;
    padding: 3px;
}

/* Responsive ------------------------------------------------------------ */
@media (max-width: 640px) {
    :root { --header-h: 64px; }
    .topbar { padding: 0 12px; gap: 10px; }
    .logo-pum { height: 38px; max-height: 38px; }
    .logo-cid { height: 28px; max-height: 28px; }
    .lang-btn { padding: 4px 9px; font-size: 12px; }
    .footer-funding-img { height: 51px; max-height: 51px; }
    .chat-pane { height: 60vh; }
}

/* AI Act transparency notice ------------------------------------------- */
.ai-notice {
    margin-top: 10px;
    font-size: 11px;
    line-height: 1.4;
    text-align: center;
    color: var(--muted);
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    width: 100%;
}
