/* CSS Variables for theming */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #767676; /* Fixed: was #999999, now meets WCAG AA 4.54:1 */
    --border-color: #dddddd;
    --border-light: #eeeeee;
    --accent-primary: #3498db;
    --accent-primary-hover: #2980b9;
    --accent-success: #2ecc71;
    --accent-danger: #e74c3c;
    --accent-warning: #f39c12;
    --nav-bg: #2c3e50;
    --nav-text: #ffffff;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.15);

    /* Spacing system (6.2) */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #b0b0b0;
    --text-muted: #9a9a9a; /* Fixed: improved contrast for dark mode */
    --border-color: #3a3a5a;
    --border-light: #2a2a4a;
    --accent-primary: #4fa3d1;
    --accent-primary-hover: #3a8dbb;
    --nav-bg: #0f0f23;
    --shadow: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.4);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #1a1a2e;
        --bg-secondary: #16213e;
        --bg-tertiary: #0f3460;
        --text-primary: #eaeaea;
        --text-secondary: #b0b0b0;
        --text-muted: #9a9a9a; /* Fixed: improved contrast for dark mode */
        --border-color: #3a3a5a;
        --border-light: #2a2a4a;
        --accent-primary: #4fa3d1;
        --accent-primary-hover: #3a8dbb;
        --nav-bg: #0f0f23;
        --shadow: 0 2px 4px rgba(0,0,0,0.3);
        --shadow-lg: 0 4px 8px rgba(0,0,0,0.4);
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Navigation */
nav {
    background: var(--nav-bg);
    color: var(--nav-text);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

nav .logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--nav-text);
    text-decoration: none;
}

nav .logo img {
    height: 32px;
    width: auto;
}

nav .nav-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

nav .nav-links a {
    color: var(--nav-text);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: background 0.2s;
}

nav .nav-links a:hover {
    background: rgba(255,255,255,0.1);
}

/* Mobile nav toggle */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
}

.nav-toggle span {
    display: block;
    width: 100%;
    height: 3px;
    background: var(--nav-text);
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
}

.nav-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.nav-toggle.active span:nth-child(2) {
    opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Theme toggle */
.theme-toggle {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    color: var(--nav-text);
    font-size: 1rem;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.theme-icon::before {
    content: "Light";
    font-size: 0.75rem;
}

[data-theme="dark"] .theme-icon::before {
    content: "Dark";
    font-size: 0.75rem;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-icon::before {
        content: "Dark";
        font-size: 0.75rem;
    }
}

/* Mobile responsive nav */
@media (max-width: 768px) {
    .logo-text {
        display: none;
    }

    .nav-toggle {
        display: flex;
    }

    nav .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--nav-bg);
        flex-direction: column;
        padding: 1rem;
        gap: 0;
        border-top: 1px solid rgba(255,255,255,0.1);
    }

    nav .nav-links.active {
        display: flex;
    }

    nav .nav-links a {
        padding: 1rem;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        width: 100%;
    }

    nav .nav-links a:last-of-type {
        border-bottom: none;
    }

    .theme-toggle {
        margin-top: 0.5rem;
        width: 100%;
    }
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

@media (max-width: 768px) {
    main {
        padding: 1rem;
    }
}

h1, h2, h3 {
    margin-bottom: 1rem;
}

a {
    color: var(--accent-primary);
}

/* Stats cards */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-primary);
}

.stat-label {
    color: var(--text-secondary);
}

/* Forms */
form {
    margin-bottom: 1rem;
}

