/* ============================================================
   Contana Web — Temă albastru-petrol / teal închis
   ============================================================ */

:root {
    --primary: #0d7377;
    --primary-dark: #0a5c5f;
    --primary-light: #14a3a8;
    --bg: #f0f4f5;
    --bg-card: #ffffff;
    --text: #1a2a2b;
    --text-muted: #5f7375;
    --border: #c8d6d7;
    --danger: #d64550;
    --warning: #e09f3e;
    --success: #2d9f5e;
    --info: #3a7ca5;
    --sidebar-bg: #0B6C9B;      /* header + meniu (albastru, suficient de inchis
                                   ca textul alb sa aiba contrast bun) */
    --sidebar-text: #ffffff;    /* scrisul meniului */
    --sidebar-active: #FFD54F;  /* elementul curent — galben, se distinge clar */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    height: 56px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}
.role-badge {
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}
.role-badge.admin { background: var(--danger); color: #fff; }
.role-badge.contabil { background: var(--warning); color: #1a1a1a; }
.role-badge.client { background: rgba(255,255,255,0.22); color: #fff; }
.btn-logout {
    background: rgba(0,0,0,0.18);
    color: #fff;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* ============================================================
   Layout: sidebar + content
   ============================================================ */
.layout {
    display: flex;
    min-height: calc(100vh - 56px);
}
.sidebar {
    width: 200px;
    background: var(--sidebar-bg);
    padding: 16px 0;
    flex-shrink: 0;
    /* Meniul ramane pe loc cand derulezi continutul. Fara `sticky`, sidebar-ul
       urca odata cu pagina si dispare sub header (care e `sticky top: 0`).
       Inaltimea = ecranul minus headerul de 56px; daca meniul e mai lung
       decat atat, deruleaza el singur, nu impinge pagina. */
    position: sticky;
    top: 56px;
    align-self: flex-start;
    height: calc(100vh - 56px);
    overflow-y: auto;
}
.side-link {
    display: block;
    padding: 10px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: 0.15s;
    border-left: 3px solid transparent;
}
.side-link:hover { background: rgba(0,0,0,0.14); color: #fff; }
.side-link.active {
    background: rgba(0,0,0,0.18);
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
    font-weight: 600;
}
.content {
    flex: 1;
    padding: 24px 32px;
    max-width: 1600px;
    /* `width: 100%` intr-un flex container inseamna 100% din PARINTE, deci
       sidebar-ul (200px) se adauga peste => pagina iese cu 200px in dreapta.
       `min-width: 0` lasa elementul sa se micsoreze sub latimea continutului. */
    min-width: 0;
    margin: 0 auto;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.card h3 {
    margin-bottom: 16px;
    color: var(--primary-dark);
    font-size: 1.05rem;
}

/* ============================================================
   Stats Grid
   ============================================================ */
.stats-section h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0 0 8px 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stats-grid {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
}
.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.quick-links {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.quick-link-card {
    flex: 1;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    transition: 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.quick-link-card:hover {
    border-color: var(--primary);
    box-shadow: 0 3px 12px rgba(13,115,119,0.15);
}

/* ============================================================
   Tables
   ============================================================ */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.table th {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 12px 16px;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafa; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
}
.badge-success { background: #d4edda; color: #155724; }
/* bulina de mesaje necitite din meniul lateral */
.side-necitite { display:inline-block; min-width:18px; margin-left:6px; padding:0 6px; border-radius:9px;
    background: var(--danger, #dc2626); color:#fff; font-size:.72rem; font-weight:700; line-height:18px; text-align:center; }
.side-necitite[hidden] { display:none; }
.badge-danger { background: #f8d7da; color: #721c24; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 4px; color: var(--text-muted); font-weight: 500; }
.form-control {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: 0.15s;
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,115,119,0.1);
}
.form-sm { width: auto; min-width: 120px; }
.form-wide { min-width: 200px; }
.inline-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    white-space: nowrap;
    cursor: pointer;
}
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}
.checkbox-block {
    display: block;
    padding: 4px 0;
    cursor: pointer;
    font-size: 0.9rem;
}
/* Liste de firme cu bife și căutare (alege_firme.js) */
[data-alege-firme] { max-height: 320px; overflow-y: auto; }
.alege-firme-bara { position: sticky; top: 0; z-index: 1; background: var(--bg-card, #fff);
    padding: 0 0 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border, #e2e8f0); }
.alege-firme-cauta { width: 100%; }
.alege-firme-info { display: block; margin-top: 3px; color: #64748b; }
.alege-firme-gol { padding: 8px 0; color: #64748b; font-size: 0.88rem; }
[data-alege-firme] .checkbox-block:has(input:checked) { font-weight: 600; }
/* rândurile ascunse de căutare: atributul hidden trebuie să bată display:block */
[data-alege-firme] [hidden] { display: none !important; }
select.form-control { cursor: pointer; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-block;
    padding: 9px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.15s;
    font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #c78c35; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #2c6a8a; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

.action-btns { display: flex; gap: 4px; }

/* ============================================================
   Flash Messages
   ============================================================ */
.flash-messages { margin-bottom: 16px; }
.flash {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    border-left: 4px solid transparent;
}
.flash.success { background: #d4edda; border-left-color: var(--success); color: #155724; }
.flash.danger { background: #f8d7da; border-left-color: var(--danger); color: #721c24; }
.flash.warning { background: #fff3cd; border-left-color: var(--warning); color: #856404; }
.flash.info { background: #d1ecf1; border-left-color: var(--info); color: #0c5460; }

/* ============================================================
   Modal
   ============================================================ */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 200;
}
.modal-content {
    background: var(--bg-card);
    padding: 28px 32px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-content h3 {
    margin-bottom: 20px;
    color: var(--primary-dark);
}
.modal-content .btn { margin-right: 8px; margin-top: 8px; }

/* ============================================================
   Login Page
   ============================================================ */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0b6f9e 0%, #1196D1 50%, #46b8e8 100%);
}
.login-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 16px;
    width: 380px;
    max-width: 90%;
    box-shadow: 0 16px 48px rgba(0,0,0,0.25);
}
.login-logo {
    text-align: center;
    font-size: 1.6rem;
    color: var(--primary);
    margin-bottom: 4px;
}
.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 24px;
}

/* ============================================================
   Headings
   ============================================================ */
h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: var(--primary-dark);
}

/* ============================================================
   Firm chip în header (CUI + denumire firmă)
   ============================================================ */
.firm-chip {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    padding: 4px 12px;
    background: rgba(255,255,255,0.08);
    border-radius: 8px;
    margin-right: 4px;
}
.firm-chip-cui { font-size: 0.62rem; color: var(--sidebar-active); font-weight: 700; letter-spacing: 0.3px; }
.firm-chip-name { font-size: 0.82rem; color: #fff; font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.firm-chip { position: relative; flex-direction: row; align-items: center; gap: 8px; }
.firm-chip > span:not(.firm-chip-switch) { display: flex; flex-direction: column; line-height: 1.15; }
.firm-chip-switch { color: #fff; background: rgba(255,255,255,0.14); border-radius: 6px; padding: 2px 7px; font-size: 0.95rem; text-decoration: none; line-height: 1; }
.firm-chip-switch:hover { background: rgba(255,255,255,0.3); }
.firm-chip-none { background: rgba(220,80,80,0.22); }
.firm-chip-none .firm-chip-name { color: #ffd9d9; }

/* ============================================================
   Sidebar — secțiuni ierarhice expandabile
   ============================================================ */
.side-section { margin-bottom: 2px; }
.side-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    cursor: pointer;
    user-select: none;
    transition: 0.15s;
}
.side-section-header:hover { background: rgba(0,0,0,0.14); color: #fff; }
.side-section-header .chevron { font-size: 0.7rem; color: var(--sidebar-text); transition: transform 0.2s; }
.side-section.open > .side-section-header .chevron { transform: rotate(90deg); }
.side-section-body { display: none; padding: 2px 0 6px; }
.side-section.open > .side-section-body { display: block; }
.side-sub {
    display: block;
    padding: 8px 20px 8px 32px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: 0.15s;
}
.side-sub:hover { background: rgba(0,0,0,0.14); color: #fff; }
.side-sub.active {
    background: rgba(0,0,0,0.18);
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
    font-weight: 700;
}
.side-sub.disabled { opacity: 0.62; cursor: default; }
.side-sub.disabled:hover { background: none; color: var(--sidebar-text); }

/* ============================================================
   Toolbar (buton acțiune + filtre)
   ============================================================ */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.form-row .form-group { flex: 1; min-width: 160px; }

/* ============================================================
   Badge-uri status documente (plan §5)
   ============================================================ */
.badge-contat { background: #d4edda; color: #155724; }
.badge-necontat { background: #d1ecf1; color: #0c5460; }
.badge-neclar { background: #fff3cd; color: #856404; }
.badge-draft { background: #fff3cd; color: #856404; }
.badge-validata { background: #d4edda; color: #155724; }

/* ============================================================
   Search dropdown (autocomplete client ONRC)
   ============================================================ */
.search-dropdown {
    position: absolute;
    z-index: 50;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    max-height: 260px;
    overflow-y: auto;
    width: 100%;
    margin-top: 2px;
}
.search-dropdown .sd-item { padding: 9px 14px; cursor: pointer; font-size: 0.85rem; border-bottom: 1px solid #eef2f2; }
.search-dropdown .sd-item:hover { background: #eaf6f7; }
.search-dropdown .sd-item .sd-cui { color: var(--text-muted); font-size: 0.75rem; }

/* Butonul ☰ apare doar pe mobil (regula suprascrisa in media query) */
.nav-toggle { display: none; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .sidebar { width: 100%; padding: 8px 0; }
    .layout { flex-direction: column; }
    .content { padding: 16px; max-width: 100%; }
    .stats-grid { flex-direction: column; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form .form-control { width: 100%; }
    .firm-chip-name { max-width: 120px; }
    .form-row { flex-direction: column; }

    /* ── Meniu colapsabil pe mobil ──────────────────────────────────────
       Fara asta, sidebar-ul ocupa tot primul ecran si utilizatorul trebuie
       sa deruleze mult ca sa ajunga la continut. Se deschide cu butonul ☰. */
    .sidebar {
        display: none;
        max-height: 70vh;
        overflow-y: auto;
        border-bottom: 2px solid rgba(255,255,255,.12);
        /* Pe mobil meniul e colapsabil si sta in fluxul paginii — `sticky`
           de pe desktop l-ar tine agatat peste continut. */
        position: static;
        height: auto;
    }
    .sidebar.open { display: block; }

    .nav-toggle {
        display: flex; align-items: center; justify-content: center;
        background: none; border: 1px solid rgba(255,255,255,.35);
        color: #fff; font-size: 1.25rem; line-height: 1;
        width: 44px; height: 44px; border-radius: 10px;
        cursor: pointer; flex: none; margin-right: .6rem;
    }

    .topbar {
        position: sticky; top: 0; z-index: 50;
        height: 52px;
        padding: 0 10px;
        padding-top: env(safe-area-inset-top);
        gap: .4rem;
        flex-wrap: nowrap;
    }
    /* Brandul nu are voie sa se rupa pe doua randuri */
    .topbar-brand { font-size: .95rem; white-space: nowrap; flex: none; }
    .topbar-user { gap: .35rem; min-width: 0; overflow: hidden; flex-wrap: nowrap; }
    /* Pe ecran mic, numele firmei si al userului mananca toata bara.
       CUI-ul si rolul raman — sunt informatia utila. */
    .topbar-user > strong { display: none; }
    .firm-chip { padding: 2px 6px; font-size: .7rem; min-width: 0; }
    .firm-chip-name { max-width: 84px; overflow: hidden;
                      text-overflow: ellipsis; white-space: nowrap; }
    .role-badge { font-size: .62rem; padding: 2px 6px; }
    .btn-logout { font-size: .72rem; padding: .35rem .6rem; white-space: nowrap; }

    /* Tinte de atingere de minim 44px — degetul, nu mouse-ul */
    .side-link, .side-sub, .side-section-header {
        min-height: 46px;
        display: flex; align-items: center;
    }
    .btn, .btn-sm, button, .vm-btn { min-height: 44px; }
    .btn-logout { min-height: 40px; padding: .5rem .8rem; }

    /* 16px pe inputuri = iOS nu mai face zoom automat la focus */
    input, select, textarea, .form-control { font-size: 16px; }

    /* Tabelele late (facturi) devin derulabile lateral, nu sparg pagina */
    .table-wrap, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 640px; }

    /* ── Tabele-carduri (Parteneri, Articole) ─────────────────────────────
       Un tabel de 7 coloane e ilizibil pe 390px chiar si cu scroll lateral.
       Fiecare rand devine un card, iar celulele isi arata eticheta din
       atributul data-label. Se aplica DOAR tabelelor marcate .table-cards. */
    table.table-cards {
        min-width: 0; width: 100%; border: 0; display: block;
    }
    table.table-cards thead { display: none; }
    table.table-cards tbody,
    table.table-cards tr,
    table.table-cards td { display: block; width: 100%; }

    table.table-cards tr {
        background: #fff; border: 1px solid var(--border);
        border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
        box-shadow: 0 1px 4px rgba(0,0,0,.05);
    }
    table.table-cards td {
        border: 0; padding: 5px 0;
        display: flex; align-items: center; justify-content: space-between;
        gap: 12px; text-align: right; font-size: .88rem;
    }
    table.table-cards td::before {
        content: attr(data-label);
        font-size: .72rem; text-transform: uppercase; letter-spacing: .4px;
        color: var(--text-muted); font-weight: 700;
        text-align: left; flex: none;
    }
    /* Denumirea e titlul cardului: pe un rand singur, fara eticheta */
    table.table-cards td[data-label="Denumire"] {
        display: block; text-align: left; font-size: 1rem;
        padding: 2px 0 8px; margin-bottom: 4px;
        border-bottom: 1px solid var(--border);
    }
    table.table-cards td[data-label="Denumire"]::before { display: none; }
    /* Randul de actiuni: butoane mari, pe toata latimea */
    table.table-cards td:last-child {
        display: flex; gap: 8px; justify-content: flex-start;
        padding-top: 10px; margin-top: 4px;
        border-top: 1px solid var(--border);
    }
    table.table-cards td:last-child::before { display: none; }
    table.table-cards td:last-child button,
    table.table-cards td:last-child .btn,
    table.table-cards td:last-child a { flex: 1; min-height: 42px; }
    /* Randul "se incarca"/"niciun rezultat" ramane centrat, fara eticheta */
    table.table-cards td[colspan] { display: block; text-align: center; }
    table.table-cards td[colspan]::before { display: none; }
}



/* ── Sortare pe coloane (static/js/sortare.js) ─────────────────────── */
th.sort-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.sort-th::after { content: '⇅'; margin-left: 6px; opacity: .45; font-size: .9em; }
th.sort-th[aria-sort="ascending"]::after { content: '▲'; opacity: 1; }
th.sort-th[aria-sort="descending"]::after { content: '▼'; opacity: 1; }
th.sort-th:hover::after { opacity: .9; }
th.sort-th:focus-visible { outline: 2px solid var(--accent, #FFD54F); outline-offset: -2px; }
.sort-bara { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; font-size: .88rem; }
.sort-bara label { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; color: var(--text-muted); }
.sort-bara select { flex: 1; min-width: 0; min-height: 38px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.sort-bara .btn { min-height: 38px; white-space: nowrap; }
