* {
    font-family: 'Inter', sans-serif;
}

body {
    background-color: #f1f3f5;
    font-size: clamp(11px, 0.8vw, 13px) !important;
}

.container-fluid {
    padding: clamp(15px, 3vw, 40px);
}

h2.text-primary {
    font-size: clamp(20px, 2.5vw, 28px);
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 15px !important;
}

.card {
    border: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    border-radius: 0;
    padding: 15px !important;
}

.form-label {
    font-size: 11.5px !important;
    font-weight: 600;
    margin-bottom: 3px;
    color: #343a40;
}

.form-control,
.form-select {
    font-size: 12.5px !important;
    padding: 6px 10px !important;
    border-radius: 0 !important;
    border: 2px solid #e9ecef !important;
    background-color: #f8f9fa;
}

.form-control:focus,
.form-select:focus {
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.1) !important;
}

.nav-tabs {
    border-bottom: 2px solid #e9ecef !important;
    margin-bottom: 20px !important;
    gap: 5px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.nav-link {
    font-size: 11.5px !important;
    font-weight: 700 !important;
    padding: 8px 15px !important;
    border-radius: 0 !important;
    margin: 0 !important;
    border: none !important;
    color: #fff !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    transition: all 0.2s ease;
    background: #222 !important;
}

.nav-link:hover {
    color: #fff !important;
    background: #ab2b2d !important;
}

.nav-link.active {
    color: #fff !important;
    background: #ab2b2d !important;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: #fff;
}

/* Eliminate arrows from numeric fields */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: none;
}

