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

:root {
    --primary: #42A5F5;
    --primary-dark: #1E88E5;
    --primary-light: #E3F2FD;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navbar === */
.navbar {
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.nav-brand a { color: white; font-weight: 700; font-size: 1.1rem; }
.nav-brand a:hover { text-decoration: none; }
.nav-hamburger {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    margin-left: auto;
    border-radius: var(--radius);
}
.nav-hamburger:hover { background: rgba(255,255,255,0.15); }
.nav-links { display: flex; gap: 0.25rem; margin-left: 2rem; flex: 1; }
.nav-links > a {
    color: rgba(255,255,255,0.85);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
}
.nav-links > a:hover { background: rgba(255,255,255,0.15); color: white; text-decoration: none; }
.nav-links > a.active { background: var(--primary-dark); color: white; }

/* Nav dropdown */
.nav-dropdown { position: relative; display: flex; }
.nav-dropdown-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.85);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.nav-dropdown-toggle:hover { background: rgba(255,255,255,0.15); color: white; }
.nav-dropdown-toggle.active { background: var(--primary-dark); color: white; }
.nav-dropdown-toggle .arrow { font-size: 0.6rem; }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.3rem;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 160px;
    z-index: 150;
    border: 1px solid var(--gray-200);
    overflow: hidden;
}
.nav-dropdown-menu.show { display: block; }
.nav-dropdown-menu a {
    display: block;
    padding: 0.55rem 1rem;
    color: var(--gray-700);
    font-size: 0.85rem;
    transition: background 0.1s;
}
.nav-dropdown-menu a:hover { background: var(--gray-100); text-decoration: none; }
.nav-dropdown-menu a.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 500; }

/* Navbar quick search */
.nav-search {
    display: flex;
    align-items: center;
    margin-right: 1rem;
}
.nav-search input {
    padding: 0.35rem 0.6rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: rgba(255,255,255,0.15);
    color: white;
    width: 160px;
    transition: background 0.15s, border-color 0.15s, width 0.2s;
}
.nav-search input::placeholder { color: rgba(255,255,255,0.6); }
.nav-search input:focus {
    outline: none;
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
    width: 200px;
}
.nav-search button {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    padding: 0.35rem 0.4rem;
    font-size: 0.85rem;
}
.nav-search button:hover { color: white; }

/* Global Search Dropdown */
.nav-search-wrapper { position: relative; display: flex; align-items: center; margin-right: 1rem; }
.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 280px;
    margin-top: 0.3rem;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
    z-index: 200;
    max-height: 400px;
    overflow-y: auto;
}
.search-dropdown.show { display: block; }
.search-category {
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--gray-400);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}
.search-item {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-100);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-item:hover { background: var(--primary-light); color: var(--primary-dark); text-decoration: none; }
.search-empty { padding: 0.75rem; text-align: center; color: var(--gray-400); font-size: 0.82rem; }

/* User dropdown */
.nav-user { display: flex; align-items: center; position: relative; }
.user-dropdown-toggle {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: white;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.15s;
}
.user-dropdown-toggle:hover { background: rgba(255,255,255,0.25); }
.user-dropdown-toggle .arrow { font-size: 0.6rem; }
.user-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.4rem;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 150;
    border: 1px solid var(--gray-200);
    overflow: hidden;
}
.user-dropdown-menu.show { display: block; }
.user-dropdown-menu .dropdown-header {
    padding: 0.75rem 1rem 0.5rem;
    border-bottom: 1px solid var(--gray-200);
}
.user-dropdown-menu .dropdown-header .username {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 0.875rem;
}
.user-dropdown-menu .dropdown-header .role-badge {
    display: inline-block;
    margin-top: 0.2rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--primary-light);
    color: var(--primary-dark);
}
.user-dropdown-menu a {
    display: block;
    padding: 0.6rem 1rem;
    color: var(--gray-700);
    font-size: 0.85rem;
    transition: background 0.1s;
}
.user-dropdown-menu a:hover { background: var(--gray-100); text-decoration: none; }

