/* ============================================
   GLOBAL CHECKBOX UNIFICATION
   Standardizes all checkboxes to 20x20px across the app
   ============================================ */
input[type="checkbox"],
.custom-control-input[type="checkbox"],
.form-check-input[type="checkbox"],
.status-modal-checkbox,
.task-checkbox {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    cursor: pointer !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
    transform: none !important;
    -webkit-transform: none !important;
    top: 0 !important;
    left: 0 !important;
}

/* Ensure labels containing checkboxes display nicely and left-aligned */
.checkbox-label, 
.form-check-label,
.custom-control-label,
label:has(input[type="checkbox"]):not(.auto-day-chip):not(.auto-toggle) {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    cursor: pointer !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    text-align: left !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
}

/* Hide legacy decorative checkmark spans and switch tracks */
.checkmark, 
.checkbox-label .checkmark,
label:has(input[type="checkbox"]) .checkmark,
.custom-switch .custom-control-label::before,
.custom-switch .custom-control-label::after,
.custom-control-label::before,
.custom-control-label::after {
    display: none !important;
}

/* Standardized spacing for text under checkboxes */
.checkbox-label + small,
.checkbox-label + .text-muted,
label:has(input[type="checkbox"]) + small,
label:has(input[type="checkbox"]) + .text-muted {
    display: block !important;
    margin-top: 4px !important;
    margin-left: 30px !important; /* Matches 20px checkbox + 10px gap */
}

/* ============================================
   ENHANCED BADGE CONTRAST - GLOBAL
   Covers both Bootstrap 4 (.badge-*) and Bootstrap 5 (.badge.bg-*) classes
   ============================================ */
.badge {
    font-weight: 600 !important;
    font-size: 0.75em !important;
    padding: 0.375em 0.75em !important;
    border: 1px solid transparent !important;
}

/* Bootstrap 5 style badges */
.badge.bg-light {
    background-color: #e3f2fd !important;
    color: #1565c0 !important;
    font-weight: 600 !important;
    border: 1px solid #bbdefb !important;
}

.badge.bg-secondary {
    background-color: #6c757d !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge.bg-primary {
    background-color: #0d6efd !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge.bg-success {
    background-color: #198754 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge.bg-info {
    background-color: #0dcaf0 !important;
    color: #000 !important;
    font-weight: 600 !important;
}

.badge.bg-warning {
    background-color: #ffc107 !important;
    color: #000 !important;
    font-weight: 600 !important;
}

.badge.bg-danger {
    background-color: #dc3545 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

/* ============================================
   MODAL DEFAULTS (Bootstrap-style .modal.fade)
   Centralizes look/spacing so new modals match
   the app’s standard modal UX without per-modal tweaks.
   ============================================ */
.modal.fade .modal-dialog {
    max-width: 560px;
}

/* Prevent double-padding from generic .modal-content rules */
.modal.fade .modal-content {
    border-radius: 18px;
    overflow: hidden;
    padding: 0 !important;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(0,0,0,0.08);
}

.modal.fade .modal-header {
    padding: 18px 22px;
}

.modal.fade .modal-body {
    padding: 18px 22px;
}

.modal.fade .modal-footer {
    padding: 14px 22px;
    gap: 10px;
}

/* Keep primary actions consistent (blue) */
.modal.fade .modal-footer .btn {
    min-height: 44px;
    font-weight: 600;
}

/* Bootstrap 4 style badges (used in admin templates) */
.badge-primary {
    background-color: #0d6efd !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge-secondary {
    background-color: #6c757d !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge-success {
    background-color: #198754 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge-danger {
    background-color: #dc3545 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge-warning {
    background-color: #ffc107 !important;
    color: #000 !important;
    font-weight: 600 !important;
}

.badge-info {
    background-color: #17a2b8 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

.badge-light {
    background-color: #f8f9fa !important;
    color: #212529 !important;
    font-weight: 600 !important;
    border: 1px solid #dee2e6 !important;
}

.badge-dark {
    background-color: #343a40 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

/* ============================================
   ENHANCED BUTTON CONTRAST - GLOBAL
   High contrast colors for all button variants
   ============================================ */
.btn {
    font-weight: 600 !important;
    border-width: 1px !important;
}

/* Primary Button - Blue */
.btn-primary {
    background-color: #0d6efd !important;
    border-color: #0d6efd !important;
    color: #fff !important;
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background-color: #0b5ed7 !important;
    border-color: #0a58ca !important;
    color: #fff !important;
}

/* Secondary Button - Grey */
.btn-secondary {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: #fff !important;
}

.btn-secondary:hover, .btn-secondary:focus, .btn-secondary:active {
    background-color: #5c636a !important;
    border-color: #565e64 !important;
    color: #fff !important;
}

/* Success Button - Green */
.btn-success {
    background-color: #198754 !important;
    border-color: #198754 !important;
    color: #fff !important;
}

.btn-success:hover, .btn-success:focus, .btn-success:active {
    background-color: #157347 !important;
    border-color: #146c43 !important;
    color: #fff !important;
}

/* Danger Button - Red */
.btn-danger {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: #fff !important;
}

.btn-danger:hover, .btn-danger:focus, .btn-danger:active {
    background-color: #bb2d3b !important;
    border-color: #b02a37 !important;
    color: #fff !important;
}

/* Outline Primary */
.btn-outline-primary {
    color: #0d6efd !important;
    border-color: #0d6efd !important;
    background-color: transparent !important;
}

.btn-outline-primary:hover, .btn-outline-primary:focus, .btn-outline-primary:active {
    background-color: #0d6efd !important;
    border-color: #0d6efd !important;
    color: #fff !important;
}

/* Outline Success */
.btn-outline-success {
    color: #198754 !important;
    border-color: #198754 !important;
    background-color: transparent !important;
}

.btn-outline-success:hover, .btn-outline-success:focus, .btn-outline-success:active {
    background-color: #198754 !important;
    border-color: #198754 !important;
    color: #fff !important;
}

/* Outline Danger */
.btn-outline-danger {
    color: #dc3545 !important;
    border-color: #dc3545 !important;
    background-color: transparent !important;
}

.btn-outline-danger:hover, .btn-outline-danger:focus, .btn-outline-danger:active {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: #fff !important;
}

/* Ensure all custom button classes also have consistent height */
[class*="btn-"]:not(.btn-sm):not(.invoice-action-btn) {
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    line-height: 1.5 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important; /* Spacing between icon and text */
    box-sizing: border-box !important;
}

/* Override: Circular action icon buttons must stay 38x38 circles */
.icon-action-btn[class*="btn-"],
.action-btn[class*="btn-"],
.action-icon[class*="btn-"],
button.icon-action-btn,
button.action-btn,
button.action-icon {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    max-width: 38px !important;
    max-height: 38px !important;
    border-radius: 50% !important;
    padding: 0 !important;
    gap: 0 !important;
}

/* Ensure toggle buttons have consistent height */
.toggle-btn:not(.btn-sm):not(.invoice-action-btn) {
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    line-height: 1.5 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    padding: 0.7rem 1.5rem !important;
    font-size: 1.1rem !important; /* Standardize font size */
}

/* Invoices page controls (prevents late-style flicker on tab buttons) */
.invoice-controls {
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e9ecef;
}

.invoice-section-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Match dashboard-style toggle tabs */
.invoice-section-toggle .toggle-btn {
    background: #f0f0f0 !important;
    color: #666 !important;
    font-weight: 600 !important;
    border: none !important;
    border-radius: 20px !important;
    cursor: pointer;
    transition: none !important; /* Avoid visible square->rounded transition */
    box-sizing: border-box !important;
}

.invoice-section-toggle .toggle-btn.active {
    background: var(--desert-accent) !important;
    color: white !important;
}

.invoice-section-toggle .toggle-btn:focus {
    outline: none;
}

.invoice-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.75rem;
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    background: #f8f9fa;
}

.invoice-filters-label {
    font-weight: 600;
    color: #6c757d;
    margin-right: 0.25rem;
}

@media (max-width: 576px) {
    .invoice-section-btn,
    .invoice-filters .filter-btn {
        flex: 1 1 auto;
    }
}

/* Keep section transition scoped to invoices page only */
#invoices.section,
#to-send.section {
    transition: all 0.3s ease;
}

/* Ensure bubble buttons (status, team, service) have consistent height */
.status-bubble, .team-bubble, .q-service-btn {
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    line-height: 1.5 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    padding: 0.7rem 1.5rem !important;
    font-size: 1.1rem !important; /* Standardize font size */
}

.btn-warning {
    background-color: #ffc107 !important;
    border-color: #ffc107 !important;
    color: #212529 !important;
    font-weight: 600 !important;
}

.btn-warning:hover {
    background-color: #e0a800 !important;
    border-color: #d39e00 !important;
    color: #212529 !important;
}

.btn-outline-secondary {
    color: #495057 !important;
    border-color: #6c757d !important;
    background-color: #f8f9fa !important;
    font-weight: 600 !important;
}

.btn-outline-secondary:hover {
    color: #fff !important;
    background-color: #6c757d !important;
    border-color: #6c757d !important;
}

.btn-info {
    background-color: #17a2b8 !important;
    border-color: #17a2b8 !important;
    color: #fff !important;
}

.btn-info:hover {
    background-color: #138496 !important;
    border-color: #117a8b !important;
    color: #fff !important;
}

.btn-outline-info {
    color: #0c5460 !important;
    border-color: #17a2b8 !important;
    background-color: transparent !important;
}

.btn-outline-info:hover {
    color: #fff !important;
    background-color: #17a2b8 !important;
    border-color: #17a2b8 !important;
}

.btn-outline-warning {
    color: #856404 !important;
    border-color: #ffc107 !important;
    background-color: transparent !important;
}

.btn-outline-warning:hover {
    color: #212529 !important;
    background-color: #ffc107 !important;
    border-color: #ffc107 !important;
}

/* ============================================
   MODERN GLOBAL MODAL SYSTEM
   Unified, centered, beautiful modals for desktop & mobile
   ============================================ */

/* Modal Backdrop - Uniform dark overlay */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background-color: rgba(0, 0, 0, 0.65) !important; /* Uniform darker backdrop */
    backdrop-filter: blur(4px); /* Modern blur effect */
    -webkit-backdrop-filter: blur(4px);
    overflow-y: auto;
    overflow-x: hidden;
    animation: fadeIn 0.2s ease-out;
}

