/* Shared Container (all pages) */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
}

/* Tables within containers - always respect container width with horizontal scroll */
.container table,
.table-view table,
table {
    width: 100%;
    box-sizing: border-box;
}

/* Enable horizontal scroll for table views */
.table-view {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    display: block;
}

/* Table wrapper for scrolling on mobile */
.container .table-container,
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile Responsiveness (iPhone/Android) */

/* Ensure text is readable without zooming (min 16px for inputs to prevent iOS zoom) */
input, select, textarea, button {
    font-size: 16px !important;
}

/* Fix iOS Safari default styling */
input[type="text"], input[type="number"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
    -webkit-appearance: none;
    border-radius: 4px;
}

/* Touch Targets: Buttons and interactive elements should be large enough for touch interaction (min 44x44px recommended) */
button, .btn, .header-btn, a.btn, .tab-nav button, .action-buttons button {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 15px;
}

/* Media Queries: Use CSS media queries to adjust layouts for screens smaller than 768px */
@media (max-width: 768px) {
    /* General Layout */
    body {
        overflow-x: hidden;
    }

    /* Shared Container */
    .container {
        padding: 10px;
    }

    .main-content {
        padding: 10px;
    }

    /* Header */
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 15px;
        gap: 10px;
    }

    .app-header-right {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: space-between;
    }

    /* Tab Navigation */
    .tab-nav {
        flex-wrap: wrap;
        width: 100%;
    }

    .tab-nav button {
        flex: 1 1 auto;
        border-radius: 4px !important;
        border: 1px solid #ccc !important;
        margin-bottom: 5px;
        text-align: center;
    }

    /* Two Panel Layout */
    .two-panel-layout {
        grid-template-columns: 1fr !important;
        display: flex;
        flex-direction: column;
    }

    .left-panel, .right-panel {
        width: 100%;
        border-right: none !important;
        border-bottom: 1px solid #ccc;
    }

    /* Filter Grid */
    .filter-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* Summary Row */
    .summary-row {
        grid-template-columns: 1fr 1fr;
    }

    /* Button Groups */
    .btn-group {
        grid-template-columns: 1fr !important;
    }

    /* Horizontal Scrolling: Avoid horizontal scrolling for the main page layout. Use overflow-x: auto for data tables if necessary. */
    .table-container, .table-responsive {
        overflow-x: auto;
        width: 100%;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 15px;
    }

    table {
        width: 100%;
        min-width: 600px; /* Ensure table doesn't squish too much */
    }

    th, td {
        padding: 12px 8px; /* Larger touch targets for table rows */
        white-space: nowrap; /* Prevent text wrapping in cells */
    }

    /* Section Boxes */
    .section-box {
        padding: 10px;
        margin-bottom: 10px;
    }

    /* Forms */
    .form-group {
        margin-bottom: 15px;
    }

    .form-group label {
        margin-bottom: 5px;
    }

    .form-group input, .form-group select, .form-group textarea {
        width: 100%;
    }
}
/* ============================================================
   COLUMN MANAGEMENT - Shared Features
   Resizable, Reorderable, Hideable Columns
============================================================ */

/* Column Settings Button */
.settings-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s;
}

.settings-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

/* Column Settings Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: #667eea;
    margin: 0;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.close-modal:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

.column-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
    cursor: grab;
}

.column-option:last-child {
    border-bottom: none;
}

.column-option label {
    cursor: pointer;
    flex-grow: 1;
}

.column-option.dragging {
    opacity: 0.5;
}

.column-option.drag-over {
    background: #f0f4ff;
    border-left: 3px solid #667eea;
}

.drag-handle {
    cursor: grab;
    color: #999;
    font-weight: bold;
}

.column-option:active .drag-handle {
    cursor: grabbing;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Column Management - Tables with resizable columns */
table:has(.resize-handle) {
    table-layout: fixed;
}

table:has(.resize-handle) th,
table:has(.resize-handle) td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Column Resize Handles */
thead th {
    position: relative;
}

