/* --- Global & Typography --- */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Fade animation for sections */
.fade {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Sidebar & Navigation --- */
.sidebar-format {
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.08);
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
    overflow-y: auto;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-right: 1px solid rgba(148, 163, 184, 0.16);
}

.sidebar-header {
    flex-shrink: 0;
    padding-bottom: 1rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 1rem;
}

.sidebar-nav button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.9rem 1rem;
    border-radius: 1.1rem;
    background: transparent;
    border: 1px solid transparent;
    color: #475569;
    font-weight: 500;
    text-align: left;
    position: relative;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.sidebar-nav button i {
    color: inherit;
    transition: color 0.2s ease;
}

.sidebar-nav button:hover {
    background: rgba(99, 102, 241, 0.08);
    color: #3730a3;
    transform: translateX(2px);
    box-shadow: 0 14px 30px rgba(99, 102, 241, 0.08);
}

.sidebar-nav button.tab-active {
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
    color: #3730a3;
    font-weight: 700;
    border-color: rgba(99, 102, 241, 0.2);
    box-shadow: 0 18px 36px rgba(99, 102, 241, 0.12);
}

.sidebar-nav button.tab-active::before {
    content: '';
    position: absolute;
    left: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    border-radius: 9999px;
    background: #6366f1;
}

.sidebar-footer {
    flex-shrink: 0;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

/* Custom scrollbar for sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 0.5);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #94a3b8 0%, #64748b 100%);
}

/* Custom scrollbar for main content */
main::-webkit-scrollbar {
    width: 8px;
}

main::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 0.3);
    border-radius: 4px;
}

main::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    border-radius: 4px;
}

main::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
}

/* Remove overflow-y-auto from main on desktop for single scrolling */
@media (min-width: 769px) {
    main {
        overflow-y: visible !important;
    }
}

/* --- Form Elements --- */
.form-input, .form-select, .form-file-input {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #374151;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(209, 213, 219, 0.5);
    border-radius: 0.75rem;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* New styles for the Role Name field */
#role-name {
    width: 100%; /* Full width */
}

/* New styles for the permissions container */
#permissions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); /* Responsive grid */
    gap: 1rem; /* Space between checkboxes */
}

.form-input:focus, .form-select:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1), 0 4px 12px rgba(79, 70, 229, 0.15);
    background-color: rgba(255, 255, 255, 0.95);
}

.form-checkbox {
    border-radius: 0.25rem;
    border: 1px solid #d1d5db;
    cursor: pointer;
}

/* App Content Visibility */
.app-content.hidden {
  display: none !important;
}

.app-content {
  display: flex;
  min-height: 100vh;
}

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(17, 24, 39, 0.75); /* gray-900 with 75% opacity */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease-in-out;
    opacity: 1;
}


.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 48rem;
    width: 90%;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    transform: scale(1);
    transition: transform 0.3s ease-in-out;
}

.modal-content-lg {
    background-color: #fff;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 64rem;
    width: 95%;
    transform: scale(1);
    transition: transform 0.3s ease-in-out;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-overlay.hidden .modal-content, .modal-overlay.hidden .modal-content-lg {
    transform: scale(0.95);
}

body.modal-open {
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Scrollable products/materials sections in Sales & Purchase modals */
.modal-content form .border.border-gray-200.rounded-lg.p-4.bg-gray-50 {
    max-height: 50vh;
    overflow-y: auto;
    margin-bottom: 1rem;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

/* Custom scrollbar for modal scrollable sections */
.modal-content form .border::-webkit-scrollbar {
    width: 6px;
}

.modal-content form .border::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.modal-content form .border::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.modal-content form .border::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Ensure modal content doesn't exceed viewport */
.modal-content {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Table Styles --- */
.table-cell-actions {
    min-width: 120px;
}

/* --- P&L Month Selector Dropdown Styles --- */
#pnl-month-selector {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #374151;
    background-color: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    cursor: pointer;
    /* Use native select appearance - no custom background images */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    /* Add down arrow indicator using CSS */
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 0.75rem center no-repeat;
    background-size: 16px;
}

#pnl-month-selector:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
    border-color: #4f46e5;
    box-shadow: 0 0 0 1px #4f46e5;
}

#pnl-month-selector:hover {
    border-color: #9ca3af;
}

/* Ensure options are visible - browser native dropdown */
#pnl-month-selector option {
    padding: 0.5rem;
    background-color: #fff;
    color: #374151;
}

/* --- Sales Trend Custom Date Range: hide native date text inputs, show only calendar icon --- */
#sales-custom-range .sales-range-input {
    /* Visually hidden but keep it selectable.
       Some browsers refuse to open native pickers when pointer-events: none.
       We still hide it using opacity/size, but allow events via the click handler.
    */
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: auto;
    top: 0;
    left: 0;
}



/* Keep the calendar icon button visible */
#sales-custom-range .calendar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Ensure clicking the icon still works even though inputs are visually hidden */
#sales-custom-range {
    position: relative;
    z-index: 1;
}

/* --- Sales Additional Materials dropdown positioning (fix “far below”) --- */
/* The additional material autocomplete results are absolutely positioned.
   Ensure they overlay correctly above modal content and align relative to the
   input wrapper (which is .relative in JS-generated markup). */
#additional-materials-container [id^="additional-material-search-results-"] {
    z-index: 9999;
}

/* If any parent has overflow hidden (modal scroll areas), keep dropdown usable. */
#additional-materials-container {
    overflow: visible;
}

/* Ensure results themselves render above everything */
#sale-modal [id^="additional-material-search-results-"] {
    position: absolute;
    z-index: 99999;
}




/* Overrides for inventory buttons when Tailwind output lacks these utilities */
.inventory-add-btn {
    background: linear-gradient(90deg, #7c3aed 0%, #6d28d9 100%);
    color: #ffffff;
    box-shadow: 0 12px 30px rgba(124, 58, 237, 0.15);
    transition: background 0.18s ease, transform 0.18s ease;
}
.inventory-add-btn:hover {
    background: linear-gradient(90deg, #6d28d9 0%, #5b21b6 100%);
    transform: translateY(-1px);
}

.save-materials-btn {
    background-color: #6b21a8; /* purple-600 */
    color: #ffffff;
    transition: background-color 0.18s ease, transform 0.18s ease;
}
.save-materials-btn:hover {
    background-color: #581c87; /* purple-700 */
    transform: translateY(-1px);
}