/* === Breadcrumbs === */
.breadcrumb-bar {
    position: sticky;
    top: 56px;
    z-index: 90;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.breadcrumb {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 0;
    padding: 0.5rem 0;
}
.breadcrumb a { color: var(--gray-500); }
.breadcrumb a:hover { color: var(--primary); text-decoration: underline; }
.breadcrumb .separator { margin: 0 0.35rem; color: var(--gray-400); }
.breadcrumb .current { color: var(--gray-700); font-weight: 500; }

/* === Product Tab Toggle === */
.product-tab-toggle {
    position: relative;
    display: inline-block;
}
.product-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    text-transform: uppercase;
    box-shadow: var(--shadow);
    transition: background 0.15s;
}
.product-tab-btn:hover { background: var(--primary-dark); }
.product-tab-btn-secondary { background: var(--gray-600); }
.product-tab-btn-secondary:hover { background: var(--gray-700); }
.product-tab-icon { font-size: 1.1rem; line-height: 1; }
.product-tab-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 120px;
    z-index: 50;
    overflow: hidden;
}
.product-tab-menu.show { display: block; }
.product-tab-menu a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
}
.product-tab-menu a:hover { background: var(--gray-100); text-decoration: none; }
.product-tab-menu a.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* === Container === */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* === Cards === */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}
.card-header h2 { font-size: 1.15rem; font-weight: 600; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: white; border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-group { display: flex; gap: 0.5rem; }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.3rem; font-size: 0.875rem; color: var(--gray-700); }
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: border-color 0.15s;
    background: white;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-inline { display: flex; gap: 0.5rem; align-items: end; }

/* === Tables === */
.table-wrapper { overflow-x: auto; }
/* clip prevents creating a scroll container that breaks position:sticky */
.table-wrapper:has(.sticky-header) { overflow-x: clip; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--gray-200); font-size: 0.85rem; }
th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.85rem;
}
th a { color: var(--gray-600); }
th a:hover { color: var(--primary); text-decoration: none; }
tr:hover { background: var(--gray-50); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-small { font-size: 0.8rem; }

/* === Sticky Table Headers === */
.sticky-header { border-collapse: separate; border-spacing: 0; }
.sticky-header thead th {
    position: sticky;
    top: var(--sticky-top, 91px);  /* navbar 56px + breadcrumb ~35px */
    z-index: 10;
    background: var(--gray-50);
    box-shadow: 0 1px 0 var(--gray-200);
}
.sticky-header thead tr.filter-row td {
    position: sticky;
    top: var(--filter-top, 125px);  /* set dynamically by JS */
    z-index: 10;
    background: white;
    box-shadow: 0 1px 0 var(--gray-200);
}

/* === Alerts === */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--primary-light); color: #1565C0; border: 1px solid #90CAF9; }
.alert-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: 0.7; }
.alert-close:hover { opacity: 1; }

/* === Page Size Select === */
/* === Filter Presets === */
.filter-presets { position: relative; display: inline-block; }
.filter-presets .preset-toggle { cursor: pointer; }
.preset-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 50;
}
.preset-menu.show { display: block; }
.preset-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}
.preset-item:last-child { border-bottom: none; }
.preset-item a {
    flex: 1;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.preset-item a:hover { color: var(--primary); }
.preset-delete {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    margin-left: 0.5rem;
}
.preset-delete:hover { color: var(--danger); }
.preset-empty {
    padding: 0.5rem 0.75rem;
    color: var(--gray-400);
    font-size: 0.82rem;
    text-align: center;
}

/* === Inline Editing === */
.editable {
    cursor: pointer;
    border-bottom: 1px dashed var(--gray-300);
    padding-bottom: 1px;
}
.editable:hover { background: var(--primary-light); border-bottom-color: var(--primary); }

/* === Undo Toast === */
.undo-toast {
    position: fixed;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 9999;
    font-size: 0.9rem;
    transition: bottom 0.3s ease;
}
.undo-toast.show { bottom: 2rem; }
.undo-toast button {
    background: none;
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}
.undo-toast button:hover { background: rgba(255,255,255,0.15); }

/* === Page Size Select === */
.page-size-select {
    font-size: 0.82rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.page-size-select select {
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--gray-300);
    border-radius: 3px;
    font-size: 0.82rem;
    background: white;
    cursor: pointer;
}

/* === Pagination === */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
    margin-top: 1rem;
    padding-top: 1rem;
}
.pagination a, .pagination span {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--gray-700);
}
.pagination a:hover { background: var(--gray-100); text-decoration: none; }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .disabled { color: var(--gray-400); cursor: not-allowed; }