input, select, textarea {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

button {
    padding: 0.5rem 1rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

button:hover, a.btn:hover {
    background: var(--accent-primary-hover);
}

button.secondary, a.btn.secondary {
    background: #95a5a6;
}

button.secondary:hover, a.btn.secondary:hover {
    background: #7f8c8d;
}

button.danger, a.btn.danger {
    background: var(--accent-danger);
}

button.danger:hover, a.btn.danger:hover {
    background: #c0392b;
}

/* Button-styled links */
a.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    text-decoration: none;
    transition: background 0.2s;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

tr:hover {
    background: var(--bg-tertiary);
}

/* Low stock warning */
tr.low-stock {
    background: rgba(243, 156, 18, 0.1);
}

tr.low-stock td:first-child::before {
    content: "⚠ ";
    color: var(--accent-warning);
}

tr.out-of-stock {
    background: rgba(231, 76, 60, 0.1);
}

tr.out-of-stock td:first-child::before {
    content: "✗ ";
    color: var(--accent-danger);
}

/* Cards */
.card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.breadcrumb {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.breadcrumb a {
    color: var(--accent-primary);
    text-decoration: none;
}

.actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.actions-secondary {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
}

.actions-secondary a {
    color: var(--text-muted);
    text-decoration: none;
}

.actions-secondary a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.text-danger {
    color: var(--danger) !important;
}

.text-danger:hover {
    color: var(--danger) !important;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
    color: var(--text-muted);
}

.link-btn:hover {
    text-decoration: underline;
}

.link-btn-danger {
    color: var(--text-muted);
}

.link-btn-danger:hover {
    color: var(--accent-danger);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.tag {
    display: inline-block;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    margin-right: 0.25rem;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.qr-code {
    max-width: 200px;
    margin: 1rem 0;
}

/* Loading states */
.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    z-index: 9999;
    pointer-events: none;
}

.global-loader .spinner {
    height: 100%;
    width: 30%;
    background: var(--accent-primary);
    animation: loading 1s ease-in-out infinite;
}

@keyframes loading {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(200%); }
    100% { transform: translateX(400%); }
}

.spinner-inline {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast notifications */
#toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--accent-primary);
    animation: slideIn 0.3s ease-out;
    pointer-events: auto;
    max-width: 350px;
}

.toast.success {
    border-left-color: var(--accent-success);
}

.toast.error {
    border-left-color: var(--accent-danger);
}

.toast.warning {
    border-left-color: var(--accent-warning);
}

.toast.fade-out {
    animation: slideOut 0.3s ease-in forwards;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* Search results dropdown */
.search-results {
    list-style: none;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.search-results li {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-light);
}

.search-results li:last-child {
    border-bottom: none;
}

.search-results li a {
    color: var(--text-primary);
    text-decoration: none;
    display: block;
}

.search-results li:hover {
    background: var(--bg-tertiary);
}

.search-results .no-results {
    color: var(--text-secondary);
    font-style: italic;
}

.search-results .no-results a {
    color: var(--accent-primary);
    font-style: normal;
}

/* Location tree */
.location-tree {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--shadow);
}

.location-node {
    margin-bottom: 0.25rem;
}

.location-row {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    border-radius: 4px;
}

.location-row:hover {
    background: var(--bg-tertiary);
}

.toggle-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    margin-right: 0.5rem;
    font-size: 1rem;
    line-height: 1;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary);
}

.toggle-btn:hover {
    background: var(--border-color);
}

.toggle-spacer {
    width: 24px;
    margin-right: 0.5rem;
}

.location-code {
    font-weight: 600;
    color: var(--accent-primary);
    text-decoration: none;
    margin-right: 0.75rem;
}

.location-code:hover {
    text-decoration: underline;
}

.location-name {
    color: var(--text-secondary);
    margin-right: 0.75rem;
}

.location-capacity {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.location-children {
    margin-left: 1rem;
    border-left: 1px dashed var(--border-color);
    padding-left: 0.5rem;
}

/* Inline forms */
.inline-form {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.inline-form h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

/* Find & Remove */
.search-results-list {
    margin-top: 1rem;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.result-item:hover {
    border-color: var(--accent-primary);
}

.result-item.removed {
    background: rgba(46, 204, 113, 0.2);
    color: var(--accent-success);
    justify-content: center;
    font-style: italic;
}

.result-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.location-badge {
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.qty-badge {
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: background-color 0.3s, color 0.3s;
}

.qty-badge.qty-updated {
    background: var(--accent-success);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    animation: pulse 0.3s ease-in-out;
}

.qty-badge.qty-error {
    background: var(--accent-danger);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    animation: shake 0.3s ease-in-out;
}

.qty-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.qty-controls input {
    width: 60px;
    text-align: center;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@media (max-width: 600px) {
    .result-item {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .result-info {
        flex: none !important;
    }

    .location-display {
        flex: none !important;
        order: -1;
        margin-bottom: 0.25rem;
    }

    .qty-controls {
        width: 100%;
        justify-content: space-between;
    }

    .qty-controls input {
        flex: 1;
        max-width: 80px;
    }

    .qty-controls button {
        flex: 1;
    }
}

/* Quick action buttons */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (max-width: 500px) {
    .quick-actions {
        grid-template-columns: 1fr;
    }
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border-radius: 8px;
    text-decoration: none;
    transition: transform 0.1s, box-shadow 0.1s;
    box-shadow: var(--shadow);
    color: white;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    color: white;
}

.action-btn-primary {
    background: var(--accent-primary);
}

.action-btn-secondary {
    background: var(--accent-success);
}

.action-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.action-label {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 1rem;
    flex-wrap: wrap;
}

.pagination a {
    padding: 0.5rem 1rem;
    background: var(--accent-primary);
    color: white;
    text-decoration: none;
    border-radius: 4px;
}

.pagination a:hover {
    background: var(--accent-primary-hover);
}

.pagination .disabled {
    padding: 0.5rem 1rem;
    background: var(--border-color);
    color: var(--text-muted);
    border-radius: 4px;
}

.pagination .page-info {
    color: var(--text-secondary);
}

/* Type overview in item form */
.type-overview {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.type-overview .type-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.type-overview .type-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.type-overview .type-info strong {
    font-size: 1rem;
}

.type-overview .type-info small {
    color: var(--text-secondary);
    display: block;
}

.type-overview .type-info .part-numbers {
    font-family: monospace;
    font-size: 0.8rem;
}

.type-overview .type-info .track-mode {
    color: var(--text-muted);
    font-style: italic;
}

.type-overview > a {
    align-self: flex-start;
    white-space: nowrap;
}

/* Bulk selection */
.bulk-select {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.bulk-actions {
    display: none;
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.bulk-actions.active {
    display: flex;
}

.bulk-actions .selected-count {
    font-weight: 600;
}

/* Keyboard shortcut hints */
.kbd {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    font-family: monospace;
    font-size: 0.8rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    box-shadow: 0 1px 0 var(--border-color);
}

/* Recent activity */
.activity-list {
    list-style: none;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.activity-icon.add {
    background: rgba(46, 204, 113, 0.2);
    color: var(--accent-success);
}

.activity-icon.remove {
    background: rgba(231, 76, 60, 0.2);
    color: var(--accent-danger);
}

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-content strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-content small {
    color: var(--text-muted);
}

/* Print styles for QR labels */
@media print {
    body * {
        visibility: hidden;
    }

    .print-area, .print-area * {
        visibility: visible;
    }

    .print-area {
        position: absolute;
        left: 0;
        top: 0;
    }

    .qr-label {
        page-break-inside: avoid;
        padding: 1rem;
        text-align: center;
        border: 1px dashed #ccc;
        margin: 0.5rem;
        display: inline-block;
    }

    .qr-label img {
        max-width: 150px;
    }

    .qr-label .label-code {
        font-weight: bold;
        font-size: 1.2rem;
        margin-top: 0.5rem;
    }

    .qr-label .label-name {
        font-size: 0.9rem;
        color: #666;
    }
}

/* Scanner input indicator */
.scanner-active input[type="search"],
.scanner-active input[type="text"].search-input {
    border-color: var(--accent-success);
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.2);
}

/* Help modal for keyboard shortcuts */
.help-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.help-modal.active {
    display: flex;
}

.help-modal-content {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.help-modal h3 {
    margin-bottom: 1rem;
}

.shortcut-list {
    list-style: none;
}

.shortcut-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
}

.shortcut-list li:last-child {
    border-bottom: none;
}

/* Type card modal (global) */
.type-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.type-modal.active {
    display: flex;
}

.type-modal-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.type-modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
}

.type-modal-close:hover {
    color: var(--accent-danger);
}

.type-name-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: pointer;
}

.type-name-link:hover {
    text-decoration-style: solid;
}

/* Image gallery with delete buttons */
.image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.image-thumb {
    position: relative;
    display: inline-block;
}

.image-thumb img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    border: 2px solid var(--border-color);
    display: block;
}

.delete-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-danger);
    color: white;
    border: 2px solid var(--bg-secondary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.delete-image-btn:hover {
    background: #b91c1c;
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.delete-image-btn:active {
    transform: scale(0.95);
}

/* Location Filter Button */
.location-filter-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--nav-text);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    margin-left: 1rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.location-filter-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.location-label {
    display: inline-block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Location Filter Modal */
.location-filter-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.location-filter-modal.active {
    display: flex;
}

.location-filter-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.location-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.location-filter-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.location-filter-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.location-filter-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.location-filter-body {
    overflow-y: auto;
    padding: 1rem;
}

.location-filter-option {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
}

.location-filter-option:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary-hover);
}

.location-filter-name {
    font-size: 0.95rem;
    display: block;
}

/* Mobile responsiveness for location filter */
@media (max-width: 768px) {
    nav {
        gap: 0.5rem;
    }

    .location-filter-btn {
        margin-left: 0.5rem;
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
        max-width: 120px;
        flex-shrink: 1;
    }

    .location-label {
        display: inline-block;
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .nav-toggle {
        margin-left: auto;
        flex-shrink: 0;
    }

    .location-filter-content {
        width: 95%;
        max-height: 90vh;
    }
}

/* ========================================
   Item Creation Workflow Improvements
   ======================================== */

/* Step Indicator */
.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.4;
    transition: opacity 0.3s;
}

.step.active {
    opacity: 1;
}

.step.completed {
    opacity: 0.7;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    font-weight: bold;
    background: var(--bg-primary);
}

.step.active .step-number {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
}

.step.completed .step-number {
    border-color: var(--accent-success);
    background: var(--accent-success);
    color: white;
}

.step.completed .step-number::before {
    content: '✓';
}

.step-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.step.active .step-label {
    color: var(--text-primary);
    font-weight: 600;
}

.step-arrow {
    font-size: 1.5rem;
    color: var(--border-color);
}

/* Form Sections */
.form-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

.form-section.section-active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-section.section-completed {
    background: var(--bg-tertiary);
}

.form-section.section-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.section-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.5rem 0;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--accent-primary);
    color: white;
    border-radius: 50%;
    font-size: 0.875rem;
}

.section-help {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0 0 1rem 2rem;
}

.required {
    color: var(--accent-danger);
}

.required-conditional {
    color: var(--accent-danger);
}

/* Selection Preview (unified) */
.selection-preview {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 0.5rem;
}

.preview-content {
    display: flex;
    gap: 1rem;
    flex: 1;
}

.preview-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.preview-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.preview-info strong {
    font-size: 1rem;
}

.preview-info small {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

/* Tracking Mode Badge */
.track-mode-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.track-mode-badge.track-individual {
    color: var(--accent-primary);
}

.track-mode-badge.track-quantity {
    color: var(--accent-success);
}

.badge-icon {
    font-size: 1rem;
}

.badge-text {
    font-weight: 500;
}

.badge-help {
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    padding: 0;
    font-size: 0.625rem;
    cursor: help;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.badge-help:hover {
    background: currentColor;
    color: white;
}

/* Suggestion Reasoning */
.suggestion-reason {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent-success);
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.suggestion-reason-icon {
    font-size: 1rem;
}

/* Field Errors */
.field-error {
    color: var(--accent-danger);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: rgba(231, 76, 60, 0.1);
    border-left: 3px solid var(--accent-danger);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-icon {
    font-size: 1rem;
}

/* Button Disabled State */
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Suggest Button Styling */
.btn-suggest {
    white-space: nowrap;
}

/* Mobile responsive for new components */
@media (max-width: 768px) {
    .step-indicator {
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .step-number {
        width: 32px;
        height: 32px;
        font-size: 0.875rem;
    }

    .step-label {
        font-size: 0.75rem;
    }

    .step-arrow {
        font-size: 1rem;
    }

    .form-section {
        padding: 1rem;
    }

    .preview-actions {
        flex-direction: column;
    }

    .preview-content {
        flex-direction: column;
    }

    .preview-thumb {
        width: 100%;
        height: auto;
        max-height: 200px;
    }
}

/* ========================================
   Utility Classes (6.1, 6.2)
   ======================================== */

/* Flexbox utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }

/* Gap utilities */
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* Margin utilities */
.mt-0 { margin-top: 0; }
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-0 { margin-bottom: 0; }
.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.ml-sm { margin-left: var(--space-sm); }
.ml-md { margin-left: var(--space-md); }
.mr-sm { margin-right: var(--space-sm); }

/* Padding utilities */
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.px-sm { padding-left: var(--space-sm); padding-right: var(--space-sm); }
.py-sm { padding-top: var(--space-sm); padding-bottom: var(--space-sm); }
.py-xs { padding-top: var(--space-xs); padding-bottom: var(--space-xs); }

/* Width utilities */
.w-full { width: 100%; }
.w-auto { width: auto; }
.max-w-xs { max-width: 200px; }
.max-w-sm { max-width: 300px; }
.max-w-md { max-width: 400px; }
.max-w-lg { max-width: 500px; }
.min-w-xs { min-width: 120px; }
.min-w-sm { min-width: 200px; }

/* Text utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--accent-success); }
.text-danger { color: var(--accent-danger); }
.text-warning { color: var(--accent-warning); }
.text-inherit { color: inherit; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 600; }
.no-underline { text-decoration: none; }
.whitespace-nowrap { white-space: nowrap; }

/* Display utilities */
.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline-flex { display: inline-flex; }

/* Border radius */
.rounded { border-radius: 4px; }
.rounded-md { border-radius: 6px; }
.rounded-lg { border-radius: 8px; }

/* ========================================
   Component-specific utility classes
   ======================================== */

/* Page header with title and actions */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.page-header h1 {
    margin-bottom: 0;
}

.page-header-actions {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

/* Card header layouts */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-xl);
}

.card-header-content {
    flex: 1;
}

.card-header-aside {
    text-align: center;
}

/* Image gallery in cards */
.card-images {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    max-width: 320px;
}

.card-images img {
    max-width: 150px;
    max-height: 150px;
    object-fit: cover;
    border-radius: 4px;
}

/* QR code display */
.qr-display {
    text-align: center;
}

.qr-display img {
    width: 150px;
    height: 150px;
}

.qr-display-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: var(--space-sm);
}

/* Status indicators */
.status-ok {
    color: var(--accent-success);
}

.status-warning {
    color: var(--accent-danger);
    font-weight: 500;
}

/* Tag variants */
.tag-danger {
    background: var(--accent-danger);
    color: white;
}

.tag-full {
    background: var(--accent-danger);
    color: white;
    margin-left: var(--space-sm);
}

/* Inline form controls */
.inline-input {
    width: 80px;
    padding: var(--space-xs) var(--space-sm);
    text-align: center;
}

.inline-btn {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
}

/* Threshold/inventory row controls */
.qty-input {
    width: 80px;
    padding: var(--space-xs) var(--space-sm);
    text-align: center;
}

.qty-input-sm {
    width: 60px;
}

.qty-display {
    min-width: 2rem;
    font-weight: 600;
}

.icon-btn {
    background: transparent;
    border: none;
    padding: var(--space-xs);
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Add threshold form box */
.add-threshold-box {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-radius: 6px;
}

.add-threshold-box label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
}

.add-threshold-header {
    font-size: 0.875rem;
    font-weight: 600;
    display: block;
    margin-bottom: var(--space-sm);
}

.add-threshold-form {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
    align-items: flex-end;
}

.add-threshold-field {
    flex: 1;
    min-width: 200px;
}

.add-threshold-field-sm {
    min-width: 120px;
}

/* Search input wrapper */
.search-input-field {
    flex: 1;
}

/* Filter input */
.filter-input {
    max-width: 300px;
}

/* Loading text */
.loading-text {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

/* Helper/hint text */
.hint {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.hint-block {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--space-sm);
}

/* Section headings */
.section-heading {
    margin-top: var(--space-lg);
    font-size: 1.125rem;
    color: var(--text-primary);
}

/* Link that looks like text */
.link-inherit {
    color: inherit;
    text-decoration: none;
}

.link-inherit:hover {
    text-decoration: underline;
}

/* Stat card that's clickable */
.stat-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform 0.1s, box-shadow 0.1s;
}

.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ========================================
   Skip Link for Accessibility (Quick Win 6)
   ======================================== */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-primary);
    color: white;
    padding: var(--space-sm) var(--space-md);
    z-index: 10000;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* ========================================
   Active Navigation State (Quick Win 1)
   ======================================== */

nav .nav-links a.active {
    background: rgba(255, 255, 255, 0.2);
    position: relative;
}

nav .nav-links a.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0.5rem;
    right: 0.5rem;
    height: 2px;
    background: white;
    border-radius: 1px;
}

/* ========================================
   Enhanced Focus States (6.4)
   ======================================== */

:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Remove default focus outline since we're using focus-visible */
:focus:not(:focus-visible) {
    outline: none;
}

/* Enhanced focus for buttons */
button:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.2);
}

/* Enhanced focus for inputs */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

/* Focus for links */
a:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Focus for checkboxes */
input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ========================================
   Loading Skeleton Styles (6.5)
   ======================================== */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-secondary) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text-sm {
    height: 0.75em;
    width: 60%;
}

.skeleton-title {
    height: 1.5em;
    width: 40%;
    margin-bottom: 1em;
}

.skeleton-card {
    height: 100px;
    width: 100%;
}

.skeleton-circle {
    border-radius: 50%;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========================================
   Touch Target Sizes for Mobile (Quick Win 5)
   ======================================== */

@media (max-width: 768px) {
    /* Ensure minimum touch target size of 44x44px */
    button,
    .btn,
    a.btn,
    .toggle-btn,
    input[type="checkbox"],
    .nav-links a,
    .location-filter-btn {
        min-height: 44px;
    }

    /* Larger checkbox hit area */
    input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }

    /* Increase nav link padding for touch */
    nav .nav-links a {
        padding: 0.75rem 1rem;
    }

    /* Larger action buttons */
    .actions button,
    .actions .btn {
        padding: 0.75rem 1rem;
    }

    /* Make inline buttons touchable */
    .inline-btn {
        min-height: 44px;
        padding: var(--space-sm) var(--space-md);
    }

    /* Touch-friendly table buttons */
    table button {
        min-height: 40px;
        padding: var(--space-sm) var(--space-md);
    }
}

/* ========================================
   Visually Hidden (for screen readers)
   ======================================== */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Tracking Mode Help (moved from inline)
   ======================================== */

.tracking-mode-help {
    margin-top: var(--space-sm);
}

/* ========================================
   QR/Barcode Camera Scanner
   ======================================== */

/* Scan button in navbar */
.scan-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--nav-text);
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 1rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.scan-btn svg {
    display: block;
}

