/* ==========================================================================
   GESIB.RO - Funcții AI în magazin: asistentul de cumpărături (widget flotant) și pagina „Listă școlară”.
   Folosește variabilele din app.css (mod luminos / întunecat prin [data-theme]).
   Poziționare: lansatorul se așază DEASUPRA butonului WhatsApp (.wa-float) și deasupra barei de navigare mobile (64px)
   sau a barei sticky de cumpărare (body.has-buybar), fără suprapuneri. Pe mobil panoul este o foaie (bottom sheet) care
   se oprește deasupra barei de jos.
   ========================================================================== */

:root {
    --ai-nav-h: 64px;        /* bara de navigare mobilă */
}
body.has-buybar {
    --ai-nav-h: 68px;        /* bara sticky de cumpărare */
}

/* --------------------------------------------------------------------------
   Lansator
   -------------------------------------------------------------------------- */
.ai-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 940;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 18px 0 14px;
    border: 0;
    border-radius: 999px;
    background: var(--brand-red);
    color: #FFFFFF;
    font: 700 14px/1 var(--font-main, sans-serif);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ai-launcher.has-wa {
    bottom: calc(20px + 56px + 12px);   /* peste .wa-float (56px la 20px) */
}
.ai-launcher:hover { transform: scale(1.04); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34); }
.ai-launcher:focus-visible { outline: 3px solid var(--brand-red-soft); outline-offset: 2px; }
.ai-launcher svg { width: 22px; height: 22px; flex-shrink: 0; }
.ai-launcher[hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   Panou (desktop)
   -------------------------------------------------------------------------- */
.ai-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 950;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: min(600px, calc(100vh - 40px));
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg, 14px);
    box-shadow: var(--shadow-modal, 0 20px 45px rgba(15, 23, 42, 0.22));
    overflow: hidden;
}
.ai-panel.has-wa { bottom: calc(20px + 56px + 12px); height: min(600px, calc(100vh - 108px)); }
.ai-panel[hidden] { display: none !important; }

.ai-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--brand-red);
    color: #FFFFFF;
}
.ai-head-title { flex: 1 1 auto; min-width: 0; font-size: 15px; font-weight: 800; line-height: 1.2; }
.ai-head-title small { display: block; font-size: 11.5px; font-weight: 500; opacity: 0.9; }
.ai-icon-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #FFFFFF;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}
.ai-icon-btn:hover { background: rgba(255, 255, 255, 0.3); }
.ai-icon-btn svg { width: 18px; height: 18px; }

.ai-log {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
    background: var(--bg-page);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ai-msg {
    max-width: 92%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.ai-msg--bot { align-self: flex-start; background: var(--bg-surface); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; }
.ai-msg--user { align-self: flex-end; background: var(--brand-red); color: #FFFFFF; border-bottom-right-radius: 4px; }
.ai-msg--err { align-self: stretch; max-width: 100%; background: var(--brand-red-soft); color: var(--brand-red-text); border: 1px solid var(--brand-red); }
.ai-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 10px 14px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 14px; }
.ai-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: ai-bounce 1.1s infinite ease-in-out; }
.ai-typing i:nth-child(2) { animation-delay: 0.15s; }
.ai-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.45; } 40% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ai-typing i { animation: none; } .ai-launcher { transition: none; } }