/* Custom Discount Type Dropdown */
.disc-type-select {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: none !important;
    background-color: #212529 !important;
    color: #fff !important;
    text-align: center;
    text-align-last: center;
    /* helps centering in selects on some browsers */
    border: 2px solid #212529 !important;
    cursor: pointer;
    font-weight: 700;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.disc-type-select:hover,
.disc-type-select:focus {
    background-color: #000 !important;
    border-color: #000 !important;
    color: #fff !important;
    box-shadow: none !important;
    outline: none !important;
}

.disc-type-select option {
    background-color: #fff;
    color: #000;
    font-weight: bold;
    text-align: center;
}


.product-input-row {
    padding: 4px 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
}

/* Scrollable Sides */
.form-side-container {
    height: calc(100vh - 60px);
    overflow-y: auto;
    padding-right: 15px;
    padding-bottom: 150px;
}

/* Premium Scrollbar */
.form-side-container::-webkit-scrollbar,
.preview-container::-webkit-scrollbar {
    width: 8px;
}

.form-side-container::-webkit-scrollbar-track,
.preview-container::-webkit-scrollbar-track {
    background: transparent;
}

.form-side-container::-webkit-scrollbar-thumb,
.preview-container::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

.form-side-container::-webkit-scrollbar-thumb:hover,
.preview-container::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Preview Zone Styles */
.preview-container {
    width: 100%;
    height: calc(100vh - 60px);
    overflow: auto !important;
    background: #cbd5e0;
    padding: 20px;
    text-align: center;
    border-radius: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.zoom-wrapper {
    display: inline-block;
    text-align: left;
    transform-origin: top center;
    transition: transform 0.1s ease-out;
}

#livePreview,
.docx-wrapper,
.docx-preview-wrapper {
    display: block;
    margin: 0 auto;
}

/* docx-preview refinement - RESET TO MINIMUM for fidelity */
.docx-wrapper,
.docx-preview-wrapper {
    background: transparent !important;
    padding: 0 !important;
}

.docx-wrapper>section,
.docx-wrapper>section.docx-preview {
    background: white !important;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2) !important;
    margin-bottom: 30px !important;
    position: relative;
}

/* Simulator vizual pentru marginea de jos a paginii A4 */
.docx-wrapper>section::after,
.docx-wrapper>section.docx-preview::after {
    content: "MARGINE DE JOS PAGINĂ A4 (Dacă textul depășește linia aceasta, va trece pe o pagină nouă în PDF/Word)";
    position: absolute;
    top: 296mm;
    /* 1mm mai sus ca să se vadă clar chenarul */
    left: 0;
    width: 100%;
    border-top: 2px dashed red;
    color: red;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    padding-top: 2px;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.7;
}

/* Custom switch size */
.form-switch .form-check-input.small-switch {
    width: 30px !important;
    height: 15px !important;
    cursor: pointer;
}

/* Adjust accordion button to push arrow to far right */
.accordion-button::after {
    margin-left: auto !important;
}

.accordion-button {
    padding-right: 10px !important;
}

.accordion-button:focus {
    box-shadow: none !important;
    border-color: #ab2b2d !important;
}

.py-1 {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.btn-evo {
    background-color: #ab2b2d !important;
    color: #fff !important;
    border: none !important;
    border-radius: 0 !important;
    transition: all 0.2s ease;
}

.btn-evo:hover {
    background-color: #222 !important;
    color: #fff !important;
}

.accordion-button:hover {
    background-color: transparent !important;
    color: inherit !important;
    cursor: default !important;
}

.accordion-button:not(.collapsed) {
    background-color: #f8f9fa !important;
    color: #000 !important;
}

.accordion-button:not(.collapsed)::after {
    filter: none !important;
}

/* === Fonturi Barlow Semi Condensed - bundlate local (nu necesita internet sau instalare) === */

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Regular-400.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Regular-500.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Regular-600.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Regular-700.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Italic-400.ttf') format('truetype');
    font-weight: 400;
    font-style: italic;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Italic-500.ttf') format('truetype');
    font-weight: 500;
    font-style: italic;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Italic-600.ttf') format('truetype');
    font-weight: 600;
    font-style: italic;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed';
    src: url('/css/fonts/BarlowSemiCondensed-Italic-700.ttf') format('truetype');
    font-weight: 700;
    font-style: italic;
    font-display: block;
}

/* Alias-uri pentru compatibilitate cu codul existent */
@font-face {
    font-family: 'Barlow Semi Condensed Medium';
    src: url('/css/fonts/BarlowSemiCondensed-Regular-500.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: block;
}

@font-face {
    font-family: 'Barlow Semi Condensed SemiBold';
    src: url('/css/fonts/BarlowSemiCondensed-Regular-600.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: block;
}

.docx-wrapper img {
    max-width: 100%;
    height: auto;
}

/* Fix: White text in black bars (Section Titles) */
.docx-wrapper td[style*="background-color: black"] *,
.docx-wrapper td[style*="background-color: rgb(0, 0, 0)"] *,
.docx-wrapper td[style*="background-color:#000000"] *,
.docx-wrapper tr[style*="background-color: black"] *,
.docx-wrapper tr[style*="background-color: rgb(0, 0, 0)"] * {
    color: white !important;
}

/* Standard Table Fidelity */
.docx-wrapper table {
    border-collapse: collapse !important;
    width: 100% !important;
}

.docx-wrapper td {
    padding: 1px 1px !important;
}

body {
    height: 100vh;
    overflow: hidden;
}

/* Global reset for buttons */
.btn {
    border-radius: 0 !important;
    text-transform: uppercase;
    font-size: 12px !important;
    font-weight: 600 !important;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
}

.btn-primary,
.btn-dark,
.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-danger {
    background-color: #111 !important;
    color: #fff !important;
    border: 1px solid #111 !important;
}

.btn-primary:hover,
.btn-dark:hover,
.btn-outline-primary:hover,
.btn-outline-secondary:hover,
.btn-outline-danger:hover {
    background-color: #ab2b2d !important;
    color: #fff !important;
    border-color: #ab2b2d !important;
}

#historyTableBody .btn-light:hover {
    background-color: #ab2b2d !important;
    color: #fff !important;
    border-color: #ab2b2d !important;
}

#historyTableBody .delete-doc:hover {
    background-color: #ab2b2d !important;
    color: #fff !important;
}

.mobile-preview-toggle,
.mobile-preview-close {
    display: none !important;
}

@media (max-width: 767.98px) {
    html,
    body {
        min-height: 100%;
        height: auto;
        overflow: auto;
    }

    body {
        font-size: 14px !important;
        padding-bottom: 78px;
    }

    .container-fluid {
        padding: 10px;
    }

    .d-flex.align-items-end.mb-4.mt-3 {
        align-items: center !important;
        margin: 8px 0 12px !important;
    }

    #appLogo {
        max-height: 38px !important;
        max-width: 72%;
    }

    #logoutBtn {
        min-height: 36px;
        padding: 8px 10px !important;
        font-size: 10px !important;
    }

    .nav-tabs {
        position: sticky;
        top: 0;
        z-index: 1200;
        background: #f1f3f5;
        padding: 6px 0;
        margin: 0 -10px 10px !important;
        padding-left: 10px;
        padding-right: 10px;
        border-bottom: 0 !important;
    }

    .nav-link {
        min-height: 42px;
        min-width: max-content;
        padding: 11px 14px !important;
        font-size: 11px !important;
    }

    .form-side-container {
        height: auto;
        overflow: visible;
        padding-right: 0;
        padding-bottom: 16px;
    }

    .card {
        padding: 12px !important;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
    }

    .accordion-button {
        min-height: 52px;
        padding: 14px 16px !important;
        font-size: 16px !important;
    }

    .accordion-body {
        padding: 12px !important;
    }

    .form-label {
        font-size: 12px !important;
        margin-bottom: 5px;
    }

    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px !important;
        padding: 10px 12px !important;
    }

    textarea.form-control {
        min-height: 92px;
    }

    .btn {
        min-height: 44px;
        font-size: 12px !important;
        white-space: normal;
    }

    .tab-pane form > .d-flex.gap-2,
    .accordion-body > .d-flex.justify-content-between {
        flex-wrap: wrap;
    }

    .tab-pane form > .d-flex.gap-2 > .btn {
        flex: 1 1 calc(50% - 8px);
        width: auto !important;
    }

    #saveProformaBtn,
    #savePvBtn {
        flex-basis: 100%;
    }

    .accordion-body > .d-flex.justify-content-between {
        align-items: stretch !important;
        gap: 10px;
    }

    .accordion-body > .d-flex.justify-content-between > span {
        width: 100%;
        font-weight: 700;
    }

    .accordion-body > .d-flex.justify-content-between > .d-flex {
        width: 100%;
    }

    .accordion-body > .d-flex.justify-content-between > .d-flex .btn {
        flex: 1 1 0;
    }

    .product-input-row {
        display: block;
        padding: 10px;
        margin-bottom: 10px;
        border: 1px solid #e9ecef;
        background: #fff;
    }

    .product-input-row > * {
        margin-bottom: 8px;
    }

    .product-input-row > *:last-child {
        margin-bottom: 0;
    }

    .product-input-row .edit-mode-view {
        padding: 10px !important;
        width: 100%;
    }

    .product-input-row .edit-mode-view .row > [class^="col"] {
        flex: 0 0 100%;
        max-width: 100%;
        width: 100%;
    }

    .product-input-row .input-group .btn {
        flex: 0 0 48px;
    }

    .product-input-row .read-only-view {
        flex-wrap: wrap;
        gap: 8px !important;
        align-items: flex-start !important;
    }

    .product-input-row .read-only-view .text-truncate {
        flex: 1 0 100%;
        order: 5;
        padding-left: 0 !important;
        border-left: 0 !important;
        white-space: normal;
    }

    .product-input-row .read-only-view .d-flex.gap-1 {
        margin-left: auto !important;
    }

    .client-autocomplete-menu {
        max-height: 235px;
        border-radius: 6px;
        padding: 5px;
    }

    .client-autocomplete-item {
        padding: 9px 10px;
        font-size: 12px;
    }

    .preview-side {
        display: none;
    }

    .preview-side.mobile-preview-open {
        display: block;
        position: fixed !important;
        inset: 0;
        z-index: 1900;
        background: #cbd5e0;
        padding: 54px 10px 10px;
    }

    .preview-modal-open {
        overflow: hidden;
    }

    .mobile-preview-toggle {
        display: block !important;
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 10px;
        z-index: 1600;
        width: calc(100% - 20px);
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
    }

    .mobile-preview-close {
        display: block !important;
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        z-index: 2000;
        width: calc(100% - 20px);
    }

    .preview-container {
        height: calc(100vh - 70px);
        padding: 10px;
    }

    #linesLeftWarning {
        top: 62px !important;
        right: 15px !important;
        font-size: 12px !important;
    }

    #history .table-responsive {
        overflow: visible;
    }

    #history table,
    #history thead,
    #history tbody,
    #history tr,
    #history td {
        display: block;
        width: 100%;
    }

    #history thead {
        display: none;
    }

    #history tr {
        display: grid;
        grid-template-columns: auto auto minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 7px;
        margin-bottom: 5px;
        padding: 7px 8px;
        background: #fff;
        border: 1px solid #e9ecef;
        box-shadow: none;
    }

    #history td {
        border: 0 !important;
        padding: 0 !important;
        min-width: 0;
    }

    #history td:nth-child(1),
    #history td:nth-child(2) {
        display: block;
        width: auto;
        margin-right: 0;
        font-weight: 800;
        color: #ab2b2d;
    }

    #history td:nth-child(3) {
        margin: 0;
        font-size: 12px;
        font-weight: 600;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #history td:nth-child(4) .btn-group,
    #history td:nth-child(4) .d-flex {
        display: flex;
        width: auto;
        gap: 3px;
        flex-wrap: nowrap;
    }

    #history td:nth-child(4) .btn {
        flex: 0 0 34px;
        width: 34px;
        min-width: 34px;
        min-height: 34px;
        padding: 4px !important;
        font-size: 13px !important;
        line-height: 1;
    }

    #history td:nth-child(4) .delete-doc {
        background: #ab2b2d !important;
        border-color: #ab2b2d !important;
        color: #fff !important;
    }

    #history .badge {
        font-size: 10px !important;
        padding: 5px 7px;
    }
}
