/* ============================================================================
   Poseo: widgetul asistentului de suport AI (1.0.139, B.2; refăcut în 1.0.140), pe sistemul „Tejghea”.
   Foaia se linkează din App.razor DOAR când Poseo:Assistant:Enabled e pornit; markup-ul e în
   Components/Layout/AssistantWidget.razor, comportamentul în wwwroot/js/asistent.js.

   Reguli (DesignSystemCssTests + AssistantWidgetTests): numai tokeni din site.css (zero hex), fără umbră
   proprie (panoul poartă clasa .pop, singura umbră a sistemului), teal = acțiune (butonul de trimitere,
   linkurile, cipurile de surse), selectat = cerneală (bula omului), fără majuscule tipografice, fără font-stretch.
   Tokenii de tipografie ai lotului 1.0.140 (--font-text, --fs-*, --lh-*) au valori de rezervă, ca widgetul să arate
   la fel și înaintea foii noi. Tema întunecată vine din light-dark() al tokenilor, fără reguli separate.
   Telefon (≤ 560 px): panoul ia tot ecranul vizibil (--asst-vh / --asst-vtop din visualViewport, deci tastatura nu
   acoperă câmpul sau caseta Turnstile), cu safe-area pe iPhone; pagina de dedesubt nu se derulează (html.asst-lock).
   ========================================================================== */

.asst[hidden], .asst [hidden] { display: none !important; }

.asst {
    --asst-font: var(--font-text, var(--font));
    --asst-gap: 16px;
}

/* ---- Butonul din colț: secundar (alb, contur de cerneală), discret; nu concurează cu primarul paginii. ---- */
.asst-launcher {
    position: fixed; right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--asst-lift, 0px)); z-index: 55;
    display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 18px 0 14px; max-width: calc(100vw - 32px);
    border: 1.5px solid var(--ink); border-radius: 999px; background: var(--surface); color: var(--ink);
    font: 600 var(--fs-sm, 14px)/1 var(--asst-font); cursor: pointer; white-space: nowrap;
    transition: background .12s, transform .12s;
}
.asst-launcher:hover { background: var(--inset); }
.asst-launcher:active { transform: translateY(1px); }
.asst-launcher .i { flex: none; color: var(--teal-text); }
/* Sertarul de navigație pe telefon are prioritate: butonul nu stă peste el. */
body:has(.site-header.nav-open) .asst-launcher { display: none; }

/* ---- Panoul: stratul ridicat al dialogului (umbra = .pop din site.css). ---- */
.asst-panel {
    position: fixed; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: 16px; z-index: 65;
    display: flex; flex-direction: column;
    width: 420px; max-width: calc(100vw - 32px);
    height: min(680px, calc(100vh - 32px)); height: min(680px, calc(100dvh - 32px));
    background: var(--elevated); color: var(--ink); font-family: var(--asst-font);
    border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
    animation: asst-in .14s ease-out;
}
.asst-panel:focus { outline: none; }
@keyframes asst-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ---- Antetul: avatarul-marcă, titlul cu chipul „AI”, nota permanentă, „Conversație nouă” și „Închide”. ---- */
.asst-head {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 10px 14px var(--asst-gap); border-bottom: 1px solid var(--line); background: var(--elevated);
}
.asst-avatar {
    flex: none; display: inline-flex; width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
    background: var(--wall); border: 1px solid var(--line);
}
.asst-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.asst-avatar-sm { width: 26px; height: 26px; margin-top: 2px; }
.asst-headtext { flex: 1 1 auto; min-width: 0; }
.asst-titlerow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.asst-title {
    margin: 0; font-family: var(--font-display, var(--asst-font)); font-size: var(--fs-lg, 17px); font-weight: 700;
    line-height: var(--lh-tight, 1.25); letter-spacing: -.01em; color: var(--ink);
}
.asst-badge {
    display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: var(--r-chip);
    border: 1px solid var(--line-2); background: var(--inset); color: var(--ink-2);
    font-size: 11.5px; font-weight: 700; line-height: 1; letter-spacing: .03em;
}
/* Avertismentul stă în antet: rămâne vizibil oricât de lungă e conversația. */
.asst-note { margin: 3px 0 0; font-size: 13px; line-height: var(--lh-snug, 1.4); color: var(--ink-2); }
.asst-tools { flex: none; display: flex; gap: 2px; margin-top: -4px; }
.asst-tools .btn.icon { width: 40px; height: 40px; }

