/* Improved Header Button Styles */
.navbar .btn,
.navbar + .content-wrapper .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    margin-right: 0.5rem;
    transition: all 0.2s ease;
    text-transform: none;
    font-weight: 500;
    height: auto;
    white-space: nowrap;
    box-shadow: none;
}

/* Primary action buttons */
.navbar .btn-primary,
.navbar + .content-wrapper .btn-primary {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.navbar .btn-primary:hover,
.navbar + .content-wrapper .btn-primary:hover {
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

/* Secondary action buttons */
.navbar .btn-secondary,
.navbar + .content-wrapper .btn-secondary,
.navbar .btn-outline-primary,
.navbar + .content-wrapper .btn-outline-primary {
    background-color: transparent;
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.navbar .btn-secondary:hover,
.navbar + .content-wrapper .btn-secondary:hover,
.navbar .btn-outline-primary:hover,
.navbar + .content-wrapper .btn-outline-primary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Buttons container in header */
.header-actions,
.navbar + .content-wrapper .header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

/* Responsive adjustments */
@media (max-width: 991px) {
    .header-actions,
    .navbar + .content-wrapper .header-actions {
        flex-wrap: wrap;
    }

    .navbar .btn,
    .navbar + .content-wrapper .btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.8125rem;
    }
}

/* Custom style for action buttons with icons */
.navbar .btn i,
.navbar + .content-wrapper .btn i {
    margin-right: 0.25rem;
}

/* Fix for specific page action buttons (seen in screenshots) */
.navbar + .content-wrapper h1 + .d-flex .btn,
.navbar + .content-wrapper h1 + .btn-group .btn,
.navbar + .content-wrapper h1 + div .btn {
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* More specific targeting for buttons in the DTG Spares page */
.header-actions .btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    height: 36px !important;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-600);
    border-color: var(--primary-700);
    box-shadow: none;
    white-space: nowrap;
}

/* Specific styling for the Request Quotes button */
.header-actions .btn-success {
    background-color: #198754;
    border-color: #157347;
}

.header-actions .btn-success:hover {
    background-color: #157347;
    border-color: #146c43;
}

/* Fix for import/add buttons */
.header-actions .btn-primary {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.header-actions .btn-primary:hover {
    background-color: #0b5ed7;
    border-color: #0b5ed7;
}

/* Ensure spacing between buttons */
.header-actions .gap-2 {
    gap: 0.5rem !important;
}

/* More compact presentation on mobile */
@media (max-width: 991px) {
    .header-actions {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }

    .header-actions .gap-2 {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .header-actions .btn {
        margin-bottom: 0.5rem;
        font-size: 0.8125rem;
        padding: 0.3rem 0.6rem;
        height: 34px !important;
        width: auto !important;
        flex: 0 0 auto;
    }

    h1 + .header-actions {
        margin-top: 0.5rem;
    }
}

/* Improve RTL compatibility */
.header-actions .btn i {
    margin-inline-end: 0.3rem;
    margin-inline-start: 0;
}

/* Minimal change to put buttons below heading */
h1 + .header-actions,
h1 + .d-flex {
    display: block;
    width: 100%;
    margin-top: 0.75rem;
}

/* Keep the existing button styling */
.btn {
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}

/* User Avatar Icon Styling */
.avatar-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
}

.user-avatar {
    background-color: #6c757d;
}

.superuser-avatar {
    background-color: #dc3545;
}

.avatar-icon i {
    margin: 0 !important;
}

/* Responsive avatar sizing */
@media (max-width: 991px) {
    .avatar-icon {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    /* Add table borders on mobile view only */
    .table {
        border: 1px solid #dee2e6;
    }

    .table th,
    .table td {
        border: 1px solid #dee2e6;
    }

    /* Mobile card view styling - subtle borders like Bootstrap default */
    .card {
        border: 1px solid rgba(0,0,0,.125);
        box-shadow: none;
        margin-bottom: 1rem;
    }

    /* Mobile styling for detail/edit/add page header buttons */
    /* Stack header and buttons vertically on mobile */
    .d-flex.justify-content-between.align-items-center {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    /* Button container styling */
    .d-flex.justify-content-between.align-items-center > div:last-child {
        margin-top: 0.75rem;
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    /* Compact text buttons on mobile */
    .d-flex.justify-content-between.align-items-center .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        white-space: nowrap;
    }

    /* Icon spacing in buttons */
    .d-flex.justify-content-between.align-items-center .btn i {
        margin-right: 0.25rem !important;
        font-size: 0.875rem;
    }

    /* Prevent horizontal scrolling on detail/edit/add pages */
    /* Force all content to respect viewport width */
    body {
        overflow-x: hidden;
    }

    /* Compact definition list layout - keep label/value side-by-side */
    dl.row {
        margin-bottom: 0.5rem;
        display: flex;
        flex-wrap: wrap;
    }

    dl.row dt {
        font-weight: bold;
        font-size: 0.875rem;
        color: #6c757d;
        margin-bottom: 0.5rem;
        width: 40%;
        padding-right: 0.5rem;
    }

    dl.row dd {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        padding-left: 0;
        width: 60%;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Stack form rows and columns on mobile (but not definition lists) */
    .row:not(dl) > [class*='col-'] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Compact card styling */
    .card {
        max-width: 100%;
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-title {
        font-size: 1rem;
        margin-bottom: 0;
    }

    /* Allow long text to wrap */
    td, th, p, span, div {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Tables should not scroll - fit content to viewport */
    .table-responsive {
        overflow-x: visible;
        max-width: 100%;
        width: 100%;
    }

    /* Compact table styling for all detail/edit/add pages */
    .table {
        font-size: 0.8125rem;
        margin-bottom: 0;
    }

    .table th,
    .table td {
        padding: 0.5rem 0.375rem;
        vertical-align: middle;
    }

    .table thead th {
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        white-space: nowrap;
    }

    /* Compact badges in tables */
    .table .badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
        white-space: nowrap;
    }

    /* Compact buttons in tables */
    .table .btn,
    .table .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    /* Remove sticky columns - causes artifacting on mobile */
    /* Tables should fit within viewport without scrolling */

    /* Compact small text in tables */
    .table small {
        font-size: 0.7rem;
    }

    /* Allow critical text columns to wrap */
    .table td {
        max-width: 150px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Keep certain columns from wrapping */
    .table td .badge,
    .table td .btn {
        white-space: nowrap;
    }

    /* Hide less important columns on mobile */
    /* Hide Size column (3rd) for variants table - least critical */
    .table th:nth-child(3),
    .table td:nth-child(3) {
        display: none;
    }

    /* Responsive column widths - compact but readable */
    .table {
        table-layout: auto;
        width: 100%;
        font-size: 0.75rem;
    }

    /* First column (LPN) - very compact */
    .table thead tr th:nth-child(1),
    .table tbody tr td:nth-child(1) {
        width: 15%;
        font-size: 0.7rem;
        padding: 0.25rem 0.2rem;
    }

    /* Second column (SKU/Location) - main identifier */
    .table thead tr th:nth-child(2),
    .table tbody tr td:nth-child(2) {
        width: 35%;
        white-space: normal;
        word-wrap: break-word;
    }

    /* Fourth column (Colour/Avail after hiding Size) - compact */
    .table thead tr th:nth-child(4),
    .table tbody tr td:nth-child(4) {
        width: 25%;
        white-space: normal;
        word-wrap: break-word;
    }

    /* Fifth column (Avail) - compact, centered */
    .table thead tr th:nth-child(5),
    .table tbody tr td:nth-child(5) {
        width: 12%;
        text-align: center;
        font-size: 0.75rem;
    }

    /* Actions column (last) - icon only, minimal width */
    .table thead tr th:last-child,
    .table tbody tr td:last-child {
        width: 13%;
        text-align: center;
        padding: 0.25rem 0.15rem;
    }

    /* Icon-only action buttons in tables */
    .table .btn {
        padding: 0.375rem 0.5rem;
        font-size: 0;
    }

    .table .btn i {
        font-size: 0.875rem;
        margin: 0;
    }

    /* Make input groups stack vertically */
    .input-group {
        flex-wrap: wrap;
    }

    .input-group > * {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* Compact form elements for edit/add pages */
    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.375rem;
        font-weight: 500;
    }

    .form-control,
    .form-select,
    .form-control:focus,
    .form-select:focus {
        font-size: 0.9375rem;
        padding: 0.5rem 0.75rem;
        border-radius: 0.25rem;
    }

    /* Compact textareas */
    textarea.form-control {
        min-height: 80px;
    }

    /* Compact form groups */
    .form-group,
    .mb-3 {
        margin-bottom: 0.75rem !important;
    }

    /* Compact form text/help text */
    .form-text,
    .text-muted,
    small {
        font-size: 0.75rem;
    }

    /* Compact checkboxes and radios */
    .form-check {
        padding-left: 1.5rem;
        margin-bottom: 0.5rem;
    }

    .form-check-input {
        margin-top: 0.25rem;
    }

    .form-check-label {
        font-size: 0.875rem;
    }

    /* Compact invalid feedback */
    .invalid-feedback,
    .valid-feedback {
        font-size: 0.75rem;
        margin-top: 0.25rem;
    }

    /* Form submit buttons */
    form .btn[type="submit"],
    form button[type="submit"] {
        width: 100%;
        margin-top: 0.5rem;
        padding: 0.625rem;
        font-size: 1rem;
    }

    /* Form action button groups */
    form .btn-group,
    form .d-flex.gap-2 {
        width: 100%;
        flex-direction: column;
    }

    form .btn-group .btn,
    form .d-flex.gap-2 .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .mb-4 {
        margin-bottom: 1rem !important;
    }

    /* Compact headings */
    h1 {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }

    h4 {
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
        margin-top: 0.5rem;
    }

    h5 {
        font-size: 1rem;
    }

    /* Compact alerts */
    .alert {
        padding: 0.75rem;
        font-size: 0.875rem;
    }

    /* Compact badges */
    .badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    /* Reduce row gutters */
    .row {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
    }
}