/* ==========================================================================
   ASISTENT VIRTUAL DERMALISNIC - v11.3 (Fixed UI & UX)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Blochează scroll-ul paginii principale când asistentul este activ */
body.avd-active {
    overflow: hidden !important;
}

/* --------------------------------------------------------------------------
   PRELOADER
   -------------------------------------------------------------------------- */
#avd-preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #0a101a;
    z-index: 1000000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: opacity 0.8s, visibility 0.8s;
}

.loading-logo {
    width: 180px;
    animation: pulse 2.5s infinite ease-in-out;
}

@keyframes pulse {
    50% { opacity: 1; transform: scale(1.05); }
}

#loading-text {
    margin-top: 24px;
    font-size: 14px;
    letter-spacing: 0.5px;
}

.loading-bar {
    width: 180px;
    height: 4px;
    background-color: #374151;
    border-radius: 2px;
    margin-top: 15px;
    overflow: hidden;
}

#loading-bar-inner {
    width: 10%;
    height: 100%;
    background-color: #00e0ff;
    transition: width 1.5s cubic-bezier(0.65, 0, 0.35, 1);
}

/* --------------------------------------------------------------------------
   CONTAINER PRINCIPAL
   -------------------------------------------------------------------------- */
#avd-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    z-index: 999999;
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    line-height: 1.6;
    background-color: #0a101a;
    opacity: 0;
    visibility: hidden;
    height: 100dvh; /* Modern browsers */
    height: calc(var(--vh, 1dvh) * 100); /* Fallback JS */
    
    /* Variabile de Culoare */
    --brand-blue: #143362;
    --brand-red: #d81e2c;
    --accent-cyan: #00e0ff;
    --text-light: #e5e7eb;
    --text-dark: #1f2937;
    --bg-light: #ffffff;
    --bg-dark: #0a101a;
    --panel-light: #f3f4f6;
    --panel-dark: #1f2937;
    --border-light: #e5e7eb;
    --border-dark: #374151;
}

#avd-container.visible {
    opacity: 1;
    visibility: visible;
}

#avd-container *,
#avd-container *::before,
#avd-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0 solid currentColor;
}

.avd-root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    color: var(--text-dark);
    background-color: var(--bg-light);
    opacity: 0;
    transition: opacity 0.5s;
    position: relative;
    overflow: hidden;
}

#avd-container.dark .avd-root {
    color: var(--text-light);
    background-color: var(--bg-dark);
}

/* --------------------------------------------------------------------------
   HEADER
   -------------------------------------------------------------------------- */
.avd-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 1rem;
    z-index: 10;
}

#avd-container.dark .avd-header {
    border-bottom-color: var(--border-dark);
}

.avd-header-brand a {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 14px;
}

.avd-header-brand img {
    height: 40px;
    width: 40px;
    border-radius: 50%;
}

.avd-header-brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.avd-header-nav a {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-dark);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s;
}

#avd-container.dark .avd-header-nav a {
    color: var(--text-light);
}

#avd-container.dark .avd-header-nav a:hover {
     color: var(--accent-cyan);
}

/* --------------------------------------------------------------------------
   ZONA DE CHAT (SCROLL FIX)
   -------------------------------------------------------------------------- */
.avd-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
    /* FIX SCROLL: Folosim flex-start și margin-top: auto pe primul copil */
    justify-content: flex-start;
}

/* Împinge mesajele jos când sunt puține */
.avd-chat-messages > :first-child {
    margin-top: auto;
}

.avd-chat-messages.initial-state {
    justify-content: center;
}
.avd-chat-messages.initial-state > :first-child {
    margin-top: 0;
}

/* Background image */
.avd-chat-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('https://dermalisnic.ro/wp-content/uploads/2025/10/asistent-dermalisnic-lateral.png');
    background-size: cover;
    background-position: center;
    z-index: 0;
    opacity: 0.05;
    transition: opacity 0.5s;
    pointer-events: none; /* Permite click prin imagine */
}

#avd-container.dark .avd-chat-messages::before {
    opacity: 0.1;
}

/* --------------------------------------------------------------------------
   BULE DE MESAJE
   -------------------------------------------------------------------------- */
.avd-bubble {
    padding: 12px 18px;
    border-radius: 18px;
    max-width: 85%;
    width: fit-content;
    word-wrap: break-word;
    position: relative;
    z-index: 1;
    line-height: 1.6;
    opacity: 0;
    animation: popIn 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    transform: translateY(10px);
}

@keyframes popIn {
    to { opacity: 1; transform: translateY(0); }
}

/* Stiluri pentru textul din interiorul bulei (inclusiv noul bold) */
.avd-bubble p {
    margin: 0;
    padding-right: 20px; /* Loc pt buton copiere */
}
.avd-bubble strong {
    font-weight: 700;
    color: inherit;
}
.avd-bubble a {
    color: inherit;
    text-decoration: underline;
}
.avd-bubble ul {
    margin: 0.5rem 0 0.5rem 1.5rem;
}
.avd-bubble li {
    margin-bottom: 0.25rem;
}

