/* ==========================================================================
   AVEBASE DESIGN SYSTEM — LAYOUT
   Header public, sidebar zona logată, footer, container, grid utilitar.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Container
   -------------------------------------------------------------------------- */
.av-container {
    width: 100%;
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--space-4);
}
@media (min-width: 992px) {
    .av-container { padding-inline: var(--space-6); }
}
.av-container--narrow { max-width: 880px; }

/* --------------------------------------------------------------------------
   Header (public + logat)
   -------------------------------------------------------------------------- */
.av-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
/* Header FULL WIDTH (ca in UI-ul vechi): logo lipit de marginea stanga,
   actiunile de marginea dreapta; doar continutul paginilor are max-width. */
.av-header__inner {
    position: relative;
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding-inline: var(--space-4);
}
@media (min-width: 992px) {
    .av-header__inner { gap: var(--space-5); padding-inline: var(--space-5); }
}
/* Mobil: logo centrat absolut, burger + CTA "+" rămân în stânga, acțiunile în dreapta */
@media (max-width: 991.98px) {
    .av-header__inner { justify-content: space-between; }
    .av-header__logo {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }
    .av-main { padding-top: var(--space-3); }
}

/* CTA compact "+" (doar mobil, lângă burger) */
.av-btn--icon {
    padding: 0.6rem 0.8rem;
}
.av-header__logo { display: flex; align-items: center; flex-shrink: 0; }
.av-header__logo img { height: 36px; width: auto; display: block; }

/* ===== Logo în funcție de temă (specificitate > .av-header__logo img) ===== */
.av-header__logo img.av-logo-on-dark { display: none; }
[data-theme="dark"] .av-header__logo img.av-logo-on-light { display: none; }
[data-theme="dark"] .av-header__logo img.av-logo-on-dark { display: block; }

/* ===== Comutator temă light / dark ===== */
.av-theme-toggle {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    /* pe LIGHT: buton dark cu luna alba (preview al temei dark) */
    background: var(--color-onyx);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), filter var(--transition-fast);
}
.av-theme-toggle:hover { filter: brightness(1.35); }
/* pe DARK: buton deschis cu soare amber (preview al temei light) */
[data-theme="dark"] .av-theme-toggle {
    background: #f3f6f4;
    color: var(--color-amber);
    border-color: transparent;
}
.av-theme-toggle__sun { display: none; }
.av-theme-toggle__moon { display: inline-block; }
[data-theme="dark"] .av-theme-toggle__moon { display: none; }
[data-theme="dark"] .av-theme-toggle__sun { display: inline-block; color: var(--color-amber); }

.av-nav {
    display: none;
    align-items: center;
    gap: var(--space-2);
    margin-inline: auto;
}
@media (min-width: 992px) {
    .av-nav { display: flex; }
}
.av-nav__link {
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-pill);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}
.av-nav__link:hover { background-color: var(--bg-subtle); color: var(--text-heading); }
.av-nav__link.active { background-color: var(--color-emerald-light); color: var(--text-heading); }

/* Chip alb rotunjit pentru logo-uri curieri — rămâne ALB și pe dark (logo-urile
   au fundal transparent/colorat, trebuie pe alb ca să se vadă în ambele teme) */
.av-logo-chip {
    background: #fff !important;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.av-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-left: auto;
    flex-shrink: 0; /* grupul din dreapta NU se micsoreaza -> nu se mai suprapun bara credit + chip */
}
.av-header__actions > * { flex-shrink: 0; }
/* bara de credit e secundara (aceleasi date in dropdown/Portofel) -> doar pe ecrane largi,
   ca sa nu se inghesuie cu chip-ul de cont in nav */
@media (max-width: 1299.98px) {
    .av-credit-meter { display: none !important; }
}

/* Burger mobil */
.av-burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    cursor: pointer;
}
.av-burger span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background-color: var(--text-primary);
    transition: transform var(--transition-base), opacity var(--transition-base);
}
@media (min-width: 992px) {
    .av-burger { display: none; }
}
.av-burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.av-burger.open span:nth-child(2) { opacity: 0; }
.av-burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Meniu mobil (drawer simplu, fără dependență JS de framework) */
.av-mobile-menu {
    display: none;
    position: fixed;
    inset: var(--header-height) 0 0 0;
    z-index: 99;
    background-color: var(--bg-surface);
    padding: var(--space-5);
    overflow-y: auto;
}
.av-mobile-menu.open { display: block; }
.av-mobile-menu .av-nav__link { display: block; padding: var(--space-3) var(--space-4); font-size: var(--fs-base); }