/* === Stats === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 0.25rem; }

/* === Login === */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
}
.login-container h1 { text-align: center; margin-bottom: 1.5rem; }

/* === Inline Column Filters === */
.filter-row td {
    padding: 0.3rem 0.4rem;
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-300);
}
.filter-input {
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 3px;
    font-size: 0.78rem;
    background: white;
    color: var(--gray-700);
    transition: border-color 0.15s;
}
.filter-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}
.filter-input::placeholder { color: var(--gray-400); font-style: italic; }

/* === Legacy Filters (kept for compatibility) === */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
.filters-bar .form-group { margin-bottom: 0; min-width: 150px; }

/* === Bulk Lookup === */
.bulk-lookup { margin-bottom: 1.5rem; }
.bulk-lookup textarea { min-height: 100px; font-family: monospace; }

/* === Import Preview === */
.preview-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}
.preview-stat {
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
    font-weight: 600;
}
.preview-stat.new { background: var(--success-light); color: #166534; }
.preview-stat.update { background: var(--primary-light); color: #1565C0; }
.preview-stat.fail { background: var(--danger-light); color: #991b1b; }
.preview-stat .count { font-size: 1.5rem; display: block; }

/* === Drill-down === */
.detail-section { margin-top: 1rem; }
.detail-section h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-regular { background: var(--gray-200); color: var(--gray-700); }
.badge-manager { background: var(--primary-light); color: var(--primary-dark); }
.badge-master { background: var(--warning-light); color: var(--warning); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warehouse { background: #e0f2f1; color: #00695c; }
.badge-manual { background: var(--primary-light); color: var(--primary-dark); }
.badge-system { background: #e8f5e9; color: #2e7d32; }

/* === Modal === */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-md);
}
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* === Loading Spinner === */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    justify-content: center;
    align-items: center;
}
.loading-overlay.show { display: flex; }
.loading-spinner {
    background: white;
    border-radius: var(--radius);
    padding: 2rem 3rem;
    box-shadow: var(--shadow-md);
    text-align: center;
}
.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.3s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-text {
    color: var(--gray-600);
    font-size: 0.9rem;
    font-weight: 500;
}

/* === Responsive === */
@media (max-width: 768px) {
    /* Navbar becomes vertical */
    .navbar {
        flex-wrap: wrap;
        height: auto;
        padding: 0.5rem 0.75rem;
        gap: 0;
    }
    .nav-brand { flex: 0 0 auto; }
    .breadcrumb-bar { top: 0; position: relative; }
    .nav-hamburger { display: block; order: 1; }

    /* Nav links: hidden by default, shown when .open */
    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        margin-left: 0;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid rgba(255,255,255,0.2);
        gap: 0.15rem;
        order: 3;
    }
    .nav-links.open { display: flex; }
    .nav-links > a { padding: 0.5rem 0.75rem; font-size: 0.9rem; }
    .nav-dropdown { flex-direction: column; }
    .nav-dropdown-menu {
        position: static;
        margin-top: 0;
        box-shadow: none;
        border: none;
        background: rgba(255,255,255,0.08);
        border-radius: 0;
    }
    .nav-dropdown-menu a { padding-left: 2rem; color: rgba(255,255,255,0.85); }
    .nav-dropdown-menu a:hover { background: rgba(255,255,255,0.1); }
    .nav-dropdown-menu a.active { background: rgba(255,255,255,0.15); color: white; }

    /* Search + user on same row */
    .nav-search-wrapper { order: 2; margin-right: 0.5rem; }
    .nav-search input { width: 100px; font-size: 0.75rem; }
    .nav-search input:focus { width: 120px; }
    .nav-user { order: 2; }

    /* Container */
    .container { padding: 0.75rem; }

    /* Cards */
    .card { padding: 1rem; }
    .card-header { flex-wrap: wrap; gap: 0.5rem; }

    /* Tables: smaller text, tighter padding */
    th, td { padding: 0.4rem 0.5rem; font-size: 0.78rem; }

    /* Stats grid */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
    .stat-card { padding: 0.75rem; }
    .stat-card .stat-value { font-size: 1.5rem; }

    /* Forms */
    .filters-bar { flex-direction: column; }
    .form-row { grid-template-columns: 1fr; }
    .btn-group { flex-wrap: wrap; }

    /* Preview summary */
    .preview-summary { grid-template-columns: repeat(2, 1fr); }
}

/* === Messaging === */
.nav-bell {
    position: relative;
    color: rgba(255,255,255,0.85);
    font-size: 1.2rem;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius);
    text-decoration: none;
    margin-right: 0.25rem;
}
.nav-bell:hover { background: rgba(255,255,255,0.15); color: white; text-decoration: none; }
.unread-badge {
    position: absolute;
    top: -2px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 9px;
    padding: 0 4px;
}
.msg-unread { font-weight: 600; background: var(--primary-light); }
.msg-entity-link {
    display: inline-block;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    color: var(--primary-dark);
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}
.msg-entity-link:hover { background: var(--primary-light); text-decoration: none; }
tr[onclick]:hover, tr[style*="cursor:pointer"]:hover {
    background: rgba(66, 165, 245, 0.08) !important;
    cursor: pointer;
}

/* === Section Sub-Nav === */
.section-nav {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* === Responsive: wide tables & order pages === */
@media (max-width: 768px) {
    /* Ensure all table wrappers scroll horizontally on mobile */
    .table-wrapper,
    .sticky-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Order page button groups: stack on mobile */
    .card-header .btn-group {
        flex-wrap: wrap;
        gap: 0.35rem;
    }
    .card-header .btn-group .btn,
    .card-header .btn-group form {
        flex: 0 0 auto;
    }

    /* Summary stats: wrap nicer on mobile */
    .card > div[style*="display:flex"][style*="gap"] {
        flex-wrap: wrap;
    }

    /* Modal: full-width on mobile */
    .modal {
        max-width: 95%;
        margin: 0 auto;
    }

    /* Pagination: wrap on mobile */
    .pagination {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .nav-search { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .preview-summary { grid-template-columns: 1fr; }
    .card-header h2 { font-size: 1rem; }

    /* Tighter card padding on small screens */
    .card { padding: 0.75rem; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }

    /* Buttons stack fully on very small screens */
    .btn-group { flex-direction: column; width: 100%; }
    .btn-group .btn { width: 100%; justify-content: center; }

    /* Login form needs breathing room */
    .login-container { margin: 2rem 0.75rem; }
}

/* Line-lock toast */
.line-lock-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--gray-800);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    box-shadow: var(--shadow-md);
    z-index: 9999;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.3s, transform 0.3s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.line-lock-toast.show {
    opacity: 1;
    transform: translateY(0);
}
.line-lock-toast-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius);
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
}
.line-lock-toast-btn:hover { background: var(--primary-dark); }
.line-lock-toast-btn:disabled { opacity: 0.6; cursor: default; }

/* Access request banner inside alloc modal */
.access-request-banner {
    background: #fff3e0;
    border: 1px solid #ffcc80;
    color: #e65100;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.84rem;
    margin-bottom: 0.75rem;
    animation: accessPulse 0.4s ease;
}
@keyframes accessPulse {
    0% { transform: scale(0.97); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* === Resizable Table Columns === */
th { position: relative; }
th .col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    user-select: none;
    z-index: 2;
}
th .col-resize-handle:hover,
th .col-resize-handle.active {
    background: var(--primary);
    opacity: 0.4;
}
body.col-resizing { cursor: col-resize !important; user-select: none !important; }
body.col-resizing * { cursor: col-resize !important; user-select: none !important; }