/* Show modal with perfect centering */
.modal.show {
    display: flex !important;
    align-items: flex-start !important; /* Start from top to allow margin to work */
    justify-content: center !important; /* Horizontal centering */
    padding: 20px !important;
    animation: fadeIn 0.2s ease-out;
}

/* Modal Content - Centered, modern design */
.modal-content {
    position: relative;
    background-color: #ffffff !important;
    border-radius: 16px !important; /* Modern rounded corners */
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 
                0 0 0 1px rgba(0, 0, 0, 0.05) !important; /* Deep shadow for elevation */
    width: 90% !important;
    max-width: 600px !important;
    max-height: calc(100vh - 200px) !important; /* Adjusted for top/bottom margins */
    margin-top: 80px !important; /* Push modal down from top */
    margin-bottom: 80px !important; /* Equal bottom margin for balance */
    margin-left: auto !important;
    margin-right: auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateZ(0); /* Hardware acceleration */
}

/* Ensure forms inside modal-content use flexbox for proper footer positioning */
.modal-content > form {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

/* Larger modals */
.modal-content.modal-lg,
.modal-lg .modal-content {
    max-width: 800px !important;
}

.modal-content.modal-xl,
.modal-xl .modal-content {
    max-width: 1200px !important;
}

/* Modal Header — match settings-page rhythm (e.g. Email History bar, column modals) */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 !important;
    padding: 20px 20px 15px 20px !important;
    border-bottom: 1px solid #e9ecef;
    background-color: #ffffff;
    flex-shrink: 0;
}

.modal-header h2,
.modal-header h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: #212529;
}

/* Close button */
.modal-header .close {
    background: none;
    border: none;
    font-size: 28px;
    font-weight: 300;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    line-height: 1;
}

.modal-header .close:hover {
    background-color: #f8f9fa;
    color: #212529;
    transform: rotate(90deg);
}

/*
 * Bootstrap 5 `.btn-close` in modal headers: match settings-style ×
 * (light weight, grey, circular hover, 90° spin) instead of the dark pill + bars.
 */
.modal-header .btn-close {
    background-color: transparent !important;
    background-image: none !important;
    border: none !important;
    -webkit-mask-image: none !important;
    mask-image: none !important;
    opacity: 1 !important;
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.2s ease !important;
    position: relative !important;
    font-size: 0 !important;
    flex-shrink: 0;
}

.modal-header .btn-close::before {
    content: '\00d7' !important;
    position: static !important;
    display: block !important;
    width: auto !important;
    height: auto !important;
    background: none !important;
    background-color: transparent !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    font-size: 28px !important;
    font-weight: 300 !important;
    color: #6c757d !important;
    line-height: 1 !important;
}

.modal-header .btn-close::after {
    content: none !important;
    display: none !important;
}

.modal-header .btn-close:hover {
    background-color: #f8f9fa !important;
    border: none !important;
    opacity: 1 !important;
    transform: rotate(90deg) !important;
}

/* Close button in modal-content (for modals without modal-header like settings page) */
.modal-content > .close {
    background: none !important;
    border: none !important;
    font-size: 28px !important;
    font-weight: 300 !important;
    color: #6c757d !important;
    cursor: pointer !important;
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.2s ease !important;
    line-height: 1 !important;
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 10 !important;
    float: none !important; /* Override old float: right */
}

.modal-content > .close:hover {
    background-color: #f8f9fa !important;
    color: #212529 !important;
    transform: rotate(90deg) !important;
}

/* Close button in automation modal header (nested structure) */
#automationSettingsModal .close,
#automationSettingsModal .close:hover {
    background: none !important;
    border: none !important;
    font-size: 28px !important;
    font-weight: 300 !important;
    color: #6c757d !important;
    cursor: pointer !important;
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.2s ease !important;
    line-height: 1 !important;
    float: none !important;
}

#automationSettingsModal .close:hover {
    background-color: #f8f9fa !important;
    color: #212529 !important;
    transform: rotate(90deg) !important;
}

/* ============================================================
   AUTOMATION MODAL — Redesigned UI
   ============================================================ */

/* Force wider modal */
#automationSettingsModal > .modal-content {
    max-width: 740px !important;
    width: 95% !important;
}

#emailPreviewModal > .modal-content {
    max-width: 580px !important;
    width: 92% !important;
}

/* Header */
.auto-header {
    padding: 20px 24px 0 24px;
    flex-shrink: 0;
}
.auto-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.auto-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}
.auto-header-title h3 {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: #1d1d1f;
    letter-spacing: -0.02em;
}
.auto-header-title i {
    font-size: 1.1rem;
}
.auto-status-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 980px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.auto-status-pill.is-on {
    background: rgba(52, 199, 89, 0.12);
    color: #28a745;
}
.auto-status-pill.is-off {
    background: rgba(142, 142, 147, 0.12);
    color: #8e8e93;
}
.auto-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.auto-icon-btn,
button.auto-icon-btn {
    background: none;
    border: 1px solid #e5e5e7;
    border-radius: 50%;
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
    max-width: 34px !important;
    max-height: 34px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6e6e73;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    padding: 0 !important;
    box-sizing: border-box;
    line-height: 1;
}
.auto-icon-btn:hover {
    background: #f5f5f5;
    color: #1d1d1f;
    border-color: #d1d1d6;
}
.auto-close-btn {
    border: none;
    font-size: 1rem;
}
.auto-close-btn:hover {
    background: #f5f5f5;
    color: #1d1d1f;
    transform: rotate(90deg) !important;
}

/* Tabs */
.auto-tabs-row {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #e5e5e7;
}
.auto-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 8px;
    font-size: 0.82rem;
    font-weight: 500;
    color: #8e8e93;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.auto-tab:hover {
    color: #1d1d1f;
    background: rgba(201, 123, 75, 0.04);
}
.auto-tab.active {
    color: #C97B4B;
    border-bottom-color: #C97B4B;
    font-weight: 600;
}
.auto-tab i {
    font-size: 0.8rem;
}

/* Tab Panels */
.auto-tab-panel {
    display: none;
}
.auto-tab-panel.active {
    display: block;
}

/* Help Banner */
.auto-help-banner {
    margin: 16px 24px 0 24px;
    background: #FFF8F0;
    border: 1px solid rgba(201, 123, 75, 0.2);
    border-radius: 12px;
    padding: 16px 20px;
}
.auto-help-content h5 {
    margin: 0 0 8px 0;
    font-size: 0.9rem;
    color: #C97B4B;
    font-weight: 600;
}
.auto-help-content p {
    margin: 0 0 8px 0;
    font-size: 0.82rem;
    color: #6e6e73;
    line-height: 1.5;
}
.auto-help-content ul {
    padding-left: 18px;
    margin: 0 0 10px 0;
}
.auto-help-content li {
    font-size: 0.82rem;
    color: #6e6e73;
    margin-bottom: 4px;
    line-height: 1.5;
}
.auto-help-trust {
    margin: 0 !important;
    padding: 10px 14px;
    background: rgba(52, 199, 89, 0.06);
    border-radius: 8px;
    color: #28a745 !important;
    font-weight: 500;
}
.auto-help-trust i {
    margin-right: 4px;
}

/* Master Control Card */
.auto-master-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background: linear-gradient(135deg, #FAFAF7 0%, #FFF8F0 100%);
    border: 1px solid #e5e5e7;
    border-radius: 16px;
    margin-bottom: 16px;
}
.auto-master-left {
    display: flex;
    align-items: center;
    gap: 14px;
}
.auto-master-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(201, 123, 75, 0.1);
    color: #C97B4B;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.auto-master-card h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #1d1d1f;
}
.auto-master-card p {
    margin: 2px 0 0 0;
    font-size: 0.78rem;
    color: #8e8e93;
}

/* Toggle Switch — override global checkbox unification */
.auto-toggle {
    position: relative !important;
    display: inline-block !important;
    width: 48px !important;
    height: 28px !important;
    flex-shrink: 0 !important;
    flex-direction: unset !important;
    align-items: unset !important;
    justify-content: unset !important;
    gap: 0 !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
    font-weight: unset !important;
    line-height: unset !important;
    cursor: pointer !important;
}
.auto-toggle input,
.auto-toggle input[type="checkbox"] {
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    min-width: 0 !important;
    min-height: 0 !important;
    position: absolute !important;
    visibility: hidden !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}
.auto-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #e5e5e7;
    transition: 0.25s ease;
    border-radius: 28px;
}
.auto-toggle-slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.25s ease;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.auto-toggle input:checked + .auto-toggle-slider {
    background-color: #C97B4B;
}
.auto-toggle input:checked + .auto-toggle-slider::before {
    transform: translateX(20px);
}
.auto-toggle input:disabled + .auto-toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}
.auto-toggle-sm {
    width: 40px !important;
    height: 24px !important;
}
.auto-toggle-sm .auto-toggle-slider::before {
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
}
.auto-toggle-sm input:checked + .auto-toggle-slider::before {
    transform: translateX(16px);
}

/* Settings Card */
.auto-settings-card {
    border: 1px solid #e5e5e7;
    border-radius: 14px;
    margin-bottom: 14px;
    overflow: hidden;
    background: #fff;
}
.auto-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: #FAFAF7;
    border-bottom: 1px solid #f0f0f2;
}
.auto-card-header i {
    color: #C97B4B;
    font-size: 0.9rem;
    width: 18px;
    text-align: center;
}
.auto-card-header h4 {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: #1d1d1f;
    flex: 1;
}
.auto-card-header .auto-toggle {
    margin-left: auto;
}
.auto-card-body {
    padding: 16px 18px;
}
.auto-hint {
    margin: 8px 0 0 0;
    font-size: 0.75rem;
    color: #8e8e93;
    line-height: 1.4;
}

/* Inputs */
.auto-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e5e5e7;
    border-radius: 10px;
    font-size: 0.85rem;
    font-family: 'Inter', -apple-system, sans-serif;
    color: #1d1d1f;
    background: #fff;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}
.auto-input:focus {
    outline: none;
    border-color: #C97B4B;
    box-shadow: 0 0 0 3px rgba(201, 123, 75, 0.1);
}
.auto-input[type="number"] {
    max-width: 100px;
}
.auto-input[type="time"] {
    max-width: 140px;
}

/* Limit Row */
.auto-limit-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.auto-limit-label {
    font-size: 0.82rem;
    color: #6e6e73;
}

/* Time Row */
.auto-time-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.auto-time-field {
    flex: 1;
    min-width: 140px;
}
.auto-time-field label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: #6e6e73;
    margin-bottom: 6px;
}

/* Day Chips */
.auto-days-grid {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
/* Day Chips — override global checkbox/label unification */
.auto-day-chip {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0 !important;
    padding: 6px 14px !important;
    border: 1px solid #e5e5e7;
    border-radius: 980px;
    font-size: 0.78rem;
    font-weight: 500 !important;
    color: #6e6e73;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    flex-direction: row !important;
    line-height: 1.2 !important;
    text-align: center !important;
    position: relative !important;
    overflow: hidden !important;
}
.auto-day-chip input,
.auto-day-chip input[type="checkbox"] {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    pointer-events: none !important;
}
.auto-day-chip:has(input:checked) {
    background: rgba(201, 123, 75, 0.1);
    border-color: #C97B4B;
    color: #C97B4B;
}
.auto-day-chip:has(input:disabled) {
    opacity: 0.7;
    cursor: default;
}
.auto-day-chip:has(input:checked:disabled) {
    background: rgba(201, 123, 75, 0.06);
    border-color: rgba(201, 123, 75, 0.3);
    color: #C97B4B;
    opacity: 1;
}

/* ===== Automations Tab — Email Cards ===== */
.auto-email-card {
    border: 1px solid #e5e5e7;
    border-radius: 14px;
    margin-bottom: 14px;
    overflow: hidden;
    background: #fff;
    transition: all 0.2s ease;
}
.auto-email-card:hover {
    border-color: #d1d1d6;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.auto-email-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
}
.auto-email-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.auto-email-card-info {
    flex: 1;
    min-width: 0;
}
.auto-email-card-info h4 {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: #1d1d1f;
}
.auto-email-card-info p {
    margin: 2px 0 0 0;
    font-size: 0.75rem;
    color: #8e8e93;
    line-height: 1.3;
}
.auto-email-card-body {
    padding: 0 18px 14px 18px;
    border-top: 1px solid #f0f0f2;
    padding-top: 14px;
}
.auto-field-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
.auto-field {
    flex: 1;
    min-width: 130px;
}
.auto-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: #6e6e73;
    margin-bottom: 6px;
}
.auto-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.auto-input-group span {
    font-size: 0.8rem;
    color: #8e8e93;
    white-space: nowrap;
}
.auto-email-card-actions {
    display: flex;
    gap: 8px;
    padding: 0 18px 14px 18px;
    border-top: 1px solid #f0f0f2;
    padding-top: 12px;
}
.auto-preview-btn,
.auto-test-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 980px;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid;
    font-family: 'Inter', -apple-system, sans-serif;
}
.auto-preview-btn {
    background: #fff;
    border-color: #e5e5e7;
    color: #6e6e73;
}
.auto-preview-btn:hover {
    background: #f5f5f5;
    color: #1d1d1f;
    border-color: #d1d1d6;
}
.auto-test-btn {
    background: rgba(201, 123, 75, 0.08);
    border-color: rgba(201, 123, 75, 0.25);
    color: #C97B4B;
}
.auto-test-btn:hover {
    background: rgba(201, 123, 75, 0.15);
    border-color: #C97B4B;
}
.auto-test-btn:disabled,
.auto-preview-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Insights Tab ===== */
.auto-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.auto-stat-card {
    background: linear-gradient(135deg, #FAFAF7 0%, #FFF8F0 100%);
    border: 1px solid #e5e5e7;
    border-radius: 14px;
    padding: 16px;
    text-align: center;
}
.auto-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #C97B4B;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.auto-stat-label {
    font-size: 0.72rem;
    color: #8e8e93;
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Breakdown List */
.auto-breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.auto-breakdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #f5f5f5;
}
.auto-breakdown-item:last-child {
    border-bottom: none;
}
.auto-breakdown-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.auto-breakdown-label {
    flex: 1;
    font-size: 0.82rem;
    color: #6e6e73;
}
.auto-breakdown-value {
    font-size: 0.88rem;
    font-weight: 600;
    color: #1d1d1f;
}
.auto-refresh-btn {
    background: none;
    border: 1px solid #e5e5e7;
    border-radius: 8px;
    padding: 4px 10px;
    cursor: pointer;
    color: #8e8e93;
    font-size: 0.78rem;
    transition: all 0.2s ease;
    margin-left: auto;
}
.auto-refresh-btn:hover {
    background: #f5f5f5;
    color: #1d1d1f;
}

/* Health Grid */
.auto-health-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 14px;
}
.auto-health-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.auto-health-label {
    font-size: 0.75rem;
    color: #8e8e93;
    font-weight: 500;
}
.auto-health-value {
    font-size: 0.88rem;
    font-weight: 600;
    color: #1d1d1f;
}

/* Trust Note */
.auto-trust-note {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: rgba(52, 199, 89, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(52, 199, 89, 0.12);
}
.auto-trust-note i {
    color: #34C759;
    margin-top: 2px;
    flex-shrink: 0;
}
.auto-trust-note p {
    margin: 0;
    font-size: 0.75rem;
    color: #6e6e73;
    line-height: 1.5;
}

/* Email Preview */
.auto-preview-subject {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 12px 16px;
    background: #FAFAF7;
    border-radius: 10px;
    margin-bottom: 16px;
}
.auto-preview-subject label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #8e8e93;
    white-space: nowrap;
}
.auto-preview-subject span {
    font-size: 0.88rem;
    font-weight: 600;
    color: #1d1d1f;
}
.auto-preview-body {
    padding: 20px;
    background: #fff;
    border: 1px solid #e5e5e7;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.6;
    color: #1d1d1f;
    min-height: 120px;
}
.auto-preview-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    padding: 10px 14px;
    background: #FFF8F0;
    border-radius: 8px;
    font-size: 0.75rem;
    color: #C97B4B;
    line-height: 1.4;
}
.auto-preview-note i {
    margin-top: 1px;
    flex-shrink: 0;
}

/* Footer Buttons */
.auto-btn-cancel {
    padding: 8px 20px;
    border: 1px solid #e5e5e7;
    border-radius: 980px;
    background: #fff;
    color: #6e6e73;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', -apple-system, sans-serif;
}
.auto-btn-cancel:hover {
    background: #f5f5f5;
    color: #1d1d1f;
}
.auto-btn-save {
    padding: 8px 24px;
    border: none;
    border-radius: 980px;
    background: #C97B4B;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'Inter', -apple-system, sans-serif;
}
.auto-btn-save:hover {
    background: #B06A3D;
    transform: scale(1.02);
}

/* Toast Notification */
.auto-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    z-index: 100000;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    animation: autoToastIn 0.3s ease;
    font-family: 'Inter', -apple-system, sans-serif;
}
.auto-toast.success { background: #28a745; }
.auto-toast.error { background: #dc3545; }
.auto-toast.info { background: #C97B4B; }
@keyframes autoToastIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 640px) {
    #automationSettingsModal > .modal-content {
        max-width: 100% !important;
        width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
    }
    .auto-header {
        padding: 16px 16px 0 16px;
    }
    .auto-master-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }
    .auto-master-card .auto-toggle {
        align-self: flex-end;
    }
    .auto-stats-grid {
        grid-template-columns: 1fr;
    }
    .auto-field-row {
        flex-direction: column;
    }
    .auto-email-card-actions {
        flex-direction: column;
    }
    .auto-preview-btn,
    .auto-test-btn {
        justify-content: center;
        width: 100%;
    }
    .auto-tab {
        font-size: 0.76rem;
        padding: 8px 4px;
    }
    .auto-tab i {
        display: none;
    }
    .auto-days-grid {
        gap: 4px;
    }
    .auto-day-chip {
        padding: 5px 10px;
        font-size: 0.72rem;
    }
    .auto-health-grid {
        grid-template-columns: 1fr;
    }
    .auto-time-row {
        flex-direction: column;
        gap: 10px;
    }
}

/* Close button in email history modal header (nested structure) */
#emailHistoryModal .close,
#emailHistoryModal .close:hover {
    background: none !important;
    border: none !important;
    font-size: 28px !important;
    font-weight: 300 !important;
    color: #6c757d !important;
    cursor: pointer !important;
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.2s ease !important;
    line-height: 1 !important;
    float: none !important;
}

#emailHistoryModal .close:hover {
    background-color: #f8f9fa !important;
    color: #212529 !important;
    transform: rotate(90deg) !important;
}

/* Style h3 titles in modals without modal-header (like settings page) */
.modal-content > h3 {
    margin: 0 !important;
    padding: 20px 20px 15px 20px !important; /* Match .modal-header padding */
    font-size: 1.5rem !important;
    font-weight: 600 !important;
    color: #212529 !important;
    border-bottom: 1px solid #e9ecef !important;
    padding-right: 60px !important; /* Leave space for close button */
}

/* Modal Body - Scrollable content */
.modal-body {
    padding: 24px !important;
    padding-bottom: 0 !important; /* Remove bottom padding when footer is inside */
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    display: flex !important;
    flex-direction: column !important; /* Allow footer inside to stick to bottom */
    position: relative !important; /* For sticky footer positioning */
}

/* Custom scrollbar for modal body */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

/* Modal Footer */
.modal-footer {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 16px 24px !important; /* Equal padding top and bottom */
    border-top: 1px solid #e9ecef !important;
    background-color: #ffffff !important;
    flex-shrink: 0 !important;
    margin-top: auto !important; /* Push footer to bottom */
}

/*
 * Footer that only duplicates the header dismiss: one secondary button (typical "Close")
 * while the modal already has × in .modal-header or top-right .modal-content > .close.
 * Frees vertical space for modal body content.
 */
.modal:has(.modal-header .close) .modal-footer:has(> button.btn-secondary:only-child),
.modal:has(.modal-header .btn-close) .modal-footer:has(> button.btn-secondary:only-child) {
    display: none !important;
}

.modal .modal-content:has(.close) .modal-footer:has(> button.btn-secondary:only-child) {
    display: none !important;
}

/* Handle footer that's inside modal-body (like on customers page) */
.modal-body .modal-footer {
    position: sticky !important;
    bottom: 0 !important;
    margin-top: 24px !important; /* Space above footer */
    margin-bottom: 0 !important;
    background-color: #ffffff !important;
    z-index: 10 !important;
    border-top: 1px solid #e9ecef !important;
    padding: 16px 24px !important;
}

/* Handle footer that's inside form but outside modal-body (like Business Settings modal) */
form .modal-footer {
    margin-top: auto !important; /* Push footer to bottom */
    flex-shrink: 0 !important;
}

/* Ensure forms inside modal-content use flexbox when they contain modal-body and modal-footer */
.modal-content > form,
.modal-content form:has(.modal-body):has(.modal-footer) {
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
}

.modal-footer .btn {
    margin: 0 !important;
    min-width: 100px;
}

/* ============================================================
   Future modal defaults (opt-in): bubble action style
   Use on new modals only: <div class="modal" data-modal-default="bubble">
   Keeps existing modals untouched.
   ============================================================ */
.modal[data-modal-default="bubble"] .modal-footer .btn {
    border-radius: 999px !important;
    border: none !important;
    min-height: 40px !important;
    padding: 9px 18px !important;
    font-weight: 600 !important;
    box-shadow: 0 2px 8px rgba(30, 144, 255, 0.08) !important;
}

.modal[data-modal-default="bubble"] .modal-footer .btn-primary {
    background: #007bff !important;
    color: #ffffff !important;
}

.modal[data-modal-default="bubble"] .modal-footer .btn-primary:hover,
.modal[data-modal-default="bubble"] .modal-footer .btn-primary:focus {
    background: #0056b3 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 16px rgba(0, 123, 255, 0.25) !important;
}

.modal[data-modal-default="bubble"] .modal-footer .btn-secondary,
.modal[data-modal-default="bubble"] .modal-footer .btn-outline-secondary {
    background: #e0e7ef !important;
    color: #6c757d !important;
    border: none !important;
}

/* New default: if header has ×, hide redundant footer cancel for bubble-default modals */
.modal[data-modal-default="bubble"]:has(.modal-header .close) .modal-footer .btn-secondary,
.modal[data-modal-default="bubble"]:has(.modal-header .btn-close) .modal-footer .btn-secondary,
.modal[data-modal-default="bubble"] .modal-content:has(.close) .modal-footer .btn-secondary,
.modal[data-modal-default="bubble"]:has(.modal-header .close) .modal-footer .btn-outline-secondary,
.modal[data-modal-default="bubble"]:has(.modal-header .btn-close) .modal-footer .btn-outline-secondary,
.modal[data-modal-default="bubble"] .modal-content:has(.close) .modal-footer .btn-outline-secondary {
    display: none !important;
}

/* Dashboard — Review Uncompleted Jobs: scrollable list, actions in footer, avoid global 80vh empty space */
#oldBookedJobsModal .modal-content {
    height: auto !important;
    max-height: min(88vh, calc(100vh - 96px)) !important;
}

#oldBookedJobsModal .modal-header {
    margin-bottom: 0 !important;
    position: relative !important;
    top: auto !important;
}

#oldBookedJobsModal .modal-body {
    display: block !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: min(56vh, calc(88vh - 220px)) !important;
    overflow-y: auto !important;
    padding: 14px 20px !important;
}

#oldBookedJobsModal .modal-footer.old-booked-jobs-modal-footer {
    position: relative !important;
    bottom: auto !important;
    margin-top: 0 !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
    padding: 12px 16px 14px 16px !important;
    background-color: #f8f9fa !important;
    border-top: 1px solid #dee2e6 !important;
}

#oldBookedJobsModal .old-booked-jobs-modal-footer .btn {
    min-width: 0 !important;
}

#oldBookedJobsModal #markCompletedBtn {
    flex: 1 1 140px;
}

#oldBookedJobsModal .old-booked-jobs-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

@media (max-width: 576px) {
    #oldBookedJobsModal .modal-footer.old-booked-jobs-modal-footer {
        flex-direction: column;
        align-items: stretch !important;
    }
    #oldBookedJobsModal #markCompletedBtn {
        flex: 1 1 auto;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .modal.show {
        padding: 0 !important; /* Full screen on mobile */
        align-items: flex-end !important; /* Slide up from bottom on mobile */
    }
    
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        border-radius: 20px 20px 0 0 !important; /* Rounded top corners only */
        margin: 0 !important; /* Remove all margins on mobile */
        animation: slideUpMobile 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    .modal-header {
        padding: 20px 20px 15px 20px !important;
    }
    
    .modal-body {
        padding: 20px !important;
        max-height: calc(90vh - 140px) !important;
    }
    
    .modal-footer {
        padding: 16px 20px 20px 20px !important;
        flex-direction: column-reverse;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100% !important;
        min-width: auto;
    }
    
    @keyframes slideUpMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* iOS Safe Area Support */
@supports (-webkit-touch-callout: none) {
    .modal-content {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .modal-footer {
        padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important;
    }
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Hide hamburger menu when modal is open */
body.modal-open .hamburger,
.modal.show ~ .hamburger,
body:has(.modal.show) .hamburger {
    display: none !important;
    z-index: 1 !important;
    pointer-events: none !important;
}

/* REMOVED: All duplicate/conflicting modal styles - using modern modal system above */

/* Prevent button hover effects from causing overflow */
.modal-content .btn {
    max-width: 100%;
    box-sizing: border-box;
    transform: none !important; /* Prevent any transform effects */
    transition: background-color 0.2s, color 0.2s, border-color 0.2s !important; /* Only allow color transitions */
}

.modal-content .btn:hover {
    transform: none !important; /* Prevent scale/transform on hover */
    max-width: 100% !important; /* Ensure button doesn't grow beyond container */
    box-sizing: border-box !important;
}

/* Add vertical padding to the scrollable area */
.modal-content {
    position: relative;
    padding-top: 24px !important;
    padding-bottom: 24px !important;
}

/* Hide scrollbar at the very top and bottom using overlays - DISABLED FOR iOS */
/* These pseudo-elements can cover content on iOS Safari */
.modal-content::before,
.modal-content::after {
    content: none !important; /* Disable by default */
    display: none !important; /* Ensure they don't render */
}

/* Only enable on desktop browsers, not on iOS */
@supports not (-webkit-touch-callout: none) {
    .modal-content::before,
    .modal-content::after {
        content: "";
        position: absolute;
        left: 0;
        width: 100%;
        height: 18px;
        background: #fefefe;
        z-index: 2;
        pointer-events: none;
    }
    .modal-content::before {
        top: 0;
        border-radius: inherit;
    }
    .modal-content::after {
        bottom: 0;
        border-radius: inherit;
    }
}

/* Optional: style the scrollbar for aesthetics */
.modal-content::-webkit-scrollbar {
    width: 10px;
}
.modal-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 8px;
}
.modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Enhanced Bootstrap close button for better contrast - DARK STANDARD */
.btn-close, #actionLogModal .btn-close {
    background-color: #495057 !important; /* Dark grey background */
    border: 2px solid #495057 !important;
    border-radius: 50% !important;
    width: 30px !important;
    height: 30px !important;
    opacity: 1 !important;
    position: relative !important;
    padding: 0 !important;
    font-size: 0 !important;
}

.btn-close::before,
.btn-close::after,
#actionLogModal .btn-close::before,
#actionLogModal .btn-close::after {
    content: '' !important;
    position: absolute !important;
    width: 15px !important;
    height: 2px !important;
    background-color: white !important; /* White X */
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
}

.btn-close::before,
#actionLogModal .btn-close::before {
    transform: translate(-50%, -50%) rotate(45deg) !important;
}

.btn-close::after,
#actionLogModal .btn-close::after {
    transform: translate(-50%, -50%) rotate(-45deg) !important;
}

.btn-close:hover,
#actionLogModal .btn-close:hover {
    background-color: #343a40 !important; /* Darker grey on hover */
    border-color: #343a40 !important;
    opacity: 0.9 !important;
}

/* Smaller close button for compact modals */
.btn-close-sm {
    width: 24px !important;
    height: 24px !important;
}

.btn-close-sm::before,
.btn-close-sm::after {
    width: 12px !important;
    height: 2px !important;
}

/* Ensure modal footer buttons don't cause overflow */
.modal-footer {
    margin-top: 20px;
    text-align: right;
    position: sticky; /* Make the footer sticky when scrolling */
    bottom: 0;
    background-color: #fefefe;
    z-index: 1;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
    /* Changed from overflow: hidden to visible for iOS compatibility */
    overflow: visible;
    /* Ensure pointer events work */
    pointer-events: auto;
}

.modal-footer .btn {
    margin-left: 10px;
    max-width: calc(50% - 5px); /* Ensure buttons don't exceed half the footer width */
    box-sizing: border-box;
    transform: none !important;
    /* Ensure buttons are fully clickable */
    position: relative;
    z-index: 10;
    pointer-events: auto;
    /* Remove tap highlight issues */
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    /* Ensure cursor shows as pointer */
    cursor: pointer;
}

.modal-footer .btn:hover {
    transform: none !important;
    max-width: calc(50% - 5px) !important;
}

/* Mobile override: ensure full-width clickable buttons and no hover shrink */
@media (max-width: 768px) {
    .modal-footer { 
        text-align: initial !important; 
    }
    .modal-footer .btn,
    .modal-footer .btn:hover {
        max-width: 100% !important;
        width: 100% !important;
        display: flex !important;
    }
}

/* Ensure content doesn't go behind the sticky footer */
.modal-body {
    padding-bottom: 10px;
}

/* Make only the modal-body scrollable, not the header/footer */
.modal-content {
    overflow: hidden !important; /* Ensures children are clipped to border-radius */
    display: flex;
    flex-direction: column;
    height: 80vh; /* or your preferred max height */
    max-height: 85vh;
    border-radius: 20px !important; /* or your preferred value */
}

.modal-header,
.modal-footer {
    flex-shrink: 0;
}

.modal-body {
    overflow-y: auto;
    flex: 1 1 auto;
    padding-top: 18px;   /* This is where the scrollbar will start */
    padding-bottom: 18px;
    background: #fefefe;
    /* Optional: add left/right padding if needed */
}

/* Custom scrollbar for modal-body only */
.modal-body::-webkit-scrollbar {
    width: 10px;
}
.modal-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 8px;
}
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

/* Modern search dropdown styles */
#globalSearchResults {
    background: rgba(255, 255, 255, 0.85); /* semi-transparent white */
    backdrop-filter: blur(8px); /* frosted glass effect */
    border: 1px solid #cfd8dc;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border-radius: 12px;
    padding: 0.5em 0;
    margin-top: 2px;
    transition: box-shadow 0.18s;
}
#globalSearchResults .list-group-item {
    background: transparent;
    border: none;
    color: #333;
    padding: 0.7em 1.2em;
    font-size: 1.05em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
