/* =====================================================
   WexSales Styles
   Font: Red Hat Display
   Theme: White background, Blue-Cyan accents
   ===================================================== */

/* CSS Variables */
:root {
    --primary-color: #0EA5E9;
    --primary-dark: #0284C7;
    --primary-light: #38BDF8;
    --secondary-color: #06B6D4;
    --accent-gradient: linear-gradient(135deg, #0EA5E9 0%, #06B6D4 100%);

    --bg-white: #FFFFFF;
    --bg-light: #F8FAFC;
    --bg-gray: #F1F5F9;

    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;

    --border-color: #E2E8F0;
    --border-light: #F1F5F9;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    --transition: all 0.2s ease;

    --header-height: 64px;

    --success-bg: #F0FDF4;
    --success-color: #16A34A;
    --success-border: #BBF7D0;
    --error-bg: #FEF2F2;
    --error-color: #DC2626;
    --error-border: #FECACA;
    --danger-color: #EF4444;
    --danger-dark: #DC2626;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Disable pull-to-refresh and the overscroll rubberband/glow */
    overscroll-behavior: none;
}

body {
    font-family: 'Red Hat Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-white);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overscroll-behavior: none;
}

/* =====================================================
   LOGIN PAGE
   ===================================================== */

.login-page {
    background: var(--bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-card {
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 40px 32px;
}

.login-logo {
    margin-bottom: 24px;
}

.login-logo img {
    max-width: 240px;
    height: auto;
}

.login-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form {
    text-align: left;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.error-message {
    background: var(--error-bg);
    color: var(--error-color);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid var(--error-border);
}

.success-message {
    background: var(--success-bg);
    color: var(--success-color);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid var(--success-border);
}

/* Forgot Password */
.forgot-password-link {
    text-align: center;
    margin-top: 16px;
}

.forgot-password-link a {
    color: var(--primary-color, #0EA5E9);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
}

.forgot-password-link a:hover {
    color: var(--primary-dark, #0284C7);
    text-decoration: underline;
}

.forgot-instructions {
    font-size: 0.9rem;
    color: var(--text-secondary, #64748B);
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-card {
    background: #fff;
    border-radius: 12px;
    padding: 32px 36px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.modal-message {
    font-size: 1rem;
    color: var(--text-primary, #1E293B);
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-card .btn {
    min-width: 120px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--bg-gray);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-dark);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.login-footer {
    margin-top: 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* =====================================================
   APP HEADER
   ===================================================== */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    height: 60px;
    width: auto;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: var(--transition);
}

.user-menu-btn:hover {
    background: var(--bg-gray);
    border-color: var(--primary-light);
}

.user-icon {
    display: flex;
    align-items: center;
    color: var(--primary-color);
}

.user-name {
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-arrow {
    color: var(--text-muted);
    transition: transform 0.2s;
}

.user-menu.active .dropdown-arrow {
    transform: rotate(180deg);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
}

.user-menu.active .user-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

/* Hard Refresh is only useful in the installed/mobile PWA (no browser
   refresh button there) — hidden on desktop. */
.dropdown-item-mobile {
    display: none;
}

/* Override the UA [hidden] rule, which .dropdown-item { display:flex }
   would otherwise win against — lets JS toggle visibility via the attribute. */
.dropdown-item[hidden] {
    display: none;
}

/* iOS "Add to Home Screen" instructions modal */
.install-intro {
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.install-steps {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.install-step-icon {
    vertical-align: middle;
    margin: 0 2px;
    color: var(--primary-color);
}

.dropdown-item:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.dropdown-item:hover {
    background: var(--bg-light);
    color: var(--primary-color);
}

.dropdown-item svg {
    color: var(--text-secondary);
}

.dropdown-item:hover svg {
    color: var(--primary-color);
}

/* =====================================================
   APP MAIN
   ===================================================== */

.app-main {
    padding-top: var(--header-height);
    min-height: 100vh;
    background: var(--bg-light);
}

/* Filters Section */
.filters-section {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    position: sticky;
    top: var(--header-height);
    z-index: 50;
}

.filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    max-width: 1400px;
    margin: 0 auto;
}

.filter-group {
    flex: 1;
    min-width: 180px;
}

.filter-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.filter-select {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.9rem;
    font-family: inherit;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.search-group {
    flex: 1.5;
    min-width: 250px;
}

.search-wrapper {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    font-size: 0.9rem;
    font-family: inherit;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    color: var(--text-primary);
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.btn-reset {
    padding: 10px 16px;
    white-space: nowrap;
}

.collapsible-filters {
    display: contents;
}

/* Mobile-only filter controls — hidden on desktop, shown at <=768px */
.filter-open-btn,
.filter-reset-mobile,
.filter-pills,
.filter-sheet-header,
.filter-sheet-backdrop,
.choice-pills {
    display: none;
}

/* Products Section */
.products-section {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    min-height: 400px;
}

.products-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.products-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.products-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    background: var(--bg-gray);
    padding: 4px 12px;
    border-radius: 20px;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* Product Card */
.product-card {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.product-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.product-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.product-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.product-price {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary-dark);
    white-space: nowrap;
    margin-left: 12px;
}

.product-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-light);
    padding: 2px 8px;
    border-radius: 4px;
    flex-shrink: 0;
}

.product-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.product-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-light);
    color: var(--text-secondary);
}

.product-badge.badge-application {
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary-dark);
}

.product-badge.badge-range {
    background: rgba(6, 182, 212, 0.1);
    color: #0891B2;
}

.product-badge.badge-state {
    background: var(--bg-gray);
    color: var(--text-secondary);
}

.product-badge.badge-segment {
    background: rgba(139, 92, 246, 0.1);
    color: #7C3AED;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* No Results */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.no-results svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-results p {
    font-size: 1rem;
}

/* =====================================================
   MODAL
   ===================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(20px);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-sm {
    max-width: 450px;
}

.modal-lg {
    max-width: 900px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-light);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-subtitle {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.modal-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary-dark);
}

.modal-badge.badge-state {
    background: var(--bg-gray);
    color: var(--text-secondary);
}

.modal-close {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

/* Product detail info */
.product-detail-info {
    display: flex;
    gap: 16px;
    margin-top: 8px;
}

.detail-item {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.detail-item strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-light);
}

.tab-btn {
    padding: 14px 20px;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-gradient);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.tab-content {
    display: none;
}

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

.tab-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.data-table th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-light);
}

.data-table td {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.data-table tbody tr:hover {
    background: var(--bg-light);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

/* =====================================================
   ADMIN PAGE STYLES
   ===================================================== */

.admin-section {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.admin-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Users Table */
.users-table-wrapper {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th,
.users-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.users-table th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-light);
}

.users-table td {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.users-table tbody tr:hover {
    background: var(--bg-light);
}

.users-table tbody tr:last-child td {
    border-bottom: none;
}

/* Email column */
.email-cell {
    font-size: 0.85rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Permission Badges */
.perm-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    margin: 2px;
}

.perm-badge.perm-on {
    background: var(--success-bg);
    color: var(--success-color);
    border: 1px solid var(--success-border);
}

.perm-badge.perm-off {
    background: var(--bg-gray);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.status-badge.active {
    background: var(--success-bg);
    color: var(--success-color);
}

.status-badge.inactive {
    background: var(--error-bg);
    color: var(--error-color);
}

.admin-badge {
    background: rgba(139, 92, 246, 0.1);
    color: #7C3AED;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
}

.action-btns {
    display: flex;
    gap: 8px;
}

/* Checkbox group for admin form */
.checkbox-group {
    margin-bottom: 16px;
}

.checkbox-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.checkbox-item:hover {
    background: var(--bg-gray);
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.checkbox-item span {
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* =====================================================
   RESPONSIVE
   ===================================================== */

@media (max-width: 1024px) {
    .filters-container {
        gap: 12px;
    }

    .filter-group {
        min-width: 160px;
    }

    .search-group {
        min-width: 200px;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 0 16px;
    }

    .header-title {
        font-size: 1.1rem;
    }

    .user-name {
        display: none;
    }

    .dropdown-item-mobile {
        display: flex;
    }

    .filters-section {
        padding: 12px 16px;
    }

    /* Sticky toolbar: search box + filter button + reset button on one row */
    .filters-container {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 8px;
    }

    .search-group {
        flex: 1;
        min-width: 0;
    }

    /* Hide the "Search" label on mobile for a clean toolbar */
    .search-group label {
        display: none;
    }

    /* Filter button — opens the bottom sheet */
    .filter-open-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 44px;
        padding: 0 14px;
        flex: 0 0 auto;
        font-family: inherit;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-primary);
        background: var(--bg-white);
        border: 1.5px solid var(--border-color);
        border-radius: var(--radius-md);
        cursor: pointer;
        transition: var(--transition);
    }

    .filter-open-btn:active {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }

    /* Reset button in the toolbar (icon only) */
    .filter-reset-mobile {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        flex: 0 0 auto;
        color: var(--text-secondary);
        background: var(--bg-white);
        border: 1.5px solid var(--border-color);
        border-radius: var(--radius-md);
        cursor: pointer;
        transition: var(--transition);
    }

    .filter-reset-mobile:active {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }

    /* Active filter pills below the toolbar */
    .filter-pills {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 10px;
    }

    .filter-pill {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 10px;
        font-size: 0.8rem;
        font-weight: 500;
        color: var(--primary-dark);
        background: var(--bg-gray);
        border: 1px solid var(--border-color);
        border-radius: 999px;
        max-width: 100%;
    }

    .filter-pill span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .filter-pill-remove {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        flex: 0 0 auto;
        padding: 0;
        font-size: 1rem;
        line-height: 1;
        color: var(--primary-dark);
        background: none;
        border: none;
        border-radius: 50%;
        cursor: pointer;
    }

    .filter-pill-remove:active {
        background: rgba(2, 132, 199, 0.15);
    }

    /* Bottom sheet — the selects slide up from the bottom */
    /* While the sheet is open, lift the whole section above the sticky header
       so the backdrop (inside this section) covers the full viewport. */
    body.sheet-open .filters-section {
        z-index: 300;
    }

    .collapsible-filters {
        display: flex;
        flex-direction: column;
        gap: 16px;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 200;
        max-height: 80vh;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
        background: var(--bg-white);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: var(--shadow-xl);
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }

    .collapsible-filters.open {
        transform: translateY(0);
    }

    .collapsible-filters .filter-group {
        width: 100%;
        min-width: auto;
        flex: none;
    }

    /* In the sheet, replace the dropdowns with multi-select choice pills */
    .collapsible-filters .filter-select {
        display: none;
    }

    .choice-pills {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 8px;
    }

    .choice-pill {
        padding: 8px 14px;
        font-family: inherit;
        font-size: 0.85rem;
        font-weight: 500;
        color: var(--text-primary);
        background: var(--bg-white);
        border: 1.5px solid var(--border-color);
        border-radius: 999px;
        cursor: pointer;
        transition: var(--transition);
    }

    .choice-pill.selected {
        color: var(--bg-white);
        background: var(--primary-color);
        border-color: var(--primary-color);
    }

    /* Sheet header (Filters title + Done) */
    .filter-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 4px;
        border-bottom: 1px solid var(--border-light);
    }

    .filter-sheet-title {
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--text-primary);
    }

    .filter-sheet-done {
        padding: 6px 14px;
        font-family: inherit;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--bg-white);
        background: var(--primary-color);
        border: none;
        border-radius: var(--radius-md);
        cursor: pointer;
    }

    .btn-reset {
        width: 100%;
        justify-content: center;
    }

    /* Backdrop behind the bottom sheet */
    .filter-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 199;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .filter-sheet-backdrop.open {
        opacity: 1;
        visibility: visible;
    }

    /* Lock background scroll while the sheet is open */
    body.sheet-open {
        overflow: hidden;
    }

    .products-section {
        padding: 16px;
    }

    .products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .modal {
        max-height: 90vh;
        margin: 10px;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-tabs {
        padding: 0 16px;
        overflow-x: auto;
    }

    .tab-btn {
        padding: 12px 16px;
        white-space: nowrap;
    }

    .modal-body {
        padding: 16px;
    }

    .data-table th,
    .data-table td {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .admin-section {
        padding: 16px;
    }

    .checkbox-grid {
        grid-template-columns: 1fr;
    }

    .users-table-wrapper {
        overflow-x: auto;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 32px 24px;
    }

    .login-logo img {
        max-width: 100px;
    }

    .login-title {
        font-size: 1.5rem;
    }

    .header-logo {
        height: 32px;
    }

    .header-title {
        font-size: 1rem;
    }

    .product-card {
        padding: 16px;
    }

    .product-name {
        font-size: 0.95rem;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }
}
