/* Help assistant — floating chat on the documentize.cloud pages (Views/Shared/_CloudAssistant.cshtml,
   js/cloud-assistant.js). Ported from the documentize repo's app-assistant.css; colours come from
   the site's tokens in cloud.css, so light and dark follow the page. Everything is scoped under
   .dza so it cannot collide with page styles. */

.dza {
    --dza-brand: var(--c-accent, #1F5FD8);
    --dza-brand-soft: var(--c-accent-soft, #E8EFFC);
    --dza-bg: var(--c-surface, #fff);
    --dza-surface: var(--c-ground, #F7F8FA);
    --dza-user: var(--c-accent-soft, #E8EFFC);
    --dza-ink: var(--c-ink, #12161D);
    --dza-muted: var(--c-muted, #5C6675);
    --dza-border: var(--c-line, #DFE3EA);
    --dza-error: #B42318;
    --dza-on-brand: #fff;
    --dza-shadow: 0 12px 40px rgba(18, 22, 29, .18), 0 2px 8px rgba(18, 22, 29, .08);
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9000;
    font-family: var(--c-sans, system-ui, sans-serif);
    font-size: 14px;
    line-height: 1.5;
    color: var(--dza-ink);
}

@media (prefers-color-scheme: dark) {
    .dza {
        --dza-error: #F97066;
        --dza-on-brand: #0D1117;
        --dza-shadow: 0 12px 40px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .3);
    }
}

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

/* ── Launcher ─────────────────────────────────────────── */
.dza-launcher {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 46px;
    padding: 0 18px 0 14px;
    border: 0;
    border-radius: 23px;
    background: var(--dza-brand);
    color: var(--dza-on-brand);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--dza-shadow);
    transition: filter .15s ease, transform .15s ease;
}
.dza-launcher:hover { filter: brightness(1.08); }
.dza-launcher:active { transform: scale(.97); }
.dza-launcher:focus-visible { outline: 3px solid var(--dza-brand-soft); outline-offset: 2px; }
.dza-open .dza-launcher { display: none; }

/* ── Panel ────────────────────────────────────────────── */
.dza-panel {
    display: flex;
    flex-direction: column;
    width: 390px;
    height: min(620px, calc(100vh - 40px));
    background: var(--dza-bg);
    border: 1px solid var(--dza-border);
    border-radius: 14px;
    box-shadow: var(--dza-shadow);
    overflow: hidden;
    animation: dza-in .18s ease-out;
}
/* Minimized = not .dza-open. !important because page stylesheets style bare section elements
   and must never be able to force the panel back into view. */
.dza-panel[hidden],
.dza:not(.dza-open) .dza-panel { display: none !important; }

@keyframes dza-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.dza-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 10px 12px 16px;
    background: var(--dza-brand);
    color: var(--dza-on-brand);
}
.dza-title { display: flex; flex-direction: column; min-width: 0; cursor: pointer; }
.dza-title strong { font-size: 15px; }
.dza-subtitle {
    font-size: 12px;
    opacity: .85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dza-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.dza-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.dza-icon-btn:hover { background: rgba(255, 255, 255, .16); }
.dza-icon-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }

/* ── Log ──────────────────────────────────────────────── */
.dza-log {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--dza-surface);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dza-msg { display: flex; }
.dza-user { justify-content: flex-end; }

.dza-bubble {
    max-width: 88%;
    padding: 9px 13px;
    border-radius: 14px;
    background: var(--dza-bg);
    border: 1px solid var(--dza-border);
    overflow-wrap: anywhere;
}
.dza-user .dza-bubble {
    background: var(--dza-user);
    border-color: transparent;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}
.dza-assistant .dza-bubble { border-bottom-left-radius: 4px; }
.dza-error .dza-bubble { color: var(--dza-error); border-color: var(--dza-error); }

.dza-bubble p { margin: 0 0 .5em; }
.dza-bubble p:last-child { margin-bottom: 0; }
.dza-bubble h4 { margin: .4em 0 .3em; font-size: 14px; }
.dza-bubble ul, .dza-bubble ol { margin: .2em 0 .5em; padding-inline-start: 1.3em; }
.dza-bubble li { margin: .15em 0; }
.dza-bubble a { color: var(--dza-brand); text-decoration: underline; }
.dza-bubble code {
    font-family: var(--c-mono, ui-monospace, monospace);
    font-size: 12.5px;
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--dza-surface);
}
.dza-bubble pre { margin: .4em 0; padding: 8px; overflow-x: auto; background: var(--dza-surface); border-radius: 6px; }
.dza-bubble pre code { padding: 0; background: none; }

.dza-suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.dza-suggestions[hidden] { display: none; }
/* Section chips: one group per page section, shown only for the section in view. */
.dza-section-chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; padding-bottom: 8px; border-bottom: 1px dashed var(--dza-border); }
.dza-section-chips[hidden] { display: none; }
.dza-section-label { width: 100%; color: var(--dza-muted); font-size: 12px; }
.dza-section-label:empty { display: none; }
.dza-chip {
    padding: 6px 11px;
    border: 1px solid var(--dza-border);
    border-radius: 16px;
    background: var(--dza-bg);
    color: var(--dza-ink);
    font: inherit;
    font-size: 13px;
    text-align: start;
    cursor: pointer;
}
.dza-chip:hover, .dza-chip:focus-visible { border-color: var(--dza-brand); color: var(--dza-brand); outline: none; }

.dza-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.dza-dots i {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--dza-muted);
    animation: dza-dot 1.2s infinite ease-in-out;
}
.dza-dots i:nth-child(2) { animation-delay: .15s; }
.dza-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dza-dot {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* ── Input ────────────────────────────────────────────── */
.dza-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--dza-border);
    background: var(--dza-bg);
    margin: 0;
}
.dza-input textarea {
    flex: 1;
    resize: none;
    min-height: 38px;
    max-height: 140px;
    padding: 8px 10px;
    border: 1px solid var(--dza-border);
    border-radius: 10px;
    background: var(--dza-bg);
    color: var(--dza-ink);
    font: inherit;
    line-height: 1.4;
}
.dza-input textarea:focus { outline: none; border-color: var(--dza-brand); }
.dza-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 10px;
    background: var(--dza-brand);
    color: var(--dza-on-brand);
    cursor: pointer;
    flex-shrink: 0;
}
.dza-send:hover:not(:disabled) { filter: brightness(1.08); }
.dza-send:disabled { opacity: .5; cursor: default; }

.dza-footnote {
    padding: 0 12px 8px;
    background: var(--dza-bg);
    color: var(--dza-muted);
    font-size: 11px;
    text-align: center;
}

/* ── Phone ────────────────────────────────────────────── */
@media (max-width: 520px) {
    .dza { right: 16px; bottom: 16px; }
    .dza-launcher-text { display: none; }
    .dza-launcher { width: 52px; height: 52px; padding: 0; justify-content: center; border-radius: 50%; }
    .dza.dza-open { left: 0; right: 0; bottom: 0; top: 0; }
    .dza-open .dza-panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .dza-panel, .dza-dots i { animation: none; }
    .dza-launcher { transition: none; }
}

@media print {
    .dza { display: none; }
}
