/* Custom CSS for Gracie Barra Management System */

/* Ensure consistent page widths - responsive */
main {
    width: 100%;
    max-width: 100%;
}

@media (min-width: 1024px) {
    main {
        width: calc(100% - 16rem); /* 16rem = 256px sidebar */
        max-width: calc(100% - 16rem);
    }
}

/* Mobile-friendly touch targets */
@media (max-width: 1023px) {
    button:not(.no-touch-target),
    a.button,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Hide scrollbar for tab navigation */
.scrollbar-hide {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;  /* Chrome, Safari and Opera */
}

/* Modal styles */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Modal content responsiveness */
/* Make grids responsive inside modals - only apply if not already responsive */
/* Use display: grid to ensure proper grid behavior */
[id*="-modal"] .grid.grid-cols-2:not([class*="sm:grid-cols"]),
[id*="-modal"] .grid.grid-cols-3:not([class*="sm:grid-cols"]) {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

@media (min-width: 640px) {
    [id*="-modal"] .grid.grid-cols-2:not([class*="sm:grid-cols"]) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    
    [id*="-modal"] .grid.grid-cols-3:not([class*="sm:grid-cols"]) {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Make flex justify-between stack on mobile in modals */
[id*="-modal"] .flex.justify-between:not([class*="sm:flex"]) {
    flex-direction: column;
    gap: 0.75rem;
}

@media (min-width: 640px) {
    [id*="-modal"] .flex.justify-between:not([class*="sm:flex"]) {
        flex-direction: row;
        align-items: center;
    }
}

/* Form buttons in modals - stack on mobile */
[id*="-modal"] form .flex.justify-end:not([class*="sm:flex"]),
[id*="-modal"] .flex.justify-end:not([class*="sm:flex"]) {
    flex-direction: column;
    width: 100%;
}

[id*="-modal"] form .flex.justify-end:not([class*="sm:flex"]) button,
[id*="-modal"] form .flex.justify-end:not([class*="sm:flex"]) a,
[id*="-modal"] .flex.justify-end:not([class*="sm:flex"]) button,
[id*="-modal"] .flex.justify-end:not([class*="sm:flex"]) a {
    width: 100%;
}

@media (min-width: 640px) {
    [id*="-modal"] form .flex.justify-end:not([class*="sm:flex"]),
    [id*="-modal"] .flex.justify-end:not([class*="sm:flex"]) {
        flex-direction: row;
        width: auto;
    }
    
    [id*="-modal"] form .flex.justify-end:not([class*="sm:flex"]) button,
    [id*="-modal"] form .flex.justify-end:not([class*="sm:flex"]) a,
    [id*="-modal"] .flex.justify-end:not([class*="sm:flex"]) button,
    [id*="-modal"] .flex.justify-end:not([class*="sm:flex"]) a {
        width: auto;
    }
}

/* Action buttons with gap - wrap on mobile */
[id*="-modal"] .flex.gap-2 {
    flex-wrap: wrap;
}

[id*="-modal"] .flex.gap-2 button:not([class*="sm:w-auto"]),
[id*="-modal"] .flex.gap-2 a:not([class*="sm:w-auto"]) {
    flex: 1 1 auto;
    min-width: fit-content;
}

@media (min-width: 640px) {
    [id*="-modal"] .flex.gap-2 button:not([class*="sm:w-auto"]),
    [id*="-modal"] .flex.gap-2 a:not([class*="sm:w-auto"]) {
        flex: 0 1 auto;
    }
}

/* Ensure grid items in modals are properly contained and don't get squashed */
[id*="-modal"] .grid > * {
    min-width: 0;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

/* Force single column on mobile for grids in modals */
/* Only apply to grids that have responsive classes (sm:grid-cols-X) to ensure mobile stacking */
@media (max-width: 639px) {
    /* Target grids with responsive classes - force single column on mobile */
    [id*="-modal"] .grid[class*="sm:grid-cols"],
    #payment-modal #payment-form {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
    
    /* Reset col-span values on mobile to prevent layout issues */
    [id*="-modal"] .grid[class*="grid-cols"] > [class*="col-span"],
    #payment-modal #payment-form > [class*="col-span"] {
        grid-column: span 1 / span 1 !important;
    }
    
    /* Ensure all direct children of the payment form stack vertically on mobile */
    #payment-modal #payment-form > * {
        width: 100%;
        max-width: 100%;
    }
}

/* Ensure responsive 3-column grids have equal widths on desktop */
@media (min-width: 640px) {
    [id*="-modal"] .grid[class*="sm:grid-cols-3"] {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    
    [id*="-modal"] .grid[class*="sm:grid-cols-3"] > * {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Ensure form inputs and selects are responsive in modals */
[id*="-modal"] input[type="text"],
[id*="-modal"] input[type="number"],
[id*="-modal"] input[type="email"],
[id*="-modal"] input[type="tel"],
[id*="-modal"] input[type="date"],
[id*="-modal"] select,
[id*="-modal"] textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Table improvements */
table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

/* Table wrapper for better styling */
.table-wrapper {
    overflow-x: auto;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    background-color: white;
}

/* Enhanced header */
thead th {
    background-color: #f3f4f6;
    font-weight: 600;
    letter-spacing: 0.025em;
    border-bottom: 2px solid #e5e7eb;
    position: relative;
}

/* Responsive cell padding */
td, th {
    padding: 0.75rem 0.75rem;
}

@media (min-width: 640px) {
    td, th {
        padding: 1rem 1.5rem;
    }
}

/* Row styling */
tbody tr {
    border-bottom: 1px solid #f3f4f6;
    transition: background-color 0.15s ease-in-out;
}

tbody tr:hover {
    background-color: #f9fafb;
}

/* Subtle alternating rows for better readability */
tbody tr:nth-child(even) {
    background-color: #fafafa;
}

tbody tr:nth-child(even):hover {
    background-color: #f3f4f6;
}

/* Last row border removal */
tbody tr:last-child {
    border-bottom: none;
}

/* Mobile optimizations */
@media (max-width: 639px) {
    table {
        font-size: 0.75rem;
    }
    
    td, th {
        padding: 0.5rem 0.5rem;
    }
    
    /* Ensure tables scroll horizontally on mobile */
    .table-wrapper {
        -webkit-overflow-scrolling: touch;
    }
}

/* DataTables wrapper improvements */
.dataTables_wrapper {
    padding: 1rem 1rem;
}

@media (min-width: 640px) {
    .dataTables_wrapper {
        padding: 1rem 1.5rem;
    }
}

/* DataTables length selector (Show X entries) */
.dataTables_wrapper .dataTables_length {
    margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_length label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.dataTables_wrapper .dataTables_length select {
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: white;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.25em 1.25em;
    transition: all 0.15s ease-in-out;
    min-height: 38px;
}

.dataTables_wrapper .dataTables_length select:hover {
    border-color: #9ca3af;
}

.dataTables_wrapper .dataTables_length select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* DataTables search/filter input */
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 1rem;
    text-align: right;
}

.dataTables_wrapper .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.dataTables_wrapper .dataTables_filter input {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: white;
    font-size: 0.875rem;
    color: #374151;
    transition: all 0.15s ease-in-out;
    min-height: 38px;
    width: 200px;
    max-width: 100%;
}

.dataTables_wrapper .dataTables_filter input::placeholder {
    color: #9ca3af;
}

.dataTables_wrapper .dataTables_filter input:hover {
    border-color: #9ca3af;
}

.dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* DataTables pagination */
.dataTables_wrapper .dataTables_paginate {
    margin-top: 1rem;
    text-align: right;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.5rem 0.75rem;
    margin-left: 0.25rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: white;
    color: #374151;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    text-decoration: none;
    display: inline-block;
    min-height: 38px;
    min-width: 38px;
    line-height: 1.5;
    text-align: center;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
    color: #111827;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background-color: #2563eb;
    border-color: #2563eb;
    color: white;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.previous,
.dataTables_wrapper .dataTables_paginate .paginate_button.next {
    font-weight: 600;
}

/* DataTables info text */
.dataTables_wrapper .dataTables_info {
    padding-top: 0.75rem;
    font-size: 0.875rem;
    color: #6b7280;
}

/* DataTables responsive improvements */
@media screen and (max-width: 767px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        margin-bottom: 0.75rem;
    }
    
    .dataTables_wrapper .dataTables_length label,
    .dataTables_wrapper .dataTables_filter label {
        font-size: 0.75rem;
    }
    
    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input {
        font-size: 0.75rem;
        padding: 0.375rem 0.625rem;
        min-height: 36px;
    }
    
    .dataTables_wrapper .dataTables_filter {
        text-align: left;
    }
    
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
    }
    
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        margin-top: 0.75rem;
        font-size: 0.75rem;
        text-align: left;
    }
    
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        min-height: 36px;
        min-width: 36px;
        margin-left: 0.125rem;
    }
    
    /* Better styling for DataTables responsive collapsed rows */
    table.dataTable.dtr-inline.collapsed > tbody > tr > td.child,
    table.dataTable.dtr-inline.collapsed > tbody > tr > th.child,
    table.dataTable.dtr-inline.collapsed > tbody > tr > td.dataTables_empty {
        padding: 0.75rem;
    }
    
    table.dataTable.dtr-inline.collapsed > tbody > tr > td.child ul.dtr-details {
        padding-left: 1rem;
    }
}

/* Mobile-specific DataTables improvements */
@media screen and (max-width: 639px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .dataTables_wrapper .dataTables_length label,
    .dataTables_wrapper .dataTables_filter label {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        width: 100%;
    }
    
    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
    }
    
    .dataTables_wrapper .dataTables_paginate {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
        justify-content: center;
    }
    
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        margin-left: 0;
        flex: 0 0 auto;
    }
}

/* Enhanced badge styling within tables */
table td .badge,
table td span[class*="rounded-full"] {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Action buttons in tables */
table td button,
table td a {
    margin-right: 0.5rem;
    white-space: nowrap;
}

table td button:last-child,
table td a:last-child {
    margin-right: 0;
}

/* Better spacing for action columns */
table td:last-child {
    white-space: nowrap;
}

@media (max-width: 639px) {
    table td button,
    table td a {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* Form input focus */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    ring: 2px;
    ring-color: #3b82f6;
}

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background-color: #dbeafe;
    color: #1e40af;
}

/* intl-tel-input styling to match Tailwind */
.iti {
    width: 100%;
}

.iti__flag-container {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
}

.iti__selected-flag {
    padding: 0 8px 0 12px;
    border-right: 1px solid #d1d5db;
}

.iti__selected-flag:hover {
    background-color: #f9fafb;
}

.iti input[type=tel] {
    padding-left: 52px !important;
}

.iti__country-list {
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
}

.iti__country {
    padding: 8px 12px;
}

.iti__country:hover {
    background-color: #f3f4f6;
}

/* Select2 styling for inventory module */
.select2-container {
    width: 100% !important;
}

.select2-container--default .select2-selection--single {
    height: 38px;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 38px;
    padding-left: 12px;
    padding-right: 20px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
    right: 8px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #6b7280 transparent transparent transparent;
    border-width: 5px 4px 0 4px;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent #6b7280 transparent;
    border-width: 0 4px 5px 4px;
}

/* Select2 dropdown styling */
.select2-dropdown {
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 10000 !important; /* Ensure dropdown appears above modals */
}

.select2-results__option {
    padding: 8px 12px;
}

.select2-results__option--highlighted {
    background-color: #3b82f6;
    color: white;
}

.select2-results__option[aria-selected="true"] {
    background-color: #eff6ff;
    color: #1e40af;
}

/* Select2 in table cells */
table td .select2-container {
    min-width: 120px;
}

table td .select2-container--default .select2-selection--single {
    height: 32px;
}

table td .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 32px;
    font-size: 0.875rem;
}

/* Select2 in modals - ensure proper z-index */
.modal .select2-dropdown {
    z-index: 10001 !important;
}

.modal .select2-container--open {
    z-index: 10001 !important;
}

/* Select2 search box styling */
.select2-search--dropdown .select2-search__field {
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    padding: 6px 12px;
    margin: 4px;
    width: calc(100% - 8px);
}

.select2-search--dropdown .select2-search__field:focus {
    outline: none;
    border-color: #3b82f6;
    ring: 2px;
    ring-color: #3b82f6;
}