#globalSearchResults .list-group-item.active {
    background: #e3f2fd;
    color: #1976d2;
}
#globalSearchResults .list-group-item:hover {
    background: #f5faff;
    color: #1565c0;
}

/* Email Templates Modal Styles */
.email-templates-container {
    width: 100%;
    max-width: 800px;
}

.template-tabs {
    display: flex;
    border-bottom: 2px solid #e9ecef;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 5px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 15px;
    cursor: pointer;
    color: #6c757d;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 120px;
    text-align: center;
}

.tab-btn:hover {
    color: #495057;
    background-color: #f8f9fa;
}

.tab-btn.active {
    color: #007bff;
    border-bottom-color: #007bff;
    background-color: #f8f9fa;
}

.template-tab {
    display: none;
}

.template-tab.active {
    display: block;
}

.template-variables {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 5px;
    border-left: 4px solid #007bff;
}

.template-variables h5 {
    margin-bottom: 10px;
    color: #495057;
}

.template-variables ul {
    margin: 0;
    padding-left: 20px;
}

.template-variables li {
    margin-bottom: 5px;
    color: #6c757d;
}

.template-variables code {
    background-color: #e9ecef;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.9em;
    color: #e83e8c;
}

.default-badge {
    font-size: 0.8em;
    color: #6c757d;
    font-weight: normal;
    font-style: italic;
}

#emailSettingsModal .modal-content {
    max-width: 900px;
    width: 90%;
}

/* Price increase reminder checkbox styling */
.price-increase-section {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-top: 10px;
}

.price-increase-section .form-control {
    flex: 1;
    max-width: 200px;
    transition: all 0.3s ease;
}

.price-increase-section .form-control.price-highlighted {
    background-color: #fff3cd;
    border-color: #ffc107;
    box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
    font-weight: 600;
    color: #856404;
}

.price-increase-section .form-control.price-highlighted:focus {
    background-color: #fff3cd;
    border-color: #ffc107;
    box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
    color: #856404;
}

.price-increase-section .checkbox-container {
    flex: 1;
    padding-top: 5px;
}

.price-increase-section small {
    color: #6c757d;
    font-size: 0.875em;
    line-height: 1.4;
}

/* Mobile optimizations for modal forms */
@media (max-width: 768px) {
    /* Stack price section vertically on mobile */
    .price-increase-section {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 15px !important;
    }
    
    .price-increase-section .form-control {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    .price-increase-section .checkbox-container {
        padding-top: 0 !important;
        width: 100% !important;
    }
    
    /* Compact form groups on mobile */
    .modal-body .form-group {
        margin-bottom: 1.25rem !important;
        text-align: left !important;
        display: block !important;
        width: 100% !important;
    }
    
    .modal-body label {
        text-align: left !important;
        justify-content: flex-start !important;
        display: flex !important;
        width: 100% !important;
    }
    
    /* Reminder status items */
    .reminder-status-container {
        gap: 12px !important;
    }
    
    .reminder-status-item {
        gap: 8px !important;
    }
    
    /* Small text under checkboxes */
    .checkbox-label + small,
    .text-muted {
        display: block !important;
        margin-top: 6px !important;
        margin-left: 30px !important; /* Align with text after checkbox */
        padding-left: 0 !important;
        text-align: left !important;
    }
}

/* Price highlighting on customers page */
.service-price.price-highlighted {
    background-color: #fff3cd !important;
    border: 2px solid #ffc107 !important;
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: 600;
    color: #856404 !important;
    box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
    transition: all 0.3s ease;
}

.service-price.price-highlighted:hover {
    background-color: #ffeaa7 !important;
    border-color: #f39c12 !important;
}

/* Invoice Status Modal Specific Fixes */
.status-modal-content {
    max-height: calc(100vh - 40px) !important;
    width: 90% !important;
    max-width: 600px !important;
    margin: 20px auto !important;
    display: flex !important;
    flex-direction: column !important;
    background-color: #fefefe !important;
    border: 1px solid #888 !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
    overflow: hidden !important;
    position: relative !important;
}

/* Override any conflicting styles for status modal */
#statusModal .modal-content {
    max-height: calc(100vh - 40px) !important;
    width: 90% !important;
    max-width: 600px !important;
    margin: 20px auto !important;
    display: flex !important;
    flex-direction: column !important;
    background-color: #fefefe !important;
    border: 1px solid #888 !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
    overflow: hidden !important;
    position: relative !important;
    padding: 0 !important; /* Remove any default padding */
}

.status-modal-content .modal-header {
    flex-shrink: 0 !important;
    padding: 20px 20px 0 20px !important;
    border-bottom: 1px solid #e9ecef !important;
    margin-bottom: 0 !important;
}

.status-modal-content .modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 20px !important;
    min-height: 0 !important;
    max-height: calc(100vh - 200px) !important;
}

.status-modal-content .modal-footer {
    flex-shrink: 0 !important;
    padding: 0 20px 20px 20px !important;
    border-top: 1px solid #e9ecef !important;
    margin-top: 0 !important;
    display: flex !important;
    justify-content: flex-end !important;
    gap: 10px !important;
    /* Remove overflow hidden to prevent clipping on iOS */
    overflow: visible !important;
}

.status-modal-content .modal-footer .btn {
    padding: 8px 16px !important;
    border-radius: 4px !important;
    min-width: 100px !important;
    /* Ensure full clickable area */
    box-sizing: border-box !important;
    position: relative !important;
    z-index: 10 !important;
    /* Ensure button is fully clickable */
    pointer-events: auto !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important;
}

/* Mobile-specific fixes for status modal */
@media (max-width: 768px) {
    .status-modal-content,
    #statusModal .modal-content {
        max-height: calc(100vh - 20px) !important;
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
    }
    
    .status-modal-content .modal-body,
    #statusModal .modal-body {
        max-height: calc(100vh - 180px) !important;
        padding: 15px !important;
        overflow-y: auto !important;
    }
    
    .status-modal-content .modal-footer,
    #statusModal .modal-footer {
        padding: 0 15px 15px 15px !important;
        flex-direction: column !important;
        /* Remove gap completely on mobile - use margin instead */
        gap: 0 !important;
        overflow: visible !important;
    }
    
    .status-modal-content .modal-footer .btn,
    #statusModal .modal-footer .btn {
        /* CRITICAL: Change from inline-flex to flex for full clickable width */
        display: flex !important;
        -webkit-display: flex !important;
        display: -webkit-flex !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 0 10px 0 !important;
        /* Ensure full clickable area */
        box-sizing: border-box !important;
        position: relative !important;
        /* Remove any padding that might reduce clickable area */
        padding: 12px 16px !important;
        /* Center text within button */
        justify-content: center !important;
        -webkit-justify-content: center !important;
        align-items: center !important;
        -webkit-align-items: center !important;
        text-align: center !important;
        /* Ensure entire button is clickable */
        pointer-events: auto !important;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important;
        /* Prevent any transforms that might affect click area */
        transform: none !important;
        -webkit-transform: none !important;
        /* Ensure button content doesn't block clicks */
        overflow: visible !important;
    }
    
    /* Ensure button text doesn't limit click area */
    .status-modal-content .modal-footer .btn *,
    #statusModal .modal-footer .btn * {
        pointer-events: none !important;
    }
    
    /* Last button shouldn't have bottom margin */
    .status-modal-content .modal-footer .btn:last-child,
    #statusModal .modal-footer .btn:last-child {
        margin-bottom: 0 !important;
    }
}

/* Force status modal to use proper structure */
#statusModal {
    display: none !important;
    position: fixed !important;
    z-index: 10000 !important; /* Higher than hamburger menu (9999) */
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background-color: rgba(0,0,0,0.4) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 20px 0 !important;
}

#statusModal.show {
    display: flex !important;
    align-items: flex-start !important;
    justify-content: center !important;
    padding-top: 20px !important;
    padding-bottom: 20px !important;
}

/* Additional mobile fixes for real devices */
@media (max-width: 480px) {
    .status-modal-content,
    #statusModal .modal-content {
        max-height: calc(100vh - 10px) !important;
        width: 98% !important;
        max-width: 98% !important;
        margin: 5px auto !important;
    }
    
    .status-modal-content .modal-body,
    #statusModal .modal-body {
        max-height: calc(100vh - 160px) !important;
        padding: 12px !important;
        overflow-y: auto !important;
    }
    
    .status-modal-content .modal-header,
    #statusModal .modal-header {
        padding: 15px 15px 0 15px !important;
    }
    
    .status-modal-content .modal-footer,
    #statusModal .modal-footer {
        padding: 0 15px 15px 15px !important;
    }
}