/* ---- Conversația ---- */
.asst-log {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    display: flex; flex-direction: column; gap: 14px; padding: 16px var(--asst-gap); background: var(--ground);
}
.asst-msg { display: flex; align-items: flex-start; gap: 8px; max-width: 92%; min-width: 0; }
.asst-msg.asst-user { align-self: flex-end; justify-content: flex-end; }
.asst-msg.asst-assistant, .asst-msg.asst-refused { align-self: flex-start; }
.asst-bubble {
    min-width: 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 4px 14px 14px 14px;
    background: var(--surface); color: var(--ink);
    font-size: 15px; line-height: var(--lh-base, 1.55); overflow-wrap: anywhere;
}
/* Bula omului: selectat = umplere de cerneală (teal rămâne pentru acțiuni). */
.asst-user .asst-bubble {
    border-color: var(--ink); border-radius: 14px 4px 14px 14px; background: var(--ink); color: var(--ink-inv);
    white-space: pre-wrap;
}
.asst-refused .asst-bubble { border-left: 3px solid var(--warn); }
.asst-bubble > :first-child { margin-top: 0; }
.asst-bubble > :last-child { margin-bottom: 0; }
.asst-bubble p { margin: 0 0 10px; }
.asst-bubble ul, .asst-bubble ol { margin: 0 0 10px; padding-left: 20px; }
.asst-bubble li + li { margin-top: 4px; }
.asst-bubble li::marker { color: var(--ink-3); }
.asst-bubble strong { font-weight: 700; }
.asst-bubble .asst-h { font-weight: 700; margin-top: 4px; }
.asst-bubble a, .asst-human, .asst-error a, .asst-privacy a, .asst-handoff a {
    color: var(--teal-text); text-decoration: underline; text-underline-offset: .18em;
}

/* Sursele: cipuri cu iconiță de document, titlul tăiat cu „…” dacă e lung. */
.asst-chips { list-style: none; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; }
.asst-chips li { max-width: 100%; min-width: 0; }
.asst-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 30px; padding: 4px 11px 4px 9px;
    border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); color: var(--teal-text);
    font-size: 13px; font-weight: 600; line-height: 1.2; text-decoration: none;
    transition: background .12s, border-color .12s;
}
.asst-chip:hover { background: var(--inset); border-color: var(--teal); text-decoration: none; }
.asst-chip .i { flex: none; }
.asst-chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asst-ai-label { margin: 10px 0 0; font-size: 12.5px; line-height: 1.4; color: var(--ink-3); }
.asst-handoff { margin: 8px 0 0; font-size: 14px; }

/* Indicatorul de așteptare: doar cât durează cererea reală, fără întârziere care să imite tastarea unui om. */
.asst-typing .asst-bubble { display: inline-flex; align-items: center; gap: 5px; min-height: 40px; padding: 10px 14px; }
.asst-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: asst-dot 1.2s ease-in-out infinite; }
.asst-dot:nth-child(2) { animation-delay: .2s; }
.asst-dot:nth-child(3) { animation-delay: .4s; }
@keyframes asst-dot {
    0%, 80%, 100% { opacity: .25; }
    40% { opacity: 1; }
}

/* Întrebările sugerate: în starea goală, aliniate cu bula de bun venit. */
.asst-suggestions { list-style: none; margin: -4px 0 0; padding: 0 0 0 34px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.asst-suggest {
    display: inline-flex; align-items: center; max-width: 100%; min-height: 40px; padding: 8px 14px;
    border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); color: var(--ink);
    font: 500 14px/1.3 var(--asst-font); text-align: left; white-space: normal; cursor: pointer;
    transition: background .12s, border-color .12s;
}
.asst-suggest:hover { background: var(--inset); border-color: var(--teal); }
.asst-suggest:disabled { opacity: .5; cursor: not-allowed; }