/* BOT Bubble */
.avd-bubble.bot {
    background-color: var(--panel-light);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

#avd-container.dark .avd-bubble.bot {
    background-color: rgba(31, 41, 55, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(55, 65, 81, 0.5);
}

/* USER Bubble */
.avd-bubble.user {
    background: linear-gradient(145deg, var(--brand-blue), #1a427d);
    color: var(--text-light);
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    border: 1px solid rgba(0, 224, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Buton Copiere */
.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
    z-index: 2;
}
.avd-bubble.bot:hover .copy-btn { opacity: 0.7; }
.copy-btn:hover { opacity: 1 !important; background: rgba(0, 0, 0, 0.2); }

#avd-container.dark .copy-btn { background: rgba(255, 255, 255, 0.1); color: #9ca3af; }
#avd-container.dark .copy-btn:hover { background: rgba(255, 255, 255, 0.2); }

/* --------------------------------------------------------------------------
   ZONA DE INPUT & BUTOANE (VISIBILITY FIX)
   -------------------------------------------------------------------------- */
.avd-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    background-color: rgba(255, 255, 255, 0.85); /* Mai opac pentru contrast */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10;
}

#avd-container.dark .avd-input-area {
    background-color: rgba(10, 16, 26, 0.85);
    border-top-color: var(--border-dark);
}

.avd-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

#chat-input-main {
    flex-grow: 1;
    width: 100%;
    min-width: 50px;
    padding: 1rem 1.5rem;
    border-radius: 24px;
    border: 2px solid var(--border-light);
    background-color: var(--bg-light);
    color: var(--text-dark);
    transition: all 0.2s;
    resize: none;
    overflow-y: hidden;
    line-height: 1.5;
    min-height: 54px;
    max-height: 150px;
}
#chat-input-main:focus {
    outline: none;
    border: 2px solid var(--brand-blue);
    box-shadow: 0 0 10px rgba(20, 51, 98, 0.2);
}
#avd-container.dark #chat-input-main {
    background-color: var(--panel-dark);
    border-color: var(--border-dark);
    color: var(--text-light);
}
#avd-container.dark #chat-input-main:focus {
    border: 2px solid var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 224, 255, 0.2);
}

/* BUTOANE UTILITARE (Cameră, Upload, Reset) - FIX VIZIBILITATE */
.avd-btn {
    background-color: rgba(0, 0, 0, 0.05); /* Fundal ușor vizibil */
    border: 1px solid transparent;
    cursor: pointer;
    padding: 0.6rem;
    margin-bottom: 0.5rem;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--brand-blue); /* Culoare vizibilă */
    flex-shrink: 0;
}

.avd-btn:hover {
    background-color: rgba(20, 51, 98, 0.1);
    transform: translateY(-2px);
}

#avd-container.dark .avd-btn {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--accent-cyan);
}
#avd-container.dark .avd-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.avd-input-wrapper .avd-btn svg { width: 24px; height: 24px; }

/* Butonul Trimite */
#send-btn-main {
    background-color: var(--brand-blue);
    color: white;
    padding: 0.8rem;
    border-radius: 50%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
#send-btn-main:hover {
    background-color: var(--brand-red);
    transform: scale(1.1) rotate(15deg);
}
#avd-container.dark #send-btn-main {
    background-color: var(--accent-cyan);
    color: var(--bg-dark);
}

/* Header Buttons override */
#avd-close-btn:hover { transform: scale(1.1); }

/* --------------------------------------------------------------------------
   MODAL CAMERĂ
   -------------------------------------------------------------------------- */
#camera-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.camera-content {
    background: #1f2937;
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 500px;
    width: 90%;
}
.camera-controls {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}
#camera-view {
    width: 100%;
    height: auto;
    border-radius: 8px;
}

/* --------------------------------------------------------------------------
   OPȚIUNI ÎN CHAT (Butoane mari)
   -------------------------------------------------------------------------- */
.chat-options {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.chat-choice-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 14px 20px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: 2px solid var(--brand-blue);
    background-color: rgba(20, 51, 98, 0.05); /* Fundal subtil */
    color: var(--brand-blue);
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.chat-choice-btn:hover {
    background-color: var(--brand-blue);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

#avd-container.dark .chat-choice-btn {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background-color: rgba(0, 224, 255, 0.05);
}

#avd-container.dark .chat-choice-btn:hover {
    background-color: var(--accent-cyan);
    color: var(--bg-dark);
}

/* --------------------------------------------------------------------------
   ANIMAȚII
   -------------------------------------------------------------------------- */
.image-scan-container {
    position: relative;
    display: inline-block;
    overflow: hidden;
    border-radius: 12px;
}

.image-scan-container::before {
    content: '';
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--accent-cyan);
    box-shadow: 0 0 10px 2px var(--accent-cyan);
    opacity: 0;
}

.image-scan-container.is-scanning::before {
    opacity: 0.8;
    animation: scan-animation 2.5s ease-in-out infinite;
}

@keyframes scan-animation {
    0% { top: -10%; }
    100% { top: 110%; }
}

/* Linii Verticale Fundal */
.avd-root::before,
.avd-root::after {
    content: '';
    position: absolute;
    top: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(to bottom, transparent, var(--accent-cyan), transparent);
    animation: vertical-scan 8s linear infinite;
    opacity: 0;
    transition: opacity 0.5s;
    z-index: 1;
    pointer-events: none;
}

#avd-container.dark .avd-root::before,
#avd-container.dark .avd-root::after {
    opacity: 0.2;
}

.avd-root::before { left: 0; }
.avd-root::after { right: 0; animation-delay: -4s; }

@keyframes vertical-scan {
    0% { transform: translateY(-100%); }
    100% { transform: translateY(100%); }
}

/* --------------------------------------------------------------------------
   MEDIA QUERIES (Mobil)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .avd-header-nav { display: none; }
    .avd-header-brand h1 { font-size: 1rem; }
    .avd-input-area { padding: 0.5rem; }
    .avd-input-wrapper { gap: 0.5rem; }
    .avd-btn { padding: 0.6rem; margin-bottom: 0.3rem; }
    .avd-input-wrapper .avd-btn svg { width: 22px; height: 22px; }
    #send-btn-main { padding: 0.7rem; }
    
    .chat-choice-btn {
        width: 100%;
        max-width: 100%;
        padding: 12px;
    }
}

.hidden { display: none !important; }