/* Force mobile viewport fixes for real devices */
@media screen and (max-width: 768px) {
    #statusModal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        overflow-y: auto !important;
        padding: 0 !important;
    }
    
    #statusModal .modal-content {
        position: relative !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        margin: 10px !important;
        width: calc(100% - 20px) !important;
        max-width: calc(100% - 20px) !important;
        max-height: calc(100vh - 20px) !important;
    }
}

/* ============================================
   iOS/Safari Compatibility Fixes
   ============================================ */

/* iOS Safari WebKit prefixes for backdrop-filter */
#globalSearchResults {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

/* iOS Safari modal fixes - Ensure content is visible */
@supports (-webkit-touch-callout: none) {
    /* Disable pseudo-elements on iOS that might cover content */
    .modal-content::before,
    .modal-content::after,
    .status-modal-content::before,
    .status-modal-content::after,
    #statusModal .modal-content::before,
    #statusModal .modal-content::after {
        content: none !important;
        display: none !important;
    }
    
    /* iOS Safari specific styles */
    .modal.show {
        display: -webkit-flex !important;
        display: flex !important;
        -webkit-align-items: flex-start !important;
        align-items: flex-start !important;
        -webkit-justify-content: center !important;
        justify-content: center !important;
        padding: 20px !important;
    }
    
    .modal-content {
        -webkit-display: flex;
        display: -webkit-flex;
        display: flex;
        -webkit-flex-direction: column;
        flex-direction: column;
        /* Use reasonable max-height for mobile */
        max-height: 90vh !important;
        margin-top: 20px !important;
        margin-bottom: 20px !important;
        /* Ensure content is not hidden */
        opacity: 1 !important;
        visibility: visible !important;
        position: relative !important;
        overflow: hidden !important;
        /* iOS Safe Area Insets - Fix left/right offset */
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
    }
    
    .status-modal-content,
    #statusModal .modal-content {
        display: -webkit-flex !important;
        display: flex !important;
        -webkit-flex-direction: column !important;
        flex-direction: column !important;
        opacity: 1 !important;
        visibility: visible !important;
        position: relative !important;
        /* Force content to be visible */
        background-color: #fefefe !important;
        -webkit-transform: none !important;
        transform: none !important;
        overflow: hidden !important;
        /* iOS Safe Area Insets - Fix left/right offset */
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
    }
    
    /* Ensure no pseudo-elements cover content on status modal */
    .status-modal-content::before,
    .status-modal-content::after {
        content: none !important;
        display: none !important;
    }
    
    .modal-body {
        opacity: 1 !important;
        visibility: visible !important;
        /* Ensure text and content is visible */
        color: #212529 !important;
        /* Force content rendering */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        /* Ensure it's above any pseudo-elements */
        position: relative !important;
        z-index: 100 !important;
        /* Allow content to overflow if needed */
        overflow: visible !important;
    }
    
    .modal-header,
    .modal-footer {
        opacity: 1 !important;
        visibility: visible !important;
        display: -webkit-flex !important;
        display: flex !important;
        position: relative !important;
        z-index: 10 !important; /* Higher than any pseudo-elements */
    }
    
    /* Ensure modal body has higher z-index than pseudo-elements */
    .modal-body,
    .status-modal-content .modal-body,
    #statusModal .modal-body {
        position: relative !important;
        z-index: 10 !important; /* Higher than any pseudo-elements */
    }
    
    /* Ensure icons are visible */
    .fas,
    .far,
    .fa {
        opacity: 1 !important;
        visibility: visible !important;
        display: inline-block !important;
        font-style: normal !important;
        font-weight: normal !important;
        text-rendering: auto !important;
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
    }
    
    /* Ensure icons inside labels are visible */
    #statusModal.show .modal-body label .fas,
    #statusModal.show .modal-body label .far,
    #statusModal.show .modal-body label .fa {
        display: inline-block !important;
        opacity: 1 !important;
        visibility: visible !important;
        margin-right: 8px !important;
    }
    
    /* Fix flexbox gap for iOS Safari */
    .modal-footer,
    .status-modal-content .modal-footer {
        /* Use margin instead of gap for older iOS - completely remove gap */
        gap: 0 !important;
    }
    
    /* Fix icon centering in buttons on mobile */
    @media (max-width: 768px) {
        /* Ensure all icon buttons center their icons properly */
        button[class*="icon"],
        .icon-action-btn,
        .action-btn,
        .search-icon-btn,
        .action-icon {
            display: -webkit-flex !important;
            display: flex !important;
            -webkit-align-items: center !important;
            align-items: center !important;
            -webkit-justify-content: center !important;
            justify-content: center !important;
            text-align: center !important;
            padding: 0 !important;
            /* iOS fix: prevent baseline issues */
            -webkit-box-align: center !important;
            vertical-align: middle !important;
            line-height: 1 !important;
        }
        
        /* Fix icons inside buttons - use flex for iOS centering */
        button i,
        .btn i,
        button .fas,
        button .far,
        button .fa,
        .icon-action-btn i,
        .action-btn i,
        .search-icon-btn i,
        .action-icon i {
            padding: 0 !important;
            display: -webkit-flex !important;
            display: flex !important;
            -webkit-align-items: center !important;
            align-items: center !important;
            -webkit-justify-content: center !important;
            justify-content: center !important;
            line-height: 1 !important;
            vertical-align: middle !important;
        }
        
        /* Preserve icon spacing for buttons with text (not icon-only buttons) - HIGH SPECIFICITY */
        .btn i:not(:only-child):not(.icon-action-btn i):not(.action-btn i):not(.search-icon-btn i):not(.action-icon i),
        button i:not(:only-child):not(.icon-action-btn i):not(.action-btn i):not(.search-icon-btn i):not(.action-icon i),
        .btn-primary i:not(:only-child),
        .btn-secondary i:not(:only-child),
        .btn-success i:not(:only-child),
        .btn-danger i:not(:only-child),
        .btn-info i:not(:only-child),
        .btn-warning i:not(:only-child) {
            margin-right: 0.5rem !important;
            margin-left: 0 !important;
            width: auto !important;
            height: auto !important;
        }
        
        /* Icon-only buttons should have no margin - keep natural size for proper centering */
        .icon-action-btn i,
        .action-btn i:only-child,
        .search-icon-btn i,
        .action-icon i,
        button i:only-child,
        .btn i:only-child {
            margin: 0 !important;
            /* CRITICAL: Do NOT use width/height 100% - breaks iOS centering */
            width: auto !important;
            height: auto !important;
        }
        
        /* Specific fix for circular icon buttons */
        .icon-action-btn,
        .action-btn {
            display: -webkit-inline-flex !important;
            display: inline-flex !important;
            -webkit-align-items: center !important;
            align-items: center !important;
            -webkit-justify-content: center !important;
            justify-content: center !important;
            text-align: center !important;
            -webkit-box-align: center !important;
        }
        
        /* Fix search icon button */
        .search-icon-btn {
            display: -webkit-flex !important;
            display: flex !important;
            -webkit-align-items: center !important;
            align-items: center !important;
            -webkit-justify-content: center !important;
            justify-content: center !important;
            text-align: center !important;
        }
        
        /* Fix any button that contains only an icon */
        button:only-child i,
        .btn:only-child i {
            margin: 0 auto !important;
        }
    }
    
    /* On mobile, buttons should stack vertically with proper spacing */
    @media (max-width: 768px) {
        .modal-footer .btn,
        .status-modal-content .modal-footer .btn {
            width: 100% !important;
            max-width: 100% !important;
            margin-left: 0 !important;
            margin-right: 0 !important;
            margin-bottom: 10px !important;
            margin-top: 0 !important;
            box-sizing: border-box !important;
            /* Ensure full clickable area */
            position: relative !important;
            z-index: 10 !important;
            pointer-events: auto !important;
        }
        
        .modal-footer .btn:last-child,
        .status-modal-content .modal-footer .btn:last-child {
            margin-bottom: 0 !important;
        }
    }
    
    /* Desktop: use margin for gap fallback */
    @media (min-width: 769px) {
        .modal-footer .btn,
        .status-modal-content .modal-footer .btn {
            margin-left: 5px !important;
            margin-right: 5px !important;
        }
        
        .modal-footer .btn:first-child,
        .status-modal-content .modal-footer .btn:first-child {
            margin-left: 0 !important;
        }
    }
}