/* --------------------------------------------------------------------------
   Structura generală a paginii
   -------------------------------------------------------------------------- */
/* plasă de siguranță anti scroll orizontal pe mobil (fișierul se încarcă
   doar în shell-ul Avebase, deci nu afectează UI-ul vechi) */
html, body { overflow-x: hidden; }

/* elementul Metronic de scroll-top din markup-ul păstrat nu are stiluri în
   tema nouă → ar randa ca bloc static la finalul paginii (spațiu mort) */
.avebase-ui .scrolltop { display: none !important; }

/* headerul e FIXED (sticky e anulat de overflow-x pe ancestori) — pagina
   compensează cu padding-top */
.av-page { display: flex; flex-direction: column; min-height: 100vh; padding-top: var(--header-height); }

/* Search în header */
.av-header__search { width: 220px; }
.av-header__search .form-control { border-radius: var(--radius-pill); }

/* Chip cont in header — card subtil, 2 randuri aliniate, light + dark pe tokeni */
.av-userchip {
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    max-width: 280px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
    line-height: 1.2;
}
.av-userchip__top { display: flex; align-items: center; gap: 7px; max-width: 256px; }
.av-userchip__name {
    font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-heading);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px;
}
.av-userchip__lvl { flex-shrink: 0; }
.av-userchip__meta { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); white-space: nowrap; line-height: 1.2; }
.av-userchip__id { color: var(--color-warning); font-weight: var(--fw-bold); }
.av-userchip__credit { display: inline-flex; align-items: center; gap: 5px; color: var(--text-muted); }
.av-userchip__credit i { font-size: 11px; color: var(--text-muted); }
.av-userchip__credit-val { font-weight: var(--fw-bold); }
.av-userchip__credit-val small { font-weight: var(--fw-semibold); opacity: 0.7; }
.av-userchip__credit-val.is-neg { color: var(--color-danger); }
.av-userchip__credit-val.is-pos { color: var(--color-emerald-deep); }

/* Dropdown propriu (fără dependență de KTMenu/Bootstrap JS) */
.av-dropdown { position: relative; }
.av-dropdown__toggle { border: none; background: transparent; padding: 0; cursor: pointer; position: relative; }
.av-dropdown__menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 264px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3);
    z-index: 120;
}
.av-dropdown.open .av-dropdown__menu { display: block; }
.av-dropdown__head { padding: var(--space-2) var(--space-3); }
.av-dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.55rem var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    color: var(--text-primary);
}
.av-dropdown__item:hover { background-color: var(--bg-subtle); color: var(--color-navy); }
.av-dropdown__item .av-ico { width: 18px; text-align: center; color: var(--text-muted); }
.av-my-2 { margin-block: var(--space-2) !important; }

/* Avatar in header: nu se turteste, cerc complet, fundal restaurat (toggle-ul il facea transparent),
   alerta 2FA vizibila (nu clipuita), poza rotunda fara overflow pe container */
.av-avatar {
    flex-shrink: 0;
    overflow: visible;
    background-color: var(--color-emerald-light);
    color: var(--color-emerald-deep);
}
.av-avatar img { border-radius: var(--radius-pill); }

/* Alerta 2FA pe avatar */
.av-avatar__alert {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    background-color: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--color-warning);
    font-size: 11px;
    font-weight: var(--fw-bold);
}

/* Limita de credit din header (informație operațională completă, ca în UI-ul vechi) */
.av-credit-meter {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    text-align: center;
    min-width: 200px;
}
.av-credit-meter__title {
    display: block;
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-primary);
    margin-bottom: 2px;
}
.av-credit-meter__row { font-size: var(--fs-xs); color: var(--text-primary); margin-bottom: 4px; }
.av-credit-meter__track {
    height: 7px;
    border-radius: var(--radius-pill);
    background-color: var(--gray-200);
    overflow: hidden;
}
.av-credit-meter__bar {
    height: 100%;
    border-radius: var(--radius-pill);
    background-color: var(--color-emerald);
}