.asst-status { margin: 0; padding: 8px var(--asst-gap) 0; font-size: 13px; line-height: 1.4; color: var(--ink-2); background: var(--elevated); }
.asst-status:empty { display: none; }
.asst-error { margin: 8px var(--asst-gap) 0; font-size: 13.5px; }
.asst-remaining { margin: 8px var(--asst-gap) 0; font-size: 13px; color: var(--ink-2); }

/* ---- Întrebarea: caseta Turnstile deasupra, câmpul care crește, trimiterea în dreapta, nota dedesubt. ---- */
.asst-form {
    display: flex; flex-direction: column; gap: 8px; padding: 12px var(--asst-gap) 4px;
    border-top: 1px solid var(--line); background: var(--elevated);
}
/* Caseta stă afișată din prima verificare (Turnstile nu se randează corect într-un container display: none), dar fără
   înălțime cât provocarea e invizibilă; scriptul pune .is-interactive doar când omul trebuie să bifeze. */
.asst-turnstile { max-width: 100%; overflow: hidden; }
.asst-turnstile:not(.is-interactive) { height: 0; margin-bottom: -8px; }
.asst-compose {
    display: flex; align-items: flex-end; gap: 8px; padding: 4px 4px 4px 0;
}
/* 16 px: pe telefon câmpul nu declanșează mărirea automată a paginii la focalizare. */
.asst-input {
    flex: 1 1 auto; min-width: 0; width: 100%; min-height: 44px; max-height: 140px; height: 44px;
    padding: 11px 12px; font-size: 16px; line-height: 1.35; resize: none; overflow-y: auto;
}
.asst-send { flex: none; width: 44px; height: 44px; padding: 0; }
.asst-send .i { margin: 0; }
.asst-count { min-width: 0; font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.asst-count.is-near { color: var(--warn-text); }
.asst-privacy { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-3); }
.asst-foot { margin: 0; padding: 8px var(--asst-gap) 14px; font-size: 14px; background: var(--elevated); }

/* ---- Telefon: butonul devine cerc (numele rămâne pentru cititorul de ecran), panoul ia tot ecranul vizibil. ---- */
@media (max-width: 560px) {
    .asst { --asst-gap: 14px; }
    .asst-launcher { width: 56px; height: 56px; padding: 0; justify-content: center; }
    .asst-launcher .i { width: 24px; height: 24px; }
    .asst-launcher-text {
        position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
        clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
    }
    .asst-panel {
        top: var(--asst-vtop, 0px); left: 0; right: 0; bottom: auto;
        width: 100%; max-width: none; height: 100vh; height: var(--asst-vh, 100dvh);
        border: 0; border-radius: 0; animation-name: asst-in-phone;
    }
    .asst-head {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        padding-left: calc(var(--asst-gap) + env(safe-area-inset-left, 0px));
        padding-right: calc(6px + env(safe-area-inset-right, 0px));
    }
    .asst-log, .asst-form {
        padding-left: calc(var(--asst-gap) + env(safe-area-inset-left, 0px));
        padding-right: calc(var(--asst-gap) + env(safe-area-inset-right, 0px));
    }
    .asst-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
    .asst-msg { max-width: 94%; }
    .asst-suggestions { padding-left: 0; }
}
@keyframes asst-in-phone {
    from { opacity: 0; }
    to { opacity: 1; }
}
/* Cât panoul e pe tot ecranul, pagina de dedesubt nu se derulează (clasa o pune scriptul doar pe telefon). */
html.asst-lock, html.asst-lock body { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
    .asst-panel { animation: none; }
    .asst-dot { animation: none; opacity: .6; }
    .asst-launcher, .asst-chip, .asst-suggest { transition: none; }
}

@media print {
    .asst { display: none !important; }
}
