/* Custom Styles for Flask Auth System */

/* General */
.card {
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.btn {
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.btn:hover {
    transform: translateY(-1px);
}

/* Ensure button colors are visible */
.btn-primary {
    background-color: #007bff !important;
    border-color: #007bff !important;
    color: white !important;
}

.btn-secondary {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: white !important;
}

.btn-success {
    background-color: #28a745 !important;
    border-color: #28a745 !important;
    color: white !important;
}

.btn-danger {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: white !important;
}

.btn-warning {
    background-color: #ffc107 !important;
    border-color: #ffc107 !important;
    color: #212529 !important;
}

.btn-info {
    background-color: #17a2b8 !important;
    border-color: #17a2b8 !important;
    color: white !important;
}

.btn-outline-primary {
    color: #007bff !important;
    border-color: #007bff !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-primary:hover {
    color: white !important;
    background-color: #007bff !important;
    border-color: #007bff !important;
}

.btn-outline-secondary {
    color: #6c757d !important;
    border-color: #6c757d !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-secondary:hover {
    color: white !important;
    background-color: #6c757d !important;
    border-color: #6c757d !important;
}

.btn-outline-success {
    color: #28a745 !important;
    border-color: #28a745 !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-success:hover {
    color: white !important;
    background-color: #28a745 !important;
    border-color: #28a745 !important;
}

.btn-outline-danger {
    color: #dc3545 !important;
    border-color: #dc3545 !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-danger:hover {
    color: white !important;
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
}

.btn-outline-warning {
    color: #856404 !important;
    border-color: #ffc107 !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-warning:hover {
    color: #212529 !important;
    background-color: #ffc107 !important;
    border-color: #ffc107 !important;
}

.btn-outline-info {
    color: #17a2b8 !important;
    border-color: #17a2b8 !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-info:hover {
    color: white !important;
    background-color: #17a2b8 !important;
    border-color: #17a2b8 !important;
}

.btn-outline-dark {
    color: #343a40 !important;
    border-color: #343a40 !important;
    background-color: transparent !important;
    border-width: 2px !important;
}

.btn-outline-dark:hover {
    color: white !important;
    background-color: #343a40 !important;
    border-color: #343a40 !important;
}

/* Ensure all buttons have visible borders - DO NOT change sizing */
.btn {
    border-width: 1px !important;
    border-style: solid !important;
}

/* Compact action buttons (view, edit, delete icons in tables) */
.btn-group-sm > .btn,
.btn-sm {
    padding: 0.15rem 0.35rem;
    font-size: 0.875rem;
    border-radius: 0.2rem;
}

/* Icon-only buttons should be compact and square */
.btn-group .btn:has(i.bi:only-child),
.btn:has(> i.bi:only-child) {
    padding: 0.25rem 0.4rem;
}

/* Form styles */
.form-control {
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    transition: all 0.2s ease;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.1);
}

.form-label {
    font-weight: 500;
    color: #495057;
}

/* Login/Register pages */
.auth-container {
    min-height: calc(100vh - 200px);
    display: flex;
    align-items: center;
}

.auth-card {
    max-width: 400px;
    margin: 0 auto;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.auth-divider {
    text-align: center;
    margin: 1.5rem 0;
    position: relative;
}

.auth-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e0e0e0;
}

.auth-divider span {
    background: white;
    padding: 0 1rem;
    color: #666;
    font-size: 0.9rem;
}

/* Dashboard styles */
.stats-card {
    background: linear-gradient(135deg, var(--primary-color), color-mix(in srgb, var(--primary-color) 80%, white));
    color: white;
    border: none;
}

.stats-card .card-body {
    position: relative;
    overflow: hidden;
}

.stats-card .stats-icon {
    font-size: 3rem;
    opacity: 0.2;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

.stats-number {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
}

.stats-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin: 0;
}

/* Table styles */
.table {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.table thead th {
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    font-weight: 600;
    color: #495057;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

/* Badge styles */
.badge {
    font-size: 0.8rem;
    padding: 0.4em 0.8em;
    font-weight: 500;
    border-radius: 0.375rem;
}

/* Support both Bootstrap 4 and 5 badge styles */
.badge-success,
.bg-success.badge {
    background-color: #28a745 !important;
    color: white !important;
}

.badge-danger,
.bg-danger.badge {
    background-color: #dc3545 !important;
    color: white !important;
}

.badge-warning,
.bg-warning.badge {
    background-color: #ffc107 !important;
    color: #212529 !important;
}

.badge-info,
.bg-info.badge {
    background-color: #17a2b8 !important;
    color: white !important;
}

.badge-primary,
.bg-primary.badge {
    background-color: #007bff !important;
    color: white !important;
}

.badge-secondary,
.bg-secondary.badge {
    background-color: #6c757d !important;
    color: white !important;
}

/* Profile page */
.profile-header {
    background: linear-gradient(135deg, var(--primary-color), color-mix(in srgb, var(--primary-color) 80%, white));
    color: white;
    border-radius: 12px 12px 0 0;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border: 4px solid white;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
}

/* Settings page */
.settings-nav {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.settings-nav .nav-link {
    color: #666;
    border: none;
    border-radius: 0;
    padding: 1rem 1.5rem;
    transition: all 0.2s ease;
}

.settings-nav .nav-link:hover {
    background: #f8f9fa;
    color: var(--primary-color);
}

.settings-nav .nav-link.active {
    background: var(--primary-color);
    color: white;
}

/* Timeline styles for audit logs */
.timeline {
    position: relative;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e0e0e0;
}

.timeline-item {
    position: relative;
    padding-left: 3rem;
    margin-bottom: 1.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0.5rem;
    width: 1rem;
    height: 1rem;
    background: var(--primary-color);
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 0 0 3px #e0e0e0;
}

.timeline-content {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Mobile-First Responsive Design */

/* Touch-friendly elements - minimum 44x44px touch targets */
@media (max-width: 768px) {
    .btn, .nav-link, .dropdown-item, a.list-group-item {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-link, .dropdown-item {
        padding: 0.75rem 1rem;
    }
}

/* Improved navbar for mobile */
@media (max-width: 991px) {
    .navbar-collapse {
        max-height: 70vh;
        overflow-y: auto;
    }
}

/* Better dropdown behavior on mobile */
@media (max-width: 991px) {
    .navbar-nav .dropdown-menu {
        border: none;
        background-color: rgba(0, 0, 0, 0.05);
        padding-left: 1rem;
        box-shadow: none;
    }

    .navbar-dark .dropdown-menu {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .navbar-nav .dropdown-item {
        color: inherit;
        padding: 0.75rem 1rem;
    }

    /* Ensure dropdowns are visible when expanded */
    .navbar-nav .dropdown-menu.show {
        display: block;
        position: static;
        float: none;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
        max-width: 100%;
    }

    .auth-card {
        margin: 1rem;
        max-width: 100%;
    }

    .stats-card .stats-number {
        font-size: 1.5rem;
    }

    /* Larger touch targets for buttons on mobile */
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 1rem;
        min-height: 44px;
    }

    .btn-sm {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-height: 38px;
    }

    /* Improve card spacing */
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Stack button groups vertically on mobile */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .btn-group > .btn {
        width: 100%;
        border-radius: 0.375rem !important;
        margin-bottom: 0.5rem;
    }

    .btn-group > .btn:last-child {
        margin-bottom: 0;
    }

    .table-responsive {
        font-size: 0.9rem;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent horizontal overflow */
    .row {
        margin-left: 0;
        margin-right: 0;
    }

    .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
    .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Fix modal sizing on mobile */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 1rem;
    }

    /* Adjust button groups on mobile */
    .btn-group-vertical .btn {
        margin-bottom: 0.5rem;
    }

    /* Improve table display on mobile - card-style layout */
    .table-responsive .table {
        border: 0;
    }

    .table-responsive .table thead {
        display: none;
    }

    .table-responsive .table,
    .table-responsive .table tbody,
    .table-responsive .table tr,
    .table-responsive .table td {
        display: block;
        width: 100%;
    }

    .table-responsive .table tr {
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        margin-bottom: 1rem;
        padding: 0.75rem;
        background: white;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    .table-responsive .table td {
        border: none;
        position: relative;
        padding-left: 50% !important;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .table-responsive .table td:before {
        content: attr(data-label);
        position: absolute;
        left: 0.75rem;
        width: 45%;
        white-space: normal;
        font-weight: 600;
        color: #495057;
    }

    .table-responsive .table td:first-child {
        border-top-left-radius: 0.5rem;
        border-top-right-radius: 0.5rem;
    }

    .table-responsive .table td:last-child {
        border-bottom-left-radius: 0.5rem;
        border-bottom-right-radius: 0.5rem;
    }

    /* Forms on mobile */
    .form-control, .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
        padding: 0.625rem 0.875rem;
    }

    .form-label {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    /* Improved alert messages */
    .alert {
        font-size: 0.95rem;
        padding: 1rem;
    }

    /* Better footer on mobile */
    footer.bg-dark {
        padding: 2rem 0 1rem;
    }

    footer .col-md-6 {
        text-align: center !important;
        margin-bottom: 1rem;
    }

    footer .row > div:last-child {
        margin-bottom: 0;
    }
}

@media (max-width: 576px) {
    .container {
        padding: 0 0.5rem;
    }

    /* Stack navigation items vertically on very small screens */
    .navbar-nav {
        text-align: center;
    }

    /* Reduce padding for small screens */
    .card-body {
        padding: 1rem;
    }

    /* Adjust footer layout */
    .footer .row .col-md-6 {
        text-align: center !important;
        margin-bottom: 1rem;
    }
}

/* ==========================================
   PAGE HEADERS & ACTION BUTTONS MOBILE
   ========================================== */

@media (max-width: 768px) {
    /* Page header optimization */
    .container h1, .container h2 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    .container h1 + p, .container h2 + p {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    /* Action button groups at top of pages */
    .mb-3 > .btn,
    .mb-3 > a.btn,
    .d-flex.gap-2 > .btn,
    .d-flex.gap-2 > a.btn {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
    }

    /* Make button groups wrap and stack better */
    .d-flex.gap-2,
    .d-flex.flex-wrap {
        gap: 0.5rem !important;
    }

    .mb-3 .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }

    .mb-3 .btn-group .btn {
        width: 100%;
        border-radius: 0.375rem !important;
    }

    /* Stats cards in rows */
    .row > [class*="col-"] .card {
        margin-bottom: 0.75rem;
    }

    .row > [class*="col-"] .card .card-body {
        padding: 0.75rem;
    }

    .row > [class*="col-"] .card h3,
    .row > [class*="col-"] .card h4,
    .row > [class*="col-"] .card h5 {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }
}

/* ==========================================
   DATATABLES MOBILE OPTIMIZATION
   ========================================== */

@media (max-width: 768px) {
    /* DataTable wrapper */
    .dataTables_wrapper {
        font-size: 0.9rem;
    }

    /* Top controls (length, buttons) */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        margin-bottom: 0.75rem;
    }

    .dataTables_wrapper .dataTables_length select {
        min-height: 44px;
        font-size: 16px;
        padding: 0.5rem;
    }

    .dataTables_wrapper .dataTables_filter input {
        min-height: 44px;
        font-size: 16px;
        padding: 0.5rem;
        width: 100%;
        max-width: none;
    }

    /* DataTable buttons */
    .dt-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .dt-buttons .btn {
        min-height: 44px;
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
        flex: 1;
        min-width: 120px;
    }

    /* Pagination */
    .dataTables_wrapper .dataTables_paginate {
        margin-top: 1rem;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .dataTables_wrapper .dataTables_paginate .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
    }

    /* Info text */
    .dataTables_wrapper .dataTables_info {
        font-size: 0.85rem;
        text-align: center;
        margin-top: 0.75rem;
    }
}

/* ==========================================
   FILTER FORMS MOBILE OPTIMIZATION
   ========================================== */

@media (max-width: 768px) {
    /* Filter row with selects */
    .row.mb-3 select.form-select,
    .row.mb-3 input.form-control {
        font-size: 16px;
        min-height: 44px;
        padding: 0.625rem 0.875rem;
        margin-bottom: 0.5rem;
    }

    /* Filter labels */
    .row.mb-3 label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
        font-weight: 600;
    }

    /* Make filter columns stack */
    .row.mb-3 > [class*="col-"] {
        margin-bottom: 0.75rem;
    }
}

/* ==========================================
   CARD IMPROVEMENTS FOR MOBILE
   ========================================== */

@media (max-width: 768px) {
    /* Card headers */
    .card-header {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    .card-header h5,
    .card-header h6 {
        font-size: 1rem;
        margin-bottom: 0;
    }

    /* Card with action buttons in header */
    .card-header .btn-group {
        margin-top: 0.5rem;
    }

    /* List groups in cards */
    .list-group-item {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    /* Badge in cards */
    .card .badge {
        font-size: 0.75rem;
        padding: 0.35em 0.65em;
    }
}

/* ==========================================
   CHARTS & GRAPHS MOBILE OPTIMIZATION
   ========================================== */

@media (max-width: 768px) {
    /* Chart containers */
    .chart-container,
    canvas {
        max-width: 100%;
        height: auto !important;
    }

    /* Make charts responsive */
    .chart-wrapper {
        position: relative;
        padding-bottom: 56.25%; /* 16:9 aspect ratio */
        height: 0;
        overflow: hidden;
    }

    .chart-wrapper canvas {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

/* ==========================================
   TABS MOBILE OPTIMIZATION
   ========================================== */

@media (max-width: 768px) {
    /* Nav tabs */
    .nav-tabs {
        border-bottom: 2px solid #dee2e6;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-link {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        white-space: nowrap;
        border-radius: 0;
    }

    .nav-tabs .nav-link.active {
        border-bottom: 3px solid var(--primary-color);
        background-color: transparent;
    }

    /* Tab content */
    .tab-content {
        padding: 1rem 0.5rem;
    }
}

/* ==========================================
   PROGRESS BARS & METERS MOBILE
   ========================================== */

@media (max-width: 768px) {
    .progress {
        height: 28px;
        font-size: 0.9rem;
    }

    .progress-bar {
        line-height: 28px;
    }

    /* Meter/gauge displays */
    .meter,
    .gauge {
        font-size: 0.9rem;
    }
}

/* ==========================================
   INFO BOXES & ALERTS MOBILE
   ========================================== */

@media (max-width: 768px) {
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    .alert .btn {
        margin-top: 0.5rem;
        width: 100%;
    }

    .alert-heading {
        font-size: 1.1rem;
    }
}

/* ==========================================
   DROPDOWN MENUS MOBILE
   ========================================== */

@media (max-width: 768px) {
    .dropdown-menu {
        min-width: 200px;
        max-width: calc(100vw - 2rem);
        font-size: 0.9rem;
    }

    .dropdown-item {
        padding: 0.75rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .dropdown-divider {
        margin: 0.5rem 0;
    }
}

/* ==========================================
   BREADCRUMB MOBILE
   ========================================== */

@media (max-width: 768px) {
    .breadcrumb {
        font-size: 0.85rem;
        padding: 0.5rem 0;
        margin-bottom: 0.75rem;
        flex-wrap: wrap;
    }

    .breadcrumb-item {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ==========================================
   TOOLTIPS & POPOVERS MOBILE
   ========================================== */

@media (max-width: 768px) {
    .tooltip {
        font-size: 0.85rem;
    }

    .popover {
        max-width: calc(100vw - 2rem);
        font-size: 0.9rem;
    }
}

/* ==========================================
   ACCORDION MOBILE
   ========================================== */

@media (max-width: 768px) {
    .accordion-button {
        font-size: 0.95rem;
        padding: 0.875rem 1rem;
        min-height: 56px;
    }

    .accordion-body {
        padding: 1rem;
        font-size: 0.9rem;
    }
}

/* ==========================================
   OFFCANVAS MOBILE ADJUSTMENTS
   ========================================== */

@media (max-width: 768px) {
    .offcanvas {
        max-width: 85vw;
    }

    .offcanvas-header {
        padding: 1rem;
    }

    .offcanvas-body {
        padding: 1rem;
    }
}

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   ADDITIONAL MOBILE OPTIMIZATIONS
   ============================================ */

/* Priority Cards - Touch-friendly */
@media (max-width: 768px) {
    .card.border-danger,
    .card.border-warning,
    .card.border-success,
    .card.border-info {
        min-height: 100px;
        margin-bottom: 1rem;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    }

    .card.border-danger:active,
    .card.border-warning:active,
    .card.border-success:active,
    .card.border-info:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Filter Sections */
@media (max-width: 768px) {
    .filter-section,
    .card-body > div[class*="mb-"] {
        margin-bottom: 1.5rem !important;
    }

    .card-body label {
        font-size: 0.95rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }
}

/* Input Groups with Buttons */
@media (max-width: 768px) {
    .input-group {
        flex-wrap: nowrap;
    }

    .input-group .form-control {
        min-height: 44px;
        font-size: 16px;
    }

    .input-group .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 1rem;
        white-space: nowrap;
    }

    .input-group-text {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
    }
}

/* Select Dropdowns - Enhanced */
@media (max-width: 768px) {
    select.form-select,
    select.form-control {
        min-height: 44px;
        font-size: 16px;
        padding: 0.625rem 2.5rem 0.625rem 0.875rem;
        background-size: 16px 12px;
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
    }
}

/* Textarea - Better mobile experience */
@media (max-width: 768px) {
    textarea.form-control {
        min-height: 120px;
        font-size: 16px;
        padding: 0.75rem;
        resize: vertical;
    }
}

/* Badge Groups */
@media (max-width: 768px) {
    .badge {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
        white-space: normal;
        word-wrap: break-word;
    }
}

/* Progress Bars - More visible */
@media (max-width: 768px) {
    .progress {
        height: 1.5rem;
        font-size: 0.875rem;
        border-radius: 0.5rem;
    }

    .progress-bar {
        line-height: 1.5rem;
    }
}

/* List Groups - Touch-friendly */
@media (max-width: 768px) {
    .list-group-item {
        min-height: 44px;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }

    .list-group-item-action {
        -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    }

    .list-group-item-action:active {
        background-color: rgba(0,0,0,0.05);
    }
}

/* Checkboxes and Radios - Larger touch targets */
@media (max-width: 768px) {
    .form-check {
        min-height: 44px;
        padding-left: 2.5rem;
        display: flex;
        align-items: center;
    }

    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
        margin-left: -2.5rem;
        margin-top: 0;
    }

    .form-check-label {
        font-size: 1rem;
        line-height: 1.5;
        padding-left: 0.5rem;
    }
}

/* Switch Toggles - Larger */
@media (max-width: 768px) {
    .form-switch .form-check-input {
        width: 3rem;
        height: 1.75rem;
        background-size: contain;
    }
}

/* Spacing for Mobile Forms */
@media (max-width: 768px) {
    .mb-3,
    .my-3 {
        margin-bottom: 1.5rem !important;
    }

    .mt-3,
    .my-3 {
        margin-top: 1.5rem !important;
    }
}

/* Icon Buttons - Consistent sizing */
@media (max-width: 768px) {
    .btn-icon,
    .btn[class*="btn-outline"] > i:only-child,
    .btn > i:only-child {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Status Indicators - More visible */
@media (max-width: 768px) {
    .status-indicator,
    .online-indicator,
    .offline-indicator {
        width: 12px;
        height: 12px;
        border-radius: 50%;
        display: inline-block;
    }
}

/* Collapsible Sections - Better mobile UX */
@media (max-width: 768px) {
    .collapse.show,
    .collapsing {
        transition: height 0.3s ease;
    }

    [data-bs-toggle="collapse"] {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 0.75rem 1rem;
    }
}

/* File Upload Areas */
@media (max-width: 768px) {
    .file-upload-area,
    input[type="file"] {
        min-height: 100px;
        font-size: 16px;
        padding: 1rem;
    }

    .custom-file-label {
        min-height: 44px;
        padding: 0.625rem 0.875rem;
        font-size: 16px;
    }
}

/* Sticky Elements on Mobile */
@media (max-width: 768px) {
    .sticky-top {
        top: 56px; /* Account for mobile navbar height */
    }
}

/* Horizontal Scrolling Tables - Better indicators */
@media (max-width: 768px) {
    .table-responsive {
        position: relative;
    }

    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to left, rgba(0,0,0,0.05), transparent);
        pointer-events: none;
    }
}

/* Better Touch Feedback */
@media (max-width: 768px) {
    button,
    a,
    .btn,
    .nav-link,
    .dropdown-item,
    [role="button"] {
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        touch-action: manipulation;
    }
}

/* Prevent zoom on double-tap */
@media (max-width: 768px) {
    * {
        touch-action: manipulation;
    }
}

/* ============================================
   DATATABLE MOBILE OPTIMIZATIONS
   ============================================ */

/* Mobile-specific DataTable styling */
@media (max-width: 768px) {
    /* Force table to be responsive by hiding standard table layout */
    .table-responsive .dataTable {
        width: 100% !important;
    }

    /* Hide table header on mobile */
    .table-responsive .dataTable thead {
        display: none !important;
    }

    /* Make each row a card */
    .table-responsive .dataTable tbody tr {
        display: block !important;
        margin-bottom: 1rem !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 0.5rem !important;
        padding: 1rem !important;
        background: white !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.08) !important;
    }

    /* Style each cell as a row */
    .table-responsive .dataTable tbody td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.75rem 0 !important;
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        min-height: 44px !important;
    }

    .table-responsive .dataTable tbody td:last-child {
        border-bottom: none !important;
    }

    /* Add labels before each cell using data attributes */
    .table-responsive .dataTable tbody td:before {
        content: attr(data-label) !important;
        font-weight: 600 !important;
        flex-shrink: 0 !important;
        width: 40% !important;
        color: #495057 !important;
        font-size: 0.9rem !important;
        margin-right: 1rem !important;
    }

    /* Right-align the data part */
    .table-responsive .dataTable tbody td > * {
        text-align: right !important;
        flex: 1 !important;
        max-width: 55% !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* Fix for nested elements (badges, links) */
    .table-responsive .dataTable tbody td .badge,
    .table-responsive .dataTable tbody td a,
    .table-responsive .dataTable tbody td span {
        display: inline-block !important;
        max-width: 100% !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }

    /* Ensure proper spacing and no overlap */
    .table-responsive .dataTable tbody td {
        flex-wrap: nowrap !important;
        gap: 0.5rem !important;
    }

    /* Button groups in action column */
    .table-responsive .dataTable tbody td .btn-group {
        display: flex !important;
        gap: 0.5rem !important;
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
    }

    .table-responsive .dataTable tbody td .btn-group .btn {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 0.5rem !important;
    }

    /* DataTables controls - stack vertically */
    .dataTables_wrapper .row {
        margin: 0 !important;
    }

    .dataTables_wrapper .col-sm-12 {
        padding: 0.5rem 0 !important;
    }

    /* Search input */
    .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        margin-bottom: 1rem !important;
    }

    .dataTables_wrapper .dataTables_filter label {
        width: 100% !important;
        display: block !important;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        max-width: none !important;
        min-height: 44px !important;
        font-size: 16px !important;
        margin-left: 0 !important;
        margin-top: 0.5rem !important;
        display: block !important;
    }

    /* Entries dropdown */
    .dataTables_wrapper .dataTables_length {
        margin-bottom: 1rem !important;
    }

    .dataTables_wrapper .dataTables_length label {
        display: flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
        flex-wrap: wrap !important;
    }

    .dataTables_wrapper .dataTables_length select {
        min-height: 44px !important;
        font-size: 16px !important;
        padding: 0.5rem !important;
        width: auto !important;
        min-width: 80px !important;
    }

    /* Info text */
    .dataTables_wrapper .dataTables_info {
        font-size: 0.9rem !important;
        padding: 1rem 0 !important;
        text-align: center !important;
    }

    /* Pagination */
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        padding: 1rem 0 !important;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: center !important;
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
    }

    .dataTables_wrapper .dataTables_paginate .page-link {
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1rem !important;
    }

    /* Buttons (Export, etc.) */
    .dataTables_wrapper .dt-buttons {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        margin-bottom: 1rem !important;
    }

    .dataTables_wrapper .dt-buttons .btn {
        min-height: 44px !important;
        flex: 1 1 auto !important;
        min-width: 120px !important;
    }

    /* Processing indicator */
    .dataTables_wrapper .dataTables_processing {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        background: white !important;
        padding: 2rem !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
        z-index: 9999 !important;
    }
}

/* Filter cards on mobile */
@media (max-width: 768px) {
    .filter-card .row > div {
        margin-bottom: 1rem !important;
    }

    .filter-card .row > div:last-child {
        margin-bottom: 0 !important;
    }

    .filter-card .btn {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }

    .filter-card .btn:last-child {
        margin-bottom: 0 !important;
    }
}

/* Ticket-specific mobile styling */
@media (max-width: 768px) {
    .ticket-row {
        cursor: pointer !important;
        transition: transform 0.2s ease !important;
    }

    .ticket-row:active {
        transform: scale(0.98) !important;
    }

    /* Badges should wrap properly */
    .badge {
        white-space: normal !important;
        word-wrap: break-word !important;
        display: inline-block !important;
    }

    /* Links should be touch-friendly */
    .table-responsive a {
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        padding: 0.25rem 0 !important;
    }
}

/* ============================================
   PROTOCOL CREATE PAGE MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    /* Signature canvas - larger on mobile */
    .signature-pad,
    canvas[id*="signature"],
    .signature-canvas {
        min-height: 200px !important;
        height: 200px !important;
        width: 100% !important;
        border: 2px solid #dee2e6 !important;
        border-radius: 0.5rem !important;
        touch-action: none !important;
    }

    /* Signature containers */
    .signature-container,
    .signature-field {
        margin-bottom: 1.5rem !important;
    }

    /* Bottom action buttons - stack vertically */
    .protocol-actions,
    .fixed-bottom .container-fluid,
    .fixed-bottom .d-flex {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .protocol-actions .btn,
    .fixed-bottom .btn {
        width: 100% !important;
        min-height: 50px !important;
        font-size: 1rem !important;
        padding: 0.75rem 1rem !important;
        margin: 0 !important;
    }

    /* PDF Generate button - prominent */
    .btn-success[id*="generate"],
    .btn-success[id*="pdf"],
    button:contains("PDF generieren") {
        order: -1 !important;
        background: #28a745 !important;
        font-weight: 600 !important;
    }

    /* Step indicators - responsive */
    .stepper,
    .protocol-steps {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .stepper .step,
    .protocol-steps .step {
        min-width: 70px !important;
        font-size: 0.85rem !important;
    }

    /* Accordion sections */
    .accordion-button {
        min-height: 56px !important;
        font-size: 1rem !important;
        padding: 1rem !important;
    }

    /* Photo upload areas */
    .photo-upload-area,
    .dropzone {
        min-height: 150px !important;
        padding: 1.5rem !important;
    }

    .photo-preview {
        width: calc(50% - 0.5rem) !important;
        margin-bottom: 1rem !important;
    }

    /* Date/Time inputs */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        min-height: 44px !important;
        font-size: 16px !important;
        padding: 0.625rem 0.875rem !important;
    }
}

/* Signature pad specific fixes */
@media (max-width: 768px) {
    /* SignaturePad library overrides */
    .signature-pad-canvas,
    .m-signature-pad,
    .m-signature-pad--body {
        min-height: 200px !important;
        height: 200px !important;
    }

    .m-signature-pad--body canvas {
        min-height: 200px !important;
        height: 200px !important;
        width: 100% !important;
    }

    /* Clear signature button */
    .signature-pad-clear,
    .btn-clear-signature {
        min-height: 44px !important;
        width: 100% !important;
        margin-top: 0.5rem !important;
    }

    /* Signature labels */
    .signature-label,
    label[for*="signature"] {
        font-size: 1rem !important;
        font-weight: 600 !important;
        margin-bottom: 0.75rem !important;
        display: block !important;
    }
}

/* Success animations */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Custom scrollbar */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) #f1f1f1;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--primary-color) 80%, black);
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .bg-light {
        background-color: #1a1a1a !important;
        color: #e0e0e0;
    }
    
    .card {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }
    
    .table {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }
    
    .table thead th {
        background-color: #3d3d3d;
        color: #e0e0e0;
    }
    
    .form-control {
        background-color: #3d3d3d;
        border-color: #4d4d4d;
        color: #e0e0e0;
    }
    
    .form-control:focus {
        background-color: #3d3d3d;
        border-color: var(--primary-color);
        color: #e0e0e0;
    }
}