/* --------------------------------------------------------------------------
   Shell zona logată: sidebar + conținut
   -------------------------------------------------------------------------- */
/* flex: 1 — pe paginile scurte surplusul de înălțime din .av-page (min-height
   100vh) e absorbit AICI, în zona albă de conținut; altfel s-ar duce în
   margin-top:auto de pe footer și ar lăsa un gol alb uriaș în zona footerului */
.av-shell { display: flex; flex: 1 0 auto; min-height: calc(100vh - var(--header-height)); }
/* pe mobil conținutul scurt nu mai lasă gol mare înainte de banda CTA/footer */
@media (max-width: 991.98px) {
    .av-shell { min-height: auto; }
    .av-main { padding-bottom: var(--space-4); }
}

.av-sidebar {
    display: none;
    flex-direction: column;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: var(--space-3) var(--space-3) var(--space-7); /* sus strâns; jos generos ca ultimul item să rămână accesibil la scroll */
    gap: var(--space-1);
    /* scrollbar discret */
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}
.av-sidebar::-webkit-scrollbar { width: 6px; }
.av-sidebar::-webkit-scrollbar-track { background: transparent; }
.av-sidebar::-webkit-scrollbar-thumb { background-color: var(--gray-300); border-radius: var(--radius-pill); }
.av-sidebar::-webkit-scrollbar-thumb:hover { background-color: var(--color-emerald); }

/* Desktop: sidebar FIXED pe toată înălțimea (sub header, până jos);
   conținutul, banda CTA și footerul curg DOAR în dreapta lui. */
@media (min-width: 992px) {
    .av-sidebar {
        display: flex;
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        overflow-y: auto;
        z-index: 90;
    }
    /* TOT conținutul (main, secțiuni full-width, banda CTA, footer) curge în
       dreapta sidebar-ului — padding pe wrapper, nu margini per element.
       Header-ul și sidebar-ul sunt fixed, deci nu sunt afectate. */
    .av-page--with-sidebar {
        padding-left: var(--sidebar-width);
    }
}
/* Pe mobil sidebar-ul devine drawer, deschis din burger */
@media (max-width: 991.98px) {
    .av-sidebar.open {
        display: flex;
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 99;
        width: min(85vw, 320px);
        overflow-y: auto;
        box-shadow: var(--shadow-lg);
    }
}

.av-sidebar__section {
    margin-top: var(--space-5);
    margin-bottom: var(--space-2);
    padding-inline: var(--space-3);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.av-sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.6rem var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-primary);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}
.av-sidebar__link:hover { background-color: var(--bg-subtle); color: var(--text-heading); }
.av-sidebar__link.active {
    background-color: var(--color-emerald-light);
    color: var(--text-heading);
    font-weight: var(--fw-semibold);
}
.av-sidebar__link .av-ico { width: 20px; text-align: center; color: var(--text-muted); }
.av-sidebar__link.active .av-ico, .av-sidebar__link:hover .av-ico { color: var(--color-emerald-deep); }

.av-main {
    flex: 1;
    min-width: 0;
    padding: var(--space-4) 0 var(--space-8);
}

/* Bara de titlu a paginii din zona logată */
.av-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.av-page-head h1 { margin: 0; font-size: var(--fs-2xl); }
.av-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}
.av-breadcrumb a { color: var(--text-muted); }
.av-breadcrumb a:hover { color: var(--link); }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.av-footer {
    background-color: var(--bg-inverse);
    color: var(--text-on-inverse);
    padding: var(--space-8) 0 var(--space-6);
    margin-top: auto;
}
.av-footer a { color: var(--gray-300); }
.av-footer a:hover { color: var(--color-emerald); }
.av-footer__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
}
@media (min-width: 768px) {
    .av-footer__grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
}
.av-footer__title {
    font-size: var(--fs-sm);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-emerald);
    margin-bottom: var(--space-3);
}
.av-footer__links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--fs-sm); }
.av-footer__bottom {
    margin-top: var(--space-7);
    padding-top: var(--space-5);
    border-top: 1px solid var(--gray-800);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: var(--fs-sm);
    color: var(--gray-400);
}