/* Scanner Modal */
.scanner-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.scanner-modal.active {
    display: flex;
}

.scanner-modal-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.scanner-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.scanner-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.scanner-modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.scanner-modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.scanner-modal-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#scanner-viewfinder {
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

/* Override html5-qrcode styling */
#scanner-viewfinder video {
    object-fit: cover;
}

#scanner-viewfinder img[alt="Info icon"] {
    display: none !important;
}

.scanner-hint {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

.scanner-error {
    color: var(--accent-danger);
    padding: 1rem;
    text-align: center;
}

.scanner-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: var(--accent-success);
}

.scanner-success-icon {
    font-size: 3rem;
}

/* Mobile: full screen scanner */
@media (max-width: 768px) {
    .scan-btn {
        margin-left: 0.5rem;
        padding: 0.4rem;
    }

    .scanner-modal-content {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
    }

    #scanner-viewfinder {
        max-width: none;
        flex: 1;
        aspect-ratio: auto;
    }

    .scanner-modal-body {
        flex: 1;
        display: flex;
        flex-direction: column;
    }
}

/* ========================================
   Login Page
   ======================================== */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
    padding: var(--space-xl);
}

.login-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: var(--space-2xl);
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
}

.login-logo {
    width: 80px;
    height: auto;
    margin-bottom: var(--space-lg);
}