.resize-handle {
    position: absolute;
    right: -4px;
    top: 0;
    bottom: 0;
    width: 10px;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.active {
    background: #667eea;
    border-radius: 2px;
}

/* Column Drag Reorder */
thead tr:first-child th.sortable[draggable="true"] {
    cursor: grab;
}

thead tr:first-child th.sortable[draggable="true"]:active {
    cursor: grabbing;
}

thead th.drag-over {
    border-left: 3px solid #667eea !important;
}

thead th.dragging {
    opacity: 0.4;
}

/* =============================================
   Bulk Editor Toolbar
   ============================================= */
.bulk-edit-toolbar {
    position: sticky;
    top: 0;
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
    display: none;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.bulk-edit-toolbar.active {
    display: block;
}

.bulk-edit-title {
    font-weight: 600;
    color: #856404;
    font-size: 16px;
    margin-bottom: 15px;
}

.bulk-edit-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.bulk-edit-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 10px;
}

.bulk-edit-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bulk-edit-field label {
    font-size: 13px;
    font-weight: 600;
    color: #856404;
}

.bulk-clear-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 500 !important;
    color: #c0392b !important;
    cursor: pointer;
    margin-top: 2px;
}

.bulk-clear-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: #c0392b;
}

.bulk-edit-field select,
.bulk-edit-field input {
    padding: 8px 12px;
    border: 1px solid #ffc107;
    border-radius: 6px;
    font-size: 14px;
}

.bulk-edit-field select {
    max-height: 38px;
}

.bulk-edit-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.btn-apply {
    background: #856404;
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-apply:hover {
    filter: brightness(1.1);
}

.btn-cancel {
    background: transparent;
    color: #856404;
    border: 2px solid #ffc107;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-cancel:hover {
    background: #ffe082;
}

/* Highlighted selected rows */
tbody tr.selected {
    background: #fff9c4 !important;
    outline: 2px solid #ffc107;
}

/* Mobile adjustments for bulk toolbar */
@media (max-width: 768px) {
    .bulk-edit-fields {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .bulk-edit-actions {
        flex-direction: column;
    }

    .btn-apply,
    .btn-cancel {
        width: 100%;
        text-align: center;
    }
}

/* =============================================
   Sort Icons — used by SortManager (sort-manager.js)
   ============================================= */
th .sort-icon {
    font-size: 10px;
    margin-left: 5px;
    opacity: 0.5;
    transition: opacity 0.15s;
}

th.sort-asc .sort-icon,
th.sort-desc .sort-icon {
    opacity: 1;
    color: #667eea;
}

/* =============================================
   Smart Search — used by SmartSearch (smart-search.js)
   ============================================= */
.smart-search-wrap {
    position: relative;
}
.smart-search-wrap input {
    width: 100%;
    padding: 11px 15px 11px 38px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafafa;
}
.smart-search-wrap input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
    background: white;
}
.smart-search-wrap input.nl-active {
    border-color: #667eea;
    background: #f8f5ff;
}
.smart-search-wrap .search-icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    color: #aaa;
    pointer-events: none;
    line-height: 1;
}
.smart-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
    min-height: 0;
}
.smart-tag {
    background: #e8ecff;
    color: #667eea;
    border-radius: 20px;
    padding: 3px 12px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}
.smart-tag-clear {
    background: #f0f0f0;
    color: #888;
    border-radius: 20px;
    padding: 3px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    border: none;
    transition: background 0.15s, color 0.15s;
}
.smart-tag-clear:hover {
    background: #ffd6d6;
    color: #c00;
}
.smart-search-summary {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    min-height: 14px;
}
/* Standalone smart-search bar (for pages without filter-group wrap) */
.smart-search-bar {
    background: white;
    padding: 14px 20px;
    border-radius: 8px;
    margin-bottom: 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.smart-search-bar label {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}
@media (max-width: 768px) {
    .smart-search-wrap input {
        font-size: 16px; /* prevent iOS zoom */
    }
}