.ai-cards { align-self: stretch; display: flex; flex-direction: column; gap: 8px; }
.ai-card {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 10px;
    padding: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 10px);
}
.ai-card-img { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: #FFFFFF; }
.ai-card-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ai-card-name { color: var(--text-primary); font-size: 13px; font-weight: 700; line-height: 1.3; text-decoration: none; overflow-wrap: anywhere; }
.ai-card-name:hover { color: var(--brand-red-text); text-decoration: underline; }
.ai-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12px; color: var(--text-muted); }
.ai-card-price { font-size: 14px; font-weight: 800; color: var(--text-primary); }
.ai-stock-ok { color: #15803D; font-weight: 700; }
.ai-stock-no { color: #64748B; font-weight: 700; }
.ai-stock-low { color: #C2410C; font-weight: 700; }
.ai-stock-last { color: #B91C1C; font-weight: 700; }
[data-theme="dark"] .ai-stock-low { color: #FB923C; }
[data-theme="dark"] .ai-stock-last { color: #F87171; }
[data-theme="dark"] .ai-stock-no { color: #94A3B8; }
.ai-add {
    align-self: flex-start;
    margin-top: 3px;
    min-height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: var(--brand-red);
    color: #FFFFFF;
    font: 700 12.5px/1 var(--font-main, sans-serif);
    cursor: pointer;
}
.ai-add:hover { background: var(--brand-red-hover); }
.ai-add[disabled] { opacity: 0.5; cursor: not-allowed; }

.ai-foot { flex: 0 0 auto; padding: 8px 10px 10px; border-top: 1px solid var(--border-color); background: var(--bg-surface); }
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ai-chips[hidden] { display: none; }
.ai-chip {
    padding: 6px 11px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font: 600 12px/1.2 var(--font-main, sans-serif);
    cursor: pointer;
}
.ai-chip:hover { border-color: var(--brand-red); color: var(--brand-red-text); }
.ai-form { display: flex; align-items: flex-end; gap: 8px; }
.ai-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 42px;
    max-height: 110px;
    resize: none;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    font: 14px/1.35 var(--font-main, sans-serif);
    box-sizing: border-box;
}
.ai-input:focus { outline: none; border-color: var(--brand-red); box-shadow: 0 0 0 3px var(--brand-red-soft); }
.ai-send {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: var(--brand-red);
    color: #FFFFFF;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ai-send svg { width: 18px; height: 18px; }
.ai-send[disabled] { opacity: 0.5; cursor: not-allowed; }
.ai-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.ai-note { margin: 6px 2px 0; font-size: 11px; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Mobil / tabletă (≤1024px): foaie care se oprește deasupra barei de jos; lansator cerc, deasupra WhatsApp
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
    .ai-launcher {
        right: 12px;
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
        bottom: calc(var(--ai-nav-h) + 14px + env(safe-area-inset-bottom, 0px));   /* ca .wa-float */
    }
    .ai-launcher .ai-launcher-label { display: none; }
    .ai-launcher.has-wa {
        bottom: calc(var(--ai-nav-h) + 14px + 44px + 10px + env(safe-area-inset-bottom, 0px));   /* peste .wa-float (44px) */
    }
    .ai-panel,
    .ai-panel.has-wa {
        left: 0;
        right: 0;
        width: auto;
        max-width: none;
        bottom: calc(var(--ai-nav-h) + env(safe-area-inset-bottom, 0px));
        height: min(78vh, calc(100vh - var(--ai-nav-h) - 70px));
        height: min(78dvh, calc(100dvh - var(--ai-nav-h) - 70px));
        border-radius: 16px 16px 0 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
    }
    .ai-input { font-size: 16px; }              /* fără zoom automat în iOS */
    .ai-icon-btn { width: 44px; height: 44px; }
    .ai-add { min-height: 40px; }
    .ai-chip { min-height: 36px; }
    body.ai-open .wa-float { display: none; }   /* foaia acoperă zona butonului WhatsApp */
    html.ai-lock, html.ai-lock body { overflow: hidden; }
}

/* ==========================================================================
   PAGINA „LISTĂ ȘCOLARĂ” (/lista-scolara)
   ========================================================================== */
.sl-wrap { max-width: 1180px; margin: 24px auto 56px; padding: 0 16px; box-sizing: border-box; color: var(--text-primary); }
.sl-wrap *, .sl-wrap *::before, .sl-wrap *::after { box-sizing: border-box; }
.sl-head h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.2; }
.sl-lead { margin: 0 0 18px; color: var(--text-secondary); max-width: 780px; }
.sl-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 12px; padding: 18px; margin: 0 0 16px; }
.sl-card[hidden] { display: none !important; }
.sl-h2 { margin: 0 0 12px; font-size: 17px; }
.sl-note { padding: 14px 16px; border: 1px solid var(--border-color); border-left: 4px solid var(--brand-red); border-radius: 10px; background: var(--bg-surface); }
.sl-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; }
.sl-label { display: block; margin: 0 0 6px; font-size: 13px; font-weight: 700; }
.sl-textarea, .sl-file {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text-primary);
    font: 14px/1.45 var(--font-main, sans-serif);
}
.sl-textarea { resize: vertical; min-height: 150px; }
.sl-textarea:focus { outline: none; border-color: var(--brand-red); box-shadow: 0 0 0 3px var(--brand-red-soft); }
.sl-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--text-muted); }
.sl-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.sl-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.sl-btn {
    min-height: 42px;
    padding: 0 18px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font: 700 14px/1 var(--font-main, sans-serif);
    cursor: pointer;
}
.sl-btn:hover { border-color: var(--border-hover); background: var(--bg-subtle); }
.sl-btn--primary { background: var(--brand-red); border-color: var(--brand-red); color: #FFFFFF; }
.sl-btn--primary:hover { background: var(--brand-red-hover); border-color: var(--brand-red-hover); }
.sl-btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.sl-msg { min-height: 20px; margin-top: 10px; font-size: 13.5px; }
.sl-msg.is-err { color: var(--brand-red-text); font-weight: 600; }
.sl-msg.is-ok { color: #15803D; font-weight: 600; }

.sl-rows-head, .sl-row {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 2.2fr) 92px 110px 44px;
    gap: 12px;
    align-items: center;
}
.sl-rows-head { padding: 0 12px 8px; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.sl-row { padding: 12px; margin: 0 0 8px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-subtle); }
.sl-row.is-none { border-style: dashed; }
.sl-req { min-width: 0; overflow-wrap: anywhere; }
.sl-req b { display: block; font-size: 14px; }
.sl-req small { color: var(--text-muted); font-size: 12.5px; }
.sl-prod { min-width: 0; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 10px; align-items: start; }
.sl-prod img, .sl-prod .sl-noimg { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: #FFFFFF; border: 1px solid var(--border-color); }
.sl-pname { display: block; color: var(--text-primary); font-size: 13.5px; font-weight: 700; line-height: 1.3; text-decoration: none; overflow-wrap: anywhere; }
.sl-pname:hover { color: var(--brand-red-text); text-decoration: underline; }
.sl-pmeta { margin-top: 3px; font-size: 12.5px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.sl-select {
    width: 100%;
    margin-top: 6px;
    min-height: 38px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font: 13px/1.2 var(--font-main, sans-serif);
}
.sl-qty { width: 100%; min-height: 40px; padding: 0 8px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-input); color: var(--text-primary); font: 700 14px/1 var(--font-main, sans-serif); text-align: center; }
.sl-qty:focus, .sl-select:focus { outline: none; border-color: var(--brand-red); box-shadow: 0 0 0 3px var(--brand-red-soft); }
.sl-line { font-weight: 800; text-align: right; font-size: 14px; }
.sl-rm { width: 40px; height: 40px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-surface); color: var(--text-muted); cursor: pointer; font-size: 16px; line-height: 1; }
.sl-rm:hover { border-color: var(--brand-red); color: var(--brand-red-text); }
.sl-lbl { display: none; }
.sl-reason { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.sl-total { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-color); }
.sl-total strong { font-size: 18px; }
/* niveluri de preț: bugetul întregii liste + alegerea rapidă pe fiecare articol */
.sl-budget { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-surface); }
.sl-budget-lbl { font-size: 13.5px; font-weight: 700; margin-right: 4px; }
.sl-tierbtn { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 1px; min-height: 44px; padding: 6px 14px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-subtle); color: var(--text-primary); cursor: pointer; font: inherit; text-align: left; }
.sl-tierbtn b { font-size: 13px; }
.sl-tierbtn span { font-size: 12.5px; color: var(--text-muted); }
.sl-tierbtn:hover { border-color: var(--brand-red); }
.sl-tierbtn.is-active { border-color: var(--brand-red); background: var(--brand-red-soft); box-shadow: inset 0 0 0 1px var(--brand-red); }
.sl-tierbtn.is-active span { color: var(--text-primary); }
.sl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.sl-chip { min-height: 32px; padding: 4px 10px; border: 1px solid var(--border-color); border-radius: 999px; background: var(--bg-surface); color: var(--text-primary); cursor: pointer; font: 12.5px/1.2 var(--font-main, sans-serif); }
.sl-chip b { font-weight: 800; }
.sl-chip:hover { border-color: var(--brand-red); }
.sl-chip.is-on { border-color: var(--brand-red); background: var(--brand-red-soft); color: var(--brand-red-text); }
.sl-chip.is-out { opacity: .6; }
.sl-alllbl { display: block; margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.sl-alllbl .sl-select { margin-top: 3px; }
.sl-foot { margin-top: 8px; font-size: 13px; color: var(--text-muted); }
.sl-foot a, .sl-note a, .sl-hint a { color: var(--brand-red-text); font-weight: 600; }

@media (max-width: 860px) {
    .sl-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
    .sl-wrap { margin: 14px auto 32px; padding: 0 14px; }
    .sl-head h1 { font-size: 22px; }
    .sl-card { padding: 14px; }
    .sl-actions .sl-btn { flex: 1 1 100%; min-height: 46px; }
    .sl-textarea, .sl-qty, .sl-select { font-size: 16px; }
    .sl-rows-head { display: none; }
    /* carduri suprapuse, fără overflow */
    .sl-row {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "req rm" "prod prod" "qty line";
        gap: 10px;
    }
    .sl-req { grid-area: req; }
    .sl-rm { grid-area: rm; justify-self: end; }
    .sl-prod { grid-area: prod; }
    .sl-qtywrap { grid-area: qty; display: flex; align-items: center; gap: 8px; }
    .sl-qtywrap .sl-qty { width: 96px; }
    .sl-line { grid-area: line; align-self: center; }
    .sl-lbl { display: inline; font-size: 12px; color: var(--text-muted); font-weight: 600; }
    .sl-total { flex-direction: column; align-items: stretch; }
    .sl-total .sl-btn { width: 100%; min-height: 48px; }
    .sl-budget { padding: 10px; }
    .sl-budget-lbl { flex: 1 1 100%; }
    .sl-tierbtn { flex: 1 1 0; min-width: 0; padding: 6px 8px; }
    .sl-chip { min-height: 36px; }
}