.login-card h1 {
    margin-bottom: var(--space-sm);
    font-size: 1.75rem;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: var(--space-xl);
}

.login-form {
    text-align: left;
}

.login-form .form-group {
    margin-bottom: var(--space-md);
}

.login-form label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: 500;
    color: var(--text-primary);
}

.login-form input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.login-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: var(--space-lg);
}

.login-btn:hover {
    background: var(--accent-primary-hover);
    color: white;
}

.login-error {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid var(--accent-danger);
    color: var(--accent-danger);
    padding: var(--space-sm) var(--space-md);
    border-radius: 4px;
    margin-bottom: var(--space-md);
    font-size: 0.875rem;
}

/* ========================================
   User Menu in Navigation
   ======================================== */

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: var(--space-md);
    padding-left: var(--space-md);
    border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.user-name {
    color: var(--nav-text);
    font-size: 0.875rem;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-form {
    display: flex;
}

.logout-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--nav-text);
    padding: 0.4rem;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
}

.logout-btn svg {
    display: block;
}

@media (max-width: 768px) {
    .user-menu {
        margin-left: var(--space-sm);
        padding-left: var(--space-sm);
        border-left: none;
    }

    .user-name {
        display: none;
    }

    .login-container {
        padding: var(--space-md);
    }

    .login-card {
        padding: var(--space-xl);
    }
}