/* --------------------------------------------------------------------------
   Grid utilitar simplu (nu înlocuiește Bootstrap-ul folosit de JS,
   doar pentru layout-urile noilor pagini)
   -------------------------------------------------------------------------- */
.av-grid { display: grid; gap: var(--space-5); }
.av-grid--2 { grid-template-columns: 1fr; }
.av-grid--3 { grid-template-columns: 1fr; }
.av-grid--4 { grid-template-columns: 1fr 1fr; }
@media (min-width: 768px) {
    .av-grid--2 { grid-template-columns: repeat(2, 1fr); }
    .av-grid--3 { grid-template-columns: repeat(3, 1fr); }
    .av-grid--4 { grid-template-columns: repeat(4, 1fr); }
}

.av-stack > * + * { margin-top: var(--space-4); }
.av-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* Utilitare de spațiere minime */
.av-mt-0 { margin-top: 0 !important; }
.av-mb-0 { margin-bottom: 0 !important; }
.av-mt-4 { margin-top: var(--space-4) !important; }
.av-mb-4 { margin-bottom: var(--space-4) !important; }
.av-mt-6 { margin-top: var(--space-6) !important; }
.av-mb-6 { margin-bottom: var(--space-6) !important; }
.av-text-center { text-align: center !important; }
.av-hidden { display: none !important; }
@media (max-width: 991.98px) {
    .av-desktop-only { display: none !important; }
}
@media (min-width: 992px) {
    .av-mobile-only { display: none !important; }
}

/* ===== DARK: garantează text lizibil pentru utilitarele Metronic dark hardcodate =====
   (layout.css se încarcă ultimul, deci câștigă în cascadă) */
[data-theme="dark"] .avebase-ui .text-gray-900,
[data-theme="dark"] .avebase-ui .text-gray-800,
[data-theme="dark"] .avebase-ui .text-gray-700,
[data-theme="dark"] .avebase-ui .text-dark,
[data-theme="dark"] .avebase-ui .text-black { color: var(--text-primary) !important; }
[data-theme="dark"] .avebase-ui .text-gray-600 { color: var(--text-secondary) !important; }

/* ==========================================================================
   DARK — corecții punctuale (clasă Metronic .text-primary = navy; logo-chips;
   footer pe fundal mereu-dark)
   ========================================================================== */
/* Clasa .text-primary (navy) devine albastru deschis pe dark — vizibilă pe surse dark.
   (NU confunda cu variabila --text-primary, care e deja gestionată corect.) */
[data-theme="dark"] .avebase-ui .text-primary { color: var(--text-heading) !important; }

/* Logo-urile curieri rămân pe ALB pe dark, indiferent dacă bg-white e pe div (.av-logo-chip)
   sau direct pe <img> (tabele, select2). Specificitate > override-ul generic .bg-white. */
[data-theme="dark"] .avebase-ui .av-logo-chip,
[data-theme="dark"] .avebase-ui img.bg-white { background-color: #fff !important; }

/* Footer: fundalul e mereu dark (în ambele teme); pe dark scala gri inversată întuneca
   link-urile → le facem verde-deschis lizibil. */
[data-theme="dark"] .av-footer a { color: var(--color-emerald-soft); }
[data-theme="dark"] .av-footer a:hover { color: var(--color-emerald); }

/* DARK: btn-light-primary (navy pe navy-light) -> text deschis */
[data-theme="dark"] .avebase-ui .btn-light-primary { color: var(--text-heading); }
[data-theme="dark"] .avebase-ui .btn-light-primary:hover { color: var(--color-white); }
/* DARK: text-gray-900 în butoane toggle (.btn-check + .btn) — compat îl forța navy
   cu specificitate mai mare; îl readucem deschis pe dark */
[data-theme="dark"] .avebase-ui .btn-check + .btn .text-gray-900 { color: var(--text-heading) !important; }

/* Butoane „Schimbă tema" în meniuri (dropdown user + meniu mobil) — reset aspect nativ */
button.av-dropdown__item,
button.av-nav__link,
button.av-sidebar__link {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    text-align: left;
}
button.av-dropdown__item .av-ico { color: var(--color-emerald-deep); }