/* iOS Safari specific viewport fixes */
@supports (-webkit-touch-callout: none) and (max-width: 768px) {
    /* Use dynamic viewport units that work better on iOS */
    .modal.show {
        height: 100dvh !important;
        max-height: 100dvh !important;
    }
    
    .modal-content,
    .status-modal-content,
    #statusModal .modal-content {
        max-height: 90dvh !important;
        height: auto !important;
    }
    
    .modal-body,
    .status-modal-content .modal-body,
    #statusModal .modal-body {
        max-height: calc(90dvh - 180px) !important;
    }
}

/* Force visibility for all modal content on iOS */
@supports (-webkit-touch-callout: none) {
    #statusModal.show .modal-content *,
    #statusModal.show .status-modal-content * {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    #statusModal.show .modal-body p,
    #statusModal.show .modal-body div,
    #statusModal.show .modal-body label,
    #statusModal.show .modal-body span {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: inherit !important;
    }
    
    /* Ensure current status is visible */
    #currentStatus {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        background-color: #e9ecef !important;
    }
    
    /* Ensure customer name text is visible */
    #customerNameText {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* Additional iOS fixes - ensure no content is hidden */
@supports (-webkit-touch-callout: none) {
    .modal.show .modal-header h3,
    .modal.show .modal-header h4,
    .modal.show .modal-header h5 {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: #212529 !important;
    }
    
    /* Fix for all modals, not just status modal */
    .modal.show {
        /* Prevent iOS Safari from hiding content */
        -webkit-overflow-scrolling: touch;
        overflow-y: auto !important;
    }
    
    .modal.show .modal-content {
        /* Force hardware acceleration */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
    }
    
    /* Ensure all modal body content is visible on iOS */
    .modal.show .modal-body,
    .modal.show .status-modal-content .modal-body,
    #statusModal.show .modal-body {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: #212529 !important;
    }
    
    .modal.show .modal-body *,
    .modal.show .modal-body p,
    .modal.show .modal-body div,
    .modal.show .modal-body span,
    .modal.show .modal-body label,
    .modal.show .modal-body input,
    .modal.show .modal-body select,
    .modal.show .modal-body textarea,
    .modal.show .modal-body button,
    #statusModal.show .modal-body *,
    #statusModal.show .modal-body p,
    #statusModal.show .modal-body div,
    #statusModal.show .modal-body span,
    #statusModal.show .modal-body label {
        opacity: 1 !important;
        visibility: visible !important;
        color: inherit !important;
    }
    
    /* Specific fixes for status modal content */
    #statusModal.show #customerNameText,
    #statusModal.show #currentStatus,
    #statusModal.show .modal-body > div {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: #212529 !important;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
    }
    
    /* Fix for label containers and spans */
    #statusModal.show .modal-body label,
    #statusModal.show .modal-body label span {
        display: flex !important;
        -webkit-display: flex !important;
        display: -webkit-flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: #212529 !important;
        width: 100% !important;
    }
    
    /* Fix for the div containers holding labels - more specific */
    #statusModal.show .modal-body > div,
    #statusModal.show .modal-body > div > div {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        margin-bottom: 15px !important;
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        overflow: visible !important;
    }
    
    /* Force all text nodes to be visible */
    #statusModal.show .modal-body {
        font-size: 16px !important;
        line-height: 1.5 !important;
    }
    
    /* Ensure spans with text are visible */
    #statusModal.show .modal-body span {
        white-space: normal !important;
        word-wrap: break-word !important;
        overflow: visible !important;
    }
    
    /* Fix for modal buttons specifically */
    #statusModal.show .modal-footer .btn,
    #statusModal.show .modal-content .btn {
        opacity: 1 !important;
        visibility: visible !important;
        /* CRITICAL: Use flex instead of inline-block for full width clicks */
        display: flex !important;
        -webkit-display: flex !important;
        display: -webkit-flex !important;
        -webkit-appearance: button !important;
        appearance: button !important;
        /* Ensure full clickable area on iOS */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        position: relative !important;
        z-index: 100 !important;
        pointer-events: auto !important;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important;
        cursor: pointer !important;
        /* Center text */
        justify-content: center !important;
        -webkit-justify-content: center !important;
        align-items: center !important;
        -webkit-align-items: center !important;
        text-align: center !important;
        /* Remove any transforms that might affect click area */
        transform: none !important;
        -webkit-transform: none !important;
    }
    
    /* Ensure button content doesn't block clicks */
    #statusModal.show .modal-footer .btn *,
    #statusModal.show .modal-content .btn * {
        pointer-events: none !important;
    }
    
    /* Specifically for status modal footer buttons on mobile iOS */
    @media (max-width: 768px) {
        #statusModal.show .modal-footer .btn {
            /* CRITICAL: Change display from inline-flex to flex for full width clickable area */
            display: flex !important;
            -webkit-display: flex !important;
            display: -webkit-flex !important;
            width: 100% !important;
            max-width: 100% !important;
            margin-left: 0 !important;
            margin-right: 0 !important;
            margin-bottom: 10px !important;
            box-sizing: border-box !important;
            padding: 12px 20px !important;
            /* Center the text */
            justify-content: center !important;
            -webkit-justify-content: center !important;
            align-items: center !important;
            -webkit-align-items: center !important;
            /* Ensure text doesn't limit clickable area */
            text-align: center !important;
            /* Ensure entire button is clickable - no gaps */
            border: 2px solid !important;
            outline: none !important;
            /* Remove any child elements that might block clicks */
            position: relative !important;
            overflow: visible !important;
        }
        
        #statusModal.show .modal-footer .btn:last-child {
            margin-bottom: 0 !important;
        }
        
        /* Ensure button text doesn't limit click area */
        #statusModal.show .modal-footer .btn * {
            pointer-events: none !important;
        }
    }
}

/* ==========================================================================
   GLOBAL BUTTON ICON SPACING FIX (DEFINITIVE)
   Forces a consistent gap between icons and text in all button-like elements
   ========================================================================== */
.btn, 
button.btn, 
a.btn, 
.toggle-btn, 
.status-bubble, 
.team-bubble, 
.q-service-btn, 
.invoice-section-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important; /* The definitive gap */
}

/* Reset any existing margins on icons within these buttons to prevent double spacing */
.btn i, 
button.btn i, 
a.btn i, 
.toggle-btn i, 
.status-bubble i, 
.team-bubble i, 
.q-service-btn i, 
.invoice-section-btn i,
.btn .fas,
button.btn .fas {
    margin: 0 !important;
    padding: 0 !important;
}

/* If it's an icon-only button (no text), remove the gap to keep it centered */
.btn:has(i:only-child), 
button.btn:has(i:only-child), 
a.btn:has(i:only-child),
.icon-action-btn,
.action-btn {
    gap: 0 !important;
}

/* ==========================================================================
   iOS/MOBILE ICON CENTERING - FLEXBOX APPROACH (GLOBAL)
   Uses flexbox centering - absolute positioning is handled per-page
   ========================================================================== */

/* 
 * ICON CENTERING FOR ICON-ONLY BUTTONS
 * 
 * Uses flexbox centering for general icon-only buttons.
 * Pages that need bulletproof absolute positioning (like invoice_view.html)
 * should add their own inline styles.
 */

/* Icon-only buttons should center icons with flexbox */
.action-btn,
.icon-action-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    gap: 0 !important;
}

/* Icons inside icon-only buttons - natural size, no expansion */
.action-btn > i:only-child,
.icon-action-btn > i:only-child {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    width: auto !important;
    height: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* iOS-specific - just ensure flexbox works */
@supports (-webkit-touch-callout: none) {
    .action-btn,
    .icon-action-btn {
        display: -webkit-inline-flex !important;
        display: inline-flex !important;
        -webkit-align-items: center !important;
        align-items: center !important;
        -webkit-justify-content: center !important;
        justify-content: center !important;
    }
    
    .action-btn > i:only-child,
    .icon-action-btn > i:only-child {
        display: -webkit-inline-flex !important;
        display: inline-flex !important;
        -webkit-align-items: center !important;
        align-items: center !important;
        -webkit-justify-content: center !important;
        justify-content: center !important;
    }
}