/* User Dropdown */
.user-dropdown {
    position: relative;
}

.user-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: none;
    color: var(--nav-text);
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.user-dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.1);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.user-name-short {
    font-size: 0.9rem;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-arrow {
    transition: transform 0.2s;
}

.user-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s;
    z-index: 1000;
}

.user-dropdown.open .user-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-username {
    font-weight: 600;
    color: var(--text-primary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

.dropdown-item,
a.dropdown-item,
a.dropdown-item:link,
a.dropdown-item:visited {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.6rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
    text-align: left;
}

.dropdown-item:hover,
a.dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-item svg {
    opacity: 0.7;
    flex-shrink: 0;
}

.dropdown-item-danger {
    color: var(--accent-danger);
}

.dropdown-item-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.dropdown-logout-form {
    margin: 0;
}

@media (max-width: 768px) {
    .user-name-short {
        display: none;
    }

    .user-dropdown-trigger {
        padding: 0.4rem;
    }

    .user-dropdown-menu {
        right: -0.5rem;
    }
}

/* Mobile overflow fixes */
@media (max-width: 768px) {
    /* File inputs */
    input[type="file"] {
        max-width: 100%;
        font-size: 0.875rem;
    }

    /* Form button groups */
    .form-actions {
        flex-wrap: wrap;
    }

    .form-actions .btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* Input groups with buttons */
    .form-row {
        flex-wrap: wrap;
    }

    .form-row .btn,
    .form-row button {
        flex-shrink: 1;
        min-width: 0;
        white-space: nowrap;
    }

    /* Suggest button fix */
    .btn-suggest {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Hide secondary table columns on mobile */
    .col-hide-mobile {
        display: none;
    }

    /* Compact table cells */
    th, td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }

    /* Stack action buttons vertically */
    td.actions {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    td.actions .btn,
    td.actions button {
        width: 100%;
        text-align: center;
    }
}

/* Location view */
.location-card .card-header-content p {
    margin: 0.25rem 0;
}

.location-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.qr-display-sm img {
    width: 100px;
    height: 100px;
}

.verify-status {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.verify-status:empty {
    display: none;
}

/* Collapsible threshold section */
.threshold-section {
    margin-top: 1.5rem;
}

.threshold-section summary {
    cursor: pointer;
}

.threshold-section summary h2 {
    display: inline;
}
