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

:root {
    --color-bg: #0f1117;
    --color-surface: #1a1d27;
    --color-surface-hover: #232735;
    --color-border: #2a2e3b;
    --color-text: #e4e6ed;
    --color-text-muted: #8b8fa3;
    --color-primary: #6c8dfa;
    --color-primary-hover: #5a7bf0;
    --color-danger: #f05252;
    --color-danger-hover: #d94444;
    --color-success: #34d399;
    --color-warning: #fbbf24;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', monospace;
}

/* === Light Theme === */
[data-theme="light"] {
    --color-bg: #f0f2f5;
    --color-surface: #ffffff;
    --color-surface-hover: #f5f6f8;
    --color-border: #d8dce5;
    --color-text: #1a1d27;
    --color-text-muted: #5f6578;
    --color-primary: #4a6cf7;
    --color-primary-hover: #3a5ae0;
    --color-danger: #dc3545;
    --color-danger-hover: #c82333;
    --color-success: #0ea770;
    --color-warning: #e5a000;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
}

/* Info banners */
[data-theme="light"] .info-banner {
    background: rgba(74, 108, 247, 0.06);
    border-color: rgba(74, 108, 247, 0.2);
}

[data-theme="light"] .info-banner--private {
    background: rgba(229, 160, 0, 0.06);
    border-color: rgba(229, 160, 0, 0.25);
}

/* Alias chips */
[data-theme="light"] .identity-alias-chip {
    background: rgba(74, 108, 247, 0.07);
    border-color: rgba(74, 108, 247, 0.18);
    color: #3a5ae0;
}

/* Upload zone */
[data-theme="light"] .upload-zone:hover,
[data-theme="light"] .upload-zone.dragover {
    background: rgba(74, 108, 247, 0.03);
}

/* Drag handle */
[data-theme="light"] .image-preview-item .drag-handle {
    background: rgba(0,0,0,0.4);
}

/* Modal overlay */
[data-theme="light"] .modal-overlay {
    background: rgba(0,0,0,0.35);
}

/* Login alerts */
[data-theme="light"] .login-error {
    background: rgba(220, 53, 69, 0.06);
}

[data-theme="light"] .login-success {
    background: rgba(14, 167, 112, 0.06);
}

/* Admin sidebar active states */
[data-theme="light"] .admin-nav-item.active {
    background: rgba(74, 108, 247, 0.06);
}

[data-theme="light"] .admin-nav-subitem.active {
    background: rgba(74, 108, 247, 0.06);
}

/* Landing button ghost */
[data-theme="light"] .landing-btn-ghost:hover {
    background: rgba(74, 108, 247, 0.05);
}

/* Status badges — stronger text for light backgrounds */
[data-theme="light"] .badge-open { background: rgba(74, 108, 247, 0.09); color: #3a5ae0; }
[data-theme="light"] .badge-in_progress { background: rgba(229, 160, 0, 0.1); color: #a06e00; }
[data-theme="light"] .badge-waiting_on_user { background: rgba(95, 101, 120, 0.09); color: #4a4f5e; }
[data-theme="light"] .badge-resolved { background: rgba(14, 167, 112, 0.09); color: #087d52; }
[data-theme="light"] .badge-closed { background: rgba(95, 101, 120, 0.07); color: #4a4f5e; }

[data-theme="light"] .badge-low { background: rgba(95, 101, 120, 0.07); color: #4a4f5e; }
[data-theme="light"] .badge-medium { background: rgba(74, 108, 247, 0.09); color: #3a5ae0; }
[data-theme="light"] .badge-high { background: rgba(229, 160, 0, 0.1); color: #a06e00; }
[data-theme="light"] .badge-critical { background: rgba(220, 53, 69, 0.09); color: #b21e2d; }

[data-theme="light"] .badge-category { background: rgba(74, 108, 247, 0.06); color: #5f6578; }

/* Notification unread */
[data-theme="light"] .nav-notification-item.unread {
    background: rgba(74, 108, 247, 0.04);
}

[data-theme="light"] .notification-row.unread {
    background: rgba(74, 108, 247, 0.03);
}

/* Reply internal note */
[data-theme="light"] .reply-item.internal-note {
    background: rgba(229, 160, 0, 0.04);
}

/* Status warning bg */
[data-theme="light"] .useful-info-grid .status-warning {
    background: rgba(229, 160, 0, 0.07);
}

/* Mobile sidebar overlay */
@media (max-width: 767px) {
    [data-theme="light"] .admin-sidebar-overlay.open {
        background: rgba(0, 0, 0, 0.25);
    }
}

/* Scrollbars */
[data-theme="light"] .permission-list {
    scrollbar-color: #c4c8d4 transparent;
}
[data-theme="light"] .permission-list::-webkit-scrollbar-thumb {
    background: #c4c8d4;
}
[data-theme="light"] .notes-messages::-webkit-scrollbar-thumb {
    background: #c4c8d4;
}

/* Profile page role badges */
[data-theme="light"] .company-role-admin {
    background: rgba(14, 167, 112, 0.09);
    color: #087d52;
}
[data-theme="light"] .company-role-user {
    background: rgba(74, 108, 247, 0.09);
    color: #3a5ae0;
}

/* Search results dropdown (had hardcoded white bg) */
[data-theme="light"] .search-results-dropdown {
    background: var(--color-surface);
    border-color: var(--color-border);
    box-shadow: var(--shadow-md);
}

/* Canned response select options */
[data-theme="light"] .canned-response-select select option {
    background: var(--color-surface);
    color: var(--color-text);
}

/* Live refresh banner */
[data-theme="light"] .live-refresh-banner {
    background: rgba(229, 160, 0, 0.08);
    border-color: var(--color-warning);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

.show-mobile { display: none; }

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

a:hover {
    color: var(--color-primary-hover);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* === Navigation === */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text);
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.admin-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.admin-menu-toggle:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
}

.nav-hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--color-text);
    border-radius: 1px;
    transition: transform 0.25s, opacity 0.15s;
}

.nav-bar.menu-open .nav-hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.nav-bar.menu-open .nav-hamburger span:nth-child(2) {
    opacity: 0;
}

.nav-bar.menu-open .nav-hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.nav-sector-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
}

.nav-sector-links a {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
}

.nav-sector-links a:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: 1.5rem;
}

.nav-links .nav-dropdown-toggle {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
}

.nav-links .nav-dropdown-toggle:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
}

.nav-links .nav-dropdown-toggle .arrow {
    font-size: 0.65rem;
    opacity: 0.7;
}

.nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    transition: background 0.15s, color 0.15s;
}

.nav-btn:hover, .nav-btn.active {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    color: #fff;
}

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

.btn-danger:hover {
    background: var(--color-danger-hover);
    color: #fff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.btn-outline:hover {
    background: var(--color-surface-hover);
}

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

/* === Main Content === */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* === Tab Bar === */
.tab-bar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
    font-family: var(--font-sans);
}

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

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

.tab svg {
    flex-shrink: 0;
}

/* Sub-tab bar (secondary navigation) */
.sub-tab-bar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    margin-left: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0;
}

.sub-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
    font-family: var(--font-sans);
}

.sub-tab:hover {
    color: var(--color-text);
}

.sub-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.sub-tab svg {
    flex-shrink: 0;
}

.sub-tab:disabled {
    cursor: default;
}

.tab-panel {
    display: none;
}

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

.info-banner {
    background: rgba(108, 141, 250, 0.1);
    border: 1px solid rgba(108, 141, 250, 0.25);
    color: var(--color-primary);
    font-size: 0.8rem;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
}

.info-banner--private {
    background: rgba(251, 191, 36, 0.08);
    border-color: rgba(251, 191, 36, 0.25);
    color: var(--color-warning);
}

.maintenance-banner {
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: var(--color-warning);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    text-align: center;
}

/* === Search Page === */
.search-container {
    margin-bottom: 1.5rem;
}

.search-bar {
    position: relative;
    margin-bottom: 1rem;
}

.search-bar input {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.8rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: 1rem;
    transition: border-color 0.15s;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.search-bar .search-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    pointer-events: none;
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.5rem 0;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.filter-toggle .arrow {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.filter-toggle.open .arrow {
    transform: rotate(180deg);
}

.filter-panel {
    display: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-top: 0.25rem;
    overflow: hidden;
    transition: none;
}

.filter-panel.open {
    display: block;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

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

.filter-group select,
.filter-group input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.9rem;
    transition: border-color 0.15s;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

.height-range {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.height-range select {
    flex: 1;
    min-width: 0;
}

.height-range span {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
    white-space: nowrap;
}

/* Date range inputs - give full width on separate lines */
.filter-group .height-range:has(input[type="date"]) {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
}

.filter-group .height-range:has(input[type="date"]) input[type="date"] {
    width: 100%;
    font-size: 0.85rem;
    padding: 0.55rem 0.7rem;
}

.filter-group .height-range:has(input[type="date"]) span {
    text-align: center;
    font-size: 0.7rem;
}

/* Ensure filter-group has enough width */
.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    min-width: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}

/* === Active Filter Chips === */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.6rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.filter-chip button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
}

.filter-chip button:hover {
    opacity: 1;
}

/* === Results Header === */
.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.results-count {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

/* === Record Cards === */
.record-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.record-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.record-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    color: inherit;
}

.record-card-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--color-bg);
}

.record-card-img-placeholder {
    width: 100%;
    aspect-ratio: 1;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 2.5rem;
}

.record-card-body {
    padding: 0.85rem;
}

.record-card-name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.35rem;
    color: var(--color-text);
}

.record-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.meta-tag {
    font-size: 0.75rem;
    padding: 0.15rem 0.45rem;
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
}

.meta-tag.tag-red { background: #c0392b; color: #fff; }
.meta-tag.tag-green { background: #27ae60; color: #fff; }
.meta-tag.tag-yellow { background: #f39c12; color: #000; }
.meta-tag.tag-blue { background: var(--color-primary); color: #fff; }
.meta-tag.tag-orange { background: #e67e22; color: #fff; }
.meta-tag.tag-gray { background: var(--color-surface-hover); color: var(--color-text-muted); }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    text-transform: uppercase;
    white-space: nowrap;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-active {
    background: rgba(192, 57, 43, 0.12);
    color: #c0392b;
    border: 1px solid rgba(192, 57, 43, 0.25);
}
.status-active .status-dot {
    background: #c0392b;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.2);
    animation: status-pulse 2s ease-in-out infinite;
}
.status-expired {
    background: rgba(127, 140, 141, 0.1);
    color: var(--color-text-muted);
    border: 1px solid rgba(127, 140, 141, 0.2);
}
.status-expired .status-dot {
    background: #95a5a6;
}
.status-revoked {
    background: rgba(39, 174, 96, 0.1);
    color: #1e8449;
    border: 1px solid rgba(39, 174, 96, 0.2);
}
.status-revoked .status-dot {
    background: #27ae60;
}
@keyframes status-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.2); }
    50% { box-shadow: 0 0 0 5px rgba(192, 57, 43, 0.08); }
}

.detail-link-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
}
.detail-link-chip:hover {
    background: var(--color-primary-hover);
    color: #fff;
}

/* === Loading / Empty States === */
.loading-spinner {
    display: flex;
    justify-content: center;
    padding: 2rem;
}

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

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

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state h3 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

/* === Record Detail === */
.record-detail {
    max-width: 900px;
    margin: 0 auto;
}

.record-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.record-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.record-actions {
    display: flex;
    gap: 0.5rem;
}

/* Gallery */
.gallery {
    margin-bottom: 2rem;
}

.gallery-main {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: contain;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.gallery-thumbs {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.gallery-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s;
}

.gallery-thumb.active,
.gallery-thumb:hover {
    border-color: var(--color-primary);
}

.gallery-main {
    cursor: zoom-in;
}

.gallery-empty {
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 1.2rem;
}

/* Lightbox */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.lightbox-overlay.active {
    opacity: 1;
}

.lightbox-close {
    position: absolute;
    top: env(safe-area-inset-top, 12px);
    right: 12px;
    z-index: 10001;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background 0.15s;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.lightbox-counter {
    position: absolute;
    bottom: env(safe-area-inset-bottom, 16px);
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
    z-index: 10001;
    pointer-events: none;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10001;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background 0.15s, opacity 0.15s;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }

.lightbox-img-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.lightbox-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    will-change: transform;
    transform-origin: 0 0;
    transition: none;
    pointer-events: none;
}

.lightbox-hint {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom, 16px) + 32px);
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.7rem;
    z-index: 10001;
    pointer-events: none;
    transition: opacity 0.3s;
}

@media (max-width: 600px) {
    .lightbox-nav { display: none; }
}

@media print {
    .lightbox-overlay { display: none !important; }
}

/* Detail Sections */
.detail-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.detail-section h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

/* Useful Information Section - Redesigned */
.useful-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.useful-info-grid .info-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.useful-info-grid .info-item.full-width {
    grid-column: 1 / -1;
}

.useful-info-grid .info-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.useful-info-grid .info-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    width: fit-content;
}

.useful-info-grid .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-muted);
    flex-shrink: 0;
}

.useful-info-grid .status-normal {
    background: var(--color-bg);
    color: var(--color-text-muted);
}

.useful-info-grid .status-normal .status-dot {
    background: var(--color-text-muted);
}

.useful-info-grid .status-warning {
    background: rgba(251, 191, 36, 0.1);
    color: var(--color-warning);
}

.useful-info-grid .status-warning .status-dot {
    background: var(--color-warning);
}

.useful-info-grid .info-locations {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.useful-info-grid .location-tag {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.65rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text);
}

.useful-info-grid .info-notes {
    padding: 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--color-text);
    line-height: 1.5;
}

@media (max-width: 767px) {
    .useful-info-grid {
        grid-template-columns: 1fr;
    }
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 2.5rem;
    row-gap: 1.15rem;
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.detail-field.full-width {
    grid-column: 1 / -1;
    padding-top: 1.15rem;
    margin-top: 0.15rem;
    border-top: 1px solid var(--color-border);
}

.detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--color-text-muted);
}

.detail-value {
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--color-text);
    word-break: break-word;
}

/* === Identity Section (Record Detail) === */
.identity-fields {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0;
}

.identity-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.75rem 1rem;
    border-right: 1px solid var(--color-border);
}

.identity-field:last-child {
    border-right: none;
}

.identity-age {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.identity-aliases {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.identity-alias-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.identity-alias-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--color-primary);
    background: rgba(108, 141, 250, 0.1);
    border: 1px solid rgba(108, 141, 250, 0.2);
    border-radius: 999px;
}

/* === Form Page === */
.form-container {
    max-width: 800px;
    margin: 0 auto;
}

.form-container h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

/* === Type Selector Pills === */
.type-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.type-pill {
    flex: 1;
    padding: 0.6rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: var(--font-sans);
}

.type-pill:hover {
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.type-pill.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

/* === Suspect Linker === */
.suspect-linker {
    position: relative;
}

.suspect-search-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.95rem;
    font-family: var(--font-sans);
}

.suspect-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.suspect-search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
}

.suspect-result-item {
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.1s;
}

.suspect-result-item:hover {
    background: var(--color-surface-hover);
}

.suspect-result-item.no-results {
    color: var(--color-text-muted);
    cursor: default;
}

.linked-suspects-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.linked-suspect-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.6rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
}

.linked-suspect-chip .chip-remove {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
}

.linked-suspect-chip .chip-remove:hover {
    opacity: 1;
}

.location-autocomplete {
    position: relative;
    width: 100%;
}

.location-autocomplete input {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.location-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 220px;
    overflow-y: auto;
    z-index: 50;
}

.location-result-item {
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.1s;
}

.location-result-item:hover,
.location-result-item.highlighted {
    background: var(--color-surface-hover);
}

.location-result-item .location-match {
    font-weight: 600;
}

.location-result-item .location-county {
    color: var(--color-text-muted);
    font-size: 0.82rem;
}

.location-result-item.no-results {
    color: var(--color-text-muted);
    cursor: default;
}

.alias-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    padding: 0.5rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    min-height: 42px;
    cursor: text;
}

.alias-chips-container:focus-within {
    border-color: var(--color-primary);
}

.alias-chip-input {
    flex: 1;
    min-width: 150px;
    border: none !important;
    background: transparent !important;
    outline: none !important;
    padding: 0.25rem !important;
    color: var(--color-text);
    font-size: 0.9rem;
}

.form-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.form-section h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.form-required-note {
    font-size: 0.75rem;
    font-style: italic;
    color: var(--color-text-muted);
    opacity: 0.85;
    margin-top: -0.25rem;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.form-required-note .required {
    color: var(--color-danger);
    font-style: normal;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.form-group label .required,
.form-section h2 .required {
    color: var(--color-danger);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.6rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.95rem;
    font-family: var(--font-sans);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-group .error-msg {
    font-size: 0.8rem;
    color: var(--color-danger);
    display: none;
}

.form-group.error input,
.form-group.error select,
.form-group.error textarea {
    border-color: var(--color-danger);
}

.form-group.error .error-msg {
    display: block;
}

.form-group .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text);
    cursor: pointer;
    padding: 0.65rem 0;
}

.form-group .checkbox-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--color-primary);
    cursor: pointer;
    flex-shrink: 0;
}

.name-unknown-label {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.plate-lookup-row {
    display: flex;
    gap: 0.5rem;
}

.plate-lookup-row input {
    flex: 1;
}

.plate-lookup-row .btn {
    white-space: nowrap;
    min-width: 90px;
}

.dvla-indicator {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--color-success);
    margin-top: 0.25rem;
}

/* Currency / prefixed inputs */
.input-prefix-wrap {
    display: flex;
    align-items: stretch;
}

.input-prefix {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.9rem;
}

.input-with-prefix {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important;
    flex: 1;
    min-width: 0;
}

/* Text utility classes */
.text-danger {
    color: var(--color-danger);
    font-weight: 600;
}

.text-success {
    color: var(--color-success);
    font-weight: 600;
}

/* Image Upload Area */
.upload-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    color: var(--color-text-muted);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--color-primary);
    background: rgba(108, 141, 250, 0.05);
}

.upload-zone.error {
    border-color: var(--color-danger);
    background: rgba(220, 53, 69, 0.05);
}

.upload-zone p {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.upload-zone input[type="file"] {
    display: none;
}

.image-preview-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.image-preview-item {
    position: relative;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.image-preview-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.image-preview-item .heic-converting {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.image-preview-item .image-actions {
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.image-preview-item input {
    width: 100%;
    padding: 0.3rem 0.4rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.75rem;
}

.image-preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: var(--color-danger);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.image-preview-item .drag-handle {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    font-size: 0.7rem;
}

.image-preview-item .thumbnail-btn {
    width: 100%;
    padding: 0.3rem 0.4rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}

.image-preview-item .thumbnail-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.image-preview-item.is-thumbnail {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary);
}

.image-preview-item.is-thumbnail .thumbnail-btn {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.form-footer {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    justify-content: flex-end;
}

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.9rem;
    animation: slideIn 0.25s ease;
    max-width: 350px;
}

.toast.success {
    border-left: 3px solid var(--color-success);
}

.toast.error {
    border-left: 3px solid var(--color-danger);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* === Live Refresh Banner === */
.live-refresh-banner {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid var(--color-warning);
    border-radius: var(--radius-md);
    color: var(--color-warning);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, opacity 0.3s;
    animation: slideDown 0.3s ease-out;
}

.live-refresh-banner:hover {
    background: rgba(251, 191, 36, 0.2);
}

.live-refresh-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.live-refresh-banner--floating {
    position: fixed;
    top: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    box-shadow: var(--shadow-md);
    max-width: 400px;
    width: auto;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* New record card highlight */
.record-card--new {
    animation: highlightNew 2s ease-out;
}

@keyframes highlightNew {
    0% {
        box-shadow: 0 0 0 2px var(--color-warning), 0 0 12px rgba(251, 191, 36, 0.3);
    }
    100% {
        box-shadow: none;
    }
}

/* === Delete Confirmation Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}

.modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
}

.modal h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

.modal p {
    color: var(--color-text-muted);
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

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

.modal-lg textarea {
    min-height: auto;
}

.detail-table { width: 100%; border-collapse: collapse; }
.detail-table td { padding: 0.4rem 0.5rem; font-size: 0.9rem; vertical-align: top; border-bottom: 1px solid var(--color-border); }
.detail-table td:first-child { color: var(--color-text-muted); white-space: nowrap; width: 140px; font-weight: 500; }

/* === Footer === */
.site-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* === Record Meta Footer === */
.record-meta-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.record-meta-author {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.record-meta-avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

.record-meta-avatar-img {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.record-meta-author-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.record-meta-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.record-meta-company {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.record-meta-timestamps {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.record-meta-ts {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}

.record-meta-ts-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.record-meta-ts-value {
    font-size: 0.82rem;
    color: var(--color-text);
}

.record-meta-divider {
    width: 1px;
    height: 2rem;
    background: var(--color-border);
}

/* === Print Styles === */
@media print {
    .site-header, .site-footer, .record-actions, .nav-bar {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .main-content {
        padding: 0;
    }

    .detail-section {
        background: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .record-meta-footer {
        background: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .record-meta-avatar {
        background: #666;
    }

    .gallery-main {
        max-height: 400px;
        background: none;
        border: 1px solid #ccc;
    }

    .gallery-thumbs {
        display: none;
    }

    .admin-sidebar,
    .admin-sidebar-overlay,
    .admin-menu-toggle,
    .no-print {
        display: none !important;
    }

    .admin-layout {
        display: block;
    }

    .admin-main {
        margin-left: 0;
        padding: 0;
    }

    .print-only {
        display: block !important;
    }

    .report-table {
        width: 100%;
    }

    .report-table th,
    .report-table td {
        border: 1px solid #ccc;
        padding: 0.4rem 0.6rem;
    }

    .admin-table {
        background: none;
    }

    .admin-table thead {
        background: #eee;
    }
}

/* === Login Page === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    text-align: center;
}

.login-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.login-error {
    background: rgba(240, 82, 82, 0.1);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    color: var(--color-danger);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.login-success {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid var(--color-success);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    color: var(--color-success);
    font-size: 0.9rem;
}

.login-success a {
    color: var(--color-success);
    font-weight: 600;
    text-decoration: underline;
}

.login-btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
}

.login-card .form-group {
    margin-bottom: 0.85rem;
}

.login-card .form-group input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.95rem;
}

.login-card .form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.login-card .form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 0.3rem;
}

/* === Company Picker === */
.company-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.company-option {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.85rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-align: left;
    font-family: var(--font-sans);
}

.company-option:hover {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
}

.company-option-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.company-option-desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* === Nav Dropdowns (User Menu / Company Switcher) === */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.65rem;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    white-space: nowrap;
}

.nav-dropdown-toggle:hover {
    border-color: var(--color-text-muted);
}

.nav-dropdown-toggle .arrow {
    font-size: 0.6rem;
    opacity: 0.5;
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    min-width: 200px;
    z-index: 150;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    padding: 0.25rem 0;
}

.nav-dropdown.open .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-header {
    padding: 0.65rem 0.85rem;
}

.nav-dropdown-header-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
}

.nav-dropdown-header-detail {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.1rem;
    line-height: 1.3;
}

.nav-dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: 0.25rem 0;
}

.nav-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.85rem;
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s;
    text-decoration: none;
    font-family: var(--font-sans);
}

.nav-dropdown-item:hover {
    background: var(--color-surface-hover);
}

.nav-dropdown-item.active {
    color: var(--color-primary);
    font-weight: 600;
}

.nav-dropdown-item svg.nav-dropdown-icon {
    width: 15px;
    height: 15px;
    min-width: 15px;
    min-height: 15px;
    flex: 0 0 15px;
    opacity: 0.6;
}

.nav-dropdown-item-danger {
    color: var(--color-danger, #ef4444);
}

.nav-dropdown-item-danger .nav-dropdown-icon {
    opacity: 0.8;
}

.nav-company-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-user-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Admin Layout === */
.admin-layout {
    display: flex;
    min-height: calc(100vh - 57px);
}

.admin-sidebar-overlay {
    display: none;
}

.admin-sidebar {
    width: 220px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 0.75rem 0;
    flex-shrink: 0;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem 0.55rem 1.15rem;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.1s, color 0.1s;
    border-left: 3px solid transparent;
}

.admin-nav-item:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.admin-nav-item:hover .admin-nav-icon {
    opacity: 0.8;
}

.admin-nav-item.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    background: rgba(108, 141, 250, 0.05);
}

.admin-nav-item.active .admin-nav-icon {
    opacity: 1;
}

.admin-nav-category {
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
    justify-content: flex-start;
    position: relative;
}

.admin-nav-chevron {
    width: 14px;
    height: 14px;
    margin-left: auto;
    opacity: 0.4;
    transition: transform 0.2s, opacity 0.15s;
    flex-shrink: 0;
}

.admin-nav-category.open .admin-nav-chevron {
    transform: rotate(180deg);
}

.admin-nav-category:hover .admin-nav-chevron {
    opacity: 0.7;
}

.admin-nav-sub {
    display: none;
    flex-direction: column;
}

.admin-nav-sub.open {
    display: flex;
}

.admin-nav-subitem {
    padding: 0.4rem 1rem 0.4rem 2.75rem;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.1s, color 0.1s;
    border-left: 3px solid transparent;
}

.admin-nav-subitem:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.admin-nav-subitem.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    background: rgba(108, 141, 250, 0.05);
}

.admin-main {
    flex: 1;
    padding: 1.5rem 2rem;
}

.admin-main h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.nav-user-label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* Landing page button styles (used in header for non-logged-in) */
.landing-btn-ghost {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    transition: all 0.2s;
}

.landing-btn-ghost:hover {
    border-color: var(--color-primary);
    background: rgba(108, 141, 250, 0.1);
}

/* Admin Stats */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.admin-stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    text-align: center;
}

.admin-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
}

.admin-stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.25rem;
}

/* Admin Tables */
.admin-table-wrap {
    overflow-x: auto;
}

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

.admin-table th,
.admin-table td {
    padding: 0.65rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.admin-table th {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    background: var(--color-surface);
}

.admin-table tr:hover td {
    background: var(--color-surface-hover);
}

/* Admin Forms */
.admin-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    max-width: 600px;
}

.admin-form .form-group {
    margin-bottom: 1rem;
}

.site-icon-upload {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.site-icon-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.site-icon-upload input[type="file"] {
    font-size: 0.875rem;
}

.admin-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

/* === Admin Filter Bar === */
.admin-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.admin-filter-bar-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.admin-filter-bar-inner label {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.admin-filter-bar-inner select {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    min-width: 150px;
}

.admin-filter-bar-inner select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.admin-filter-count {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* === Report Styles === */
.report-filters {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.report-filter-row {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.report-filter-row .form-group {
    margin-bottom: 0;
}

.report-filter-row label {
    display: block;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-bottom: 0.3rem;
}

.report-filter-row select,
.report-filter-row input[type="date"] {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.6rem;
    font-size: 0.88rem;
}

.report-filter-btn {
    padding-bottom: 1px;
}

.report-actions {
    display: flex;
    gap: 0.5rem;
}

.report-table tfoot td {
    border-top: 2px solid var(--color-border);
}

/* Financial Summary Cards */
.report-financial-summary {
    margin-bottom: 1.5rem;
}

.report-financial-summary h2 {
    font-size: 1.05rem;
    margin-bottom: 0.75rem;
}

.financial-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.financial-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.financial-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.financial-card-icon.stolen {
    background: rgba(240, 82, 82, 0.12);
    color: var(--color-danger);
}

.financial-card-icon.recovered {
    background: rgba(52, 211, 153, 0.12);
    color: var(--color-success);
}

.financial-card-icon.net-loss {
    background: rgba(251, 191, 36, 0.12);
    color: var(--color-warning);
}

.financial-card-icon.recovery-rate {
    background: rgba(108, 141, 250, 0.12);
    color: var(--color-primary);
}

.financial-card-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.financial-card-label {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.15rem;
}

.financial-card-value {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.financial-card-sub {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}

/* === Role Management === */
.text-muted {
    color: var(--color-text-muted);
}

#roles-table td[data-label="Actions"] {
    white-space: nowrap;
}

/* Permission list */
.permission-list {
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}
.permission-list::-webkit-scrollbar {
    width: 6px;
}
.permission-list::-webkit-scrollbar-track {
    background: transparent;
}
.permission-list::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.permission-module + .permission-module {
    border-top: 1px solid var(--color-border);
}

.permission-module-header {
    padding: 0.45rem 0.75rem;
    background: var(--color-surface);
}

.permission-module-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}
.permission-module-toggle input[type="checkbox"] {
    margin: 0;
    width: 0.875rem;
    height: 0.875rem;
    accent-color: var(--color-primary);
    flex-shrink: 0;
}
.permission-module-toggle strong {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.permission-module-items {
    display: flex;
    flex-direction: column;
}

.permission-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.3rem 0.75rem 0.3rem 1.75rem;
    transition: background 0.1s, color 0.1s;
    border-top: 1px solid var(--color-border);
}
.permission-item:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}
.permission-item:focus-within {
    background: var(--color-surface-hover);
    color: var(--color-text);
}
.permission-item input[type="checkbox"] {
    margin: 0;
    width: 0.875rem;
    height: 0.875rem;
    accent-color: var(--color-primary);
    flex-shrink: 0;
}

/* === Mobile (up to 767px) === */
@media (max-width: 767px) {
    /* Nav bar: stacked centered header + subheader */
    .nav-bar {
        flex-direction: column;
        align-items: center;
        gap: 0;
        padding: 0;
    }

    .nav-logo {
        padding: 0.6rem 0;
        border-bottom: 1px solid var(--color-border);
        width: 100%;
        justify-content: center;
    }

    .nav-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center;
        width: 100%;
        padding: 0.5rem 0.75rem;
    }

    .nav-hamburger {
        display: flex;
    }

    .nav-bar:has(.nav-hamburger) {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0.6rem 1rem;
    }

    .nav-bar:has(.nav-hamburger) .nav-logo {
        flex: 1;
        border-bottom: none;
        padding: 0;
        width: auto;
        justify-content: flex-start;
    }

    .nav-hamburger ~ .nav-sector-links,
    .nav-hamburger ~ .nav-actions {
        display: none;
    }

    .nav-bar.menu-open .nav-hamburger ~ .nav-sector-links {
        display: flex;
        flex-direction: column;
        width: 100%;
        order: 3;
        gap: 0;
        margin-left: 0;
        padding: 0.5rem 0;
        border-top: 1px solid var(--color-border);
    }

    .nav-bar.menu-open .nav-sector-links a {
        padding: 0.8rem 1.25rem;
        font-size: 1rem;
        font-weight: 600;
        border-radius: 0;
        text-align: left;
        color: var(--color-text);
    }

    .nav-bar.menu-open .nav-hamburger ~ .nav-actions {
        display: flex;
        width: 100%;
        order: 4;
        padding: 1rem 1.25rem;
        gap: 0.75rem;
        border-top: 1px solid var(--color-border);
    }

    .nav-dropdown-toggle {
        padding: 0.35rem 0.5rem;
        font-size: 0.78rem;
    }

    .nav-company-name {
        max-width: none;
    }

    .nav-user-name {
        max-width: none;
    }

    .btn-sm {
        padding: 0.3rem 0.55rem;
        font-size: 0.75rem;
    }

    /* Tab bars: horizontal scroll */
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin-bottom: 0.75rem;
    }

    .tab-bar::-webkit-scrollbar {
        display: none;
    }

    .tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.82rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .sub-tab-bar {
        margin-left: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin-bottom: 0.75rem;
    }

    .sub-tab-bar::-webkit-scrollbar {
        display: none;
    }

    .sub-tab {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Record cards: landscape image on mobile */
    .record-card-img,
    .record-card-img-placeholder {
        aspect-ratio: 4/3;
    }

    /* Search bar */
    .search-bar input {
        padding: 0.7rem 0.85rem 0.7rem 2.4rem;
        font-size: 0.9rem;
    }

    .search-bar .search-icon {
        left: 0.65rem;
    }

    /* Results header */
    .results-header {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    /* Main content tighter padding */
    .main-content {
        padding: 0.75rem;
    }

    /* Filter panel */
    .filter-panel {
        padding: 1rem;
    }

    /* Form rows stack on mobile */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Mobile text helpers */
    .hide-mobile { display: none; }
    .show-mobile { display: inline; }

    /* Record detail */
    .record-header h1 {
        font-size: 1.25rem;
    }

    .identity-fields {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .identity-field {
        padding: 0.5rem 0.5rem;
    }

    .identity-age {
        display: block;
    }

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

    .record-meta-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .record-meta-timestamps {
        width: 100%;
        justify-content: flex-start;
    }

    .record-meta-ts {
        align-items: flex-start;
    }

    /* Type selector pills scroll */
    .type-selector {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .type-selector::-webkit-scrollbar {
        display: none;
    }

    .type-pill {
        flex: 0 0 auto;
        min-width: 0;
        padding: 0.5rem 0.75rem;
        font-size: 0.82rem;
    }

    /* Toast notifications */
    .toast-container {
        left: 0.75rem;
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .toast {
        max-width: 100%;
    }

    /* Live refresh banner floating mobile */
    .live-refresh-banner--floating {
        left: 0.75rem;
        right: 0.75rem;
        transform: none;
        max-width: none;
    }

    /* Modal */
    .modal {
        margin: 0.5rem;
    }

    /* Footer */
    .site-footer {
        padding: 1.25rem 0.75rem;
    }

    /* Image upload */
    .image-preview-list {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    /* Gallery */
    .gallery-main {
        aspect-ratio: 4/3;
    }

    /* Plate lookup */
    .plate-lookup-row {
        flex-direction: column;
    }

    .plate-lookup-row .btn {
        min-width: unset;
    }
}

/* === Small phones (up to 400px) === */
@media (max-width: 400px) {
    .nav-logo {
        font-size: 0.95rem;
    }

    .nav-logo svg {
        width: 22px;
        height: 22px;
    }

    .nav-actions {
        gap: 0.35rem;
        padding: 0.4rem 0.5rem;
    }

    .nav-company-name {
        max-width: none;
    }

    .nav-user-name {
        max-width: none;
    }

    .record-card-img,
    .record-card-img-placeholder {
        aspect-ratio: 16/10;
    }

    .tab {
        padding: 0.45rem 0.6rem;
        font-size: 0.78rem;
    }

    .sub-tab {
        padding: 0.35rem 0.5rem;
        font-size: 0.76rem;
    }

    .identity-field {
        padding: 0.4rem 0.35rem;
        font-size: 0.82rem;
    }

    .identity-field .detail-label {
        font-size: 0.65rem;
    }

    .identity-field .detail-value {
        font-size: 0.82rem;
    }

    .identity-age {
        font-size: 0.7rem;
    }
}

/* === Larger phones (480px+) === */
@media (min-width: 480px) and (max-width: 767px) {
    .record-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .record-card-img,
    .record-card-img-placeholder {
        aspect-ratio: 1;
    }
}

/* === Tablet (768px+) === */
@media (min-width: 768px) {
    .record-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filter-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem 1.5rem;
    }

    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-group.full-width {
        grid-column: 1 / -1;
    }

    .nav-bar {
        padding: 0.75rem 2rem;
    }

    .main-content {
        padding: 1.5rem 2rem;
    }
}

/* === Desktop (1024px+) === */
@media (min-width: 1024px) {
    .record-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .search-layout {
        display: grid;
        grid-template-columns: 280px 1fr;
        gap: 1.5rem;
    }

    .search-layout .filter-panel {
        display: block;
        position: sticky;
        top: 80px;
        align-self: start;
    }

    .search-layout .filter-panel .filter-grid {
        grid-template-columns: 1fr;
    }

    .filter-toggle {
        display: none;
    }

    .detail-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* === Admin Mobile === */
@media (max-width: 767px) {
    .admin-menu-toggle {
        display: flex;
    }

    .admin-menu-toggle ~ .nav-logo {
        border-bottom: none;
        padding: 0;
        width: auto;
        justify-content: flex-start;
    }

    .nav-left {
        flex-shrink: 0;
    }

    .admin-menu-toggle ~ .nav-logo ~ .nav-actions,
    body:has(.admin-menu-toggle) .nav-bar {
        flex-direction: row;
        padding: 0.5rem 0.75rem;
        align-items: center;
        justify-content: space-between;
    }

    body:has(.admin-menu-toggle) .nav-actions {
        flex-wrap: nowrap;
        width: auto;
        padding: 0;
    }

    body:has(.admin-menu-toggle) .nav-user-label {
        display: none;
    }

    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 199;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s, visibility 0.25s;
    }
    .admin-sidebar-overlay.open {
        opacity: 1;
        visibility: visible;
    }

    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 200;
        border-right: 1px solid var(--color-border);
        padding: 1.25rem 0;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
    }
    .admin-sidebar.open {
        transform: translateX(0);
    }

    .admin-nav {
        flex-direction: column;
        gap: 2px;
    }

    .admin-nav-item {
        border-left: 3px solid transparent;
        padding: 0.7rem 1rem 0.7rem 1.15rem;
        font-size: 0.9rem;
    }
    .admin-nav-item.active {
        border-left-color: var(--color-primary);
        border-bottom-color: transparent;
    }

    .admin-main {
        padding: 0.85rem;
    }
    .admin-main h1 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    /* Admin toolbar stacking */
    .admin-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }
    .admin-toolbar h1 {
        margin-bottom: 0;
    }

    .admin-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-filter-bar-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .admin-filter-bar-inner label {
        margin-bottom: -0.25rem;
    }

    .admin-filter-bar-inner select {
        min-width: unset;
        width: 100%;
    }

    .admin-filter-count {
        text-align: right;
    }

    .report-filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .report-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }

    .report-actions {
        justify-content: flex-start;
    }

    .financial-cards {
        grid-template-columns: 1fr 1fr;
    }

    .financial-card {
        padding: 0.75rem 0.85rem;
    }

    .financial-card-value {
        font-size: 1.05rem;
    }

    /* Records toolbar (all-records page) */
    .records-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    /* Admin search input */
    .admin-search-input {
        width: 100% !important;
    }

    /* Audit log filters */
    .audit-filters {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    .audit-filter-selects {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }
    .audit-select {
        flex: 1;
        min-width: 0;
    }
    .audit-filter-actions {
        display: flex;
        gap: 0.5rem;
    }
    .audit-filter-actions .btn {
        flex: 1;
    }

    /* All-records tabs */
    .admin-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .admin-tabs::-webkit-scrollbar {
        display: none;
    }

    /* Admin stats on mobile */
    .admin-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .admin-stat-card {
        padding: 0.85rem;
    }
    .admin-stat-value {
        font-size: 1.5rem;
    }
    .admin-stat-label {
        font-size: 0.7rem;
    }

    /* Convert tables to stacked cards on mobile */
    .admin-table-wrap {
        overflow-x: visible;
    }
    .admin-table thead {
        display: none;
    }
    .admin-table,
    .admin-table tbody {
        display: block;
        width: 100%;
    }
    .admin-table tr {
        display: block;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        padding: 0.75rem;
        margin-bottom: 0.6rem;
    }
    .admin-table tr:hover td {
        background: transparent;
    }
    .admin-table td {
        display: flex;
        align-items: baseline;
        padding: 0.25rem 0;
        border-bottom: none;
        font-size: 0.85rem;
        gap: 0.5rem;
    }
    .admin-table td::before {
        content: attr(data-label);
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        color: var(--color-text-muted);
        flex-shrink: 0;
        min-width: 5.5rem;
    }
    /* Actions row: wrap buttons */
    .admin-table td[data-label="Actions"] {
        padding-top: 0.5rem;
        margin-top: 0.25rem;
        border-top: 1px solid var(--color-border);
        flex-wrap: wrap;
    }

    /* Admin forms */
    .admin-form {
        padding: 1rem;
    }

    /* Pagination */
    .admin-main > div:last-child {
        flex-wrap: wrap;
    }

    .permission-module-toggle strong {
        font-size: 0.72rem;
    }
    .permission-item {
        font-size: 0.78rem;
        padding: 0.25rem 0.75rem 0.25rem 1.5rem;
    }
}

/* Audit log filter components */
.audit-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}
.audit-filter-selects {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.audit-select {
    padding: 0.4rem 0.6rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.85rem;
}
.audit-filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Admin search input */
.admin-search-input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 0.9rem;
    width: 250px;
    background: var(--color-bg);
    color: var(--color-text);
}

/* Pub bans card reason */
.record-card-reason {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Suspect search dropdown in form */
.suspect-search-container {
    position: relative;
}

.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg-tertiary);
}

.selected-item {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.selected-name {
    font-weight: 500;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0 0.25rem;
}

.btn-remove:hover {
    color: var(--text-danger);
}

/* === Notes Thread === */
.notes-thread {
    margin-top: 0.5rem;
}

.notes-messages {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-right: 0.25rem;
}

.notes-messages::-webkit-scrollbar {
    width: 4px;
}

.notes-messages::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.notes-loading,
.notes-empty {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    padding: 1.5rem 0;
}

.note-message {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.75rem;
}

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
    gap: 0.5rem;
}

.note-author {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-company {
    font-weight: 400;
    color: var(--color-text-muted);
}

.note-time {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.note-body {
    font-size: 0.9rem;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.note-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.note-delete-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.note-message:hover .note-delete-btn {
    opacity: 1;
}

.note-delete-btn:hover {
    color: var(--color-danger, #dc3545);
}

.notes-composer {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.notes-composer textarea {
    flex: 1;
    resize: vertical;
    min-height: 2.5rem;
    max-height: 8rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s;
}

.notes-composer textarea:focus {
    border-color: var(--color-primary);
}

.notes-composer .btn {
    flex-shrink: 0;
    height: 2.5rem;
}

.notes-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
}

.notes-page-info {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    min-width: 6rem;
    text-align: center;
}

/* === Support Ticketing System === */

.support-container {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.support-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.support-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.support-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.support-filters select {
    padding: 0.4rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.85rem;
}

.ticket-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ticket-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-decoration: none;
    color: inherit;
}

.ticket-row:hover {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
    color: inherit;
}

.ticket-row.has-unread {
    border-left: 3px solid var(--color-primary);
}

.ticket-info {
    flex: 1;
    min-width: 0;
}

.ticket-subject {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ticket-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    flex-wrap: wrap;
}

.ticket-number {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.ticket-badges {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-open { background: rgba(108, 141, 250, 0.15); color: #6c8dfa; }
.badge-in_progress { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.badge-waiting_on_user { background: rgba(139, 143, 163, 0.15); color: #8b8fa3; }
.badge-resolved { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.badge-closed { background: rgba(139, 143, 163, 0.1); color: #6b7280; }

.badge-low { background: rgba(139, 143, 163, 0.1); color: #8b8fa3; }
.badge-medium { background: rgba(108, 141, 250, 0.15); color: #6c8dfa; }
.badge-high { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.badge-critical { background: rgba(240, 82, 82, 0.15); color: #f05252; }

.badge-category { background: rgba(108, 141, 250, 0.1); color: var(--color-text-muted); }

.reply-count {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.ticket-detail-header {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.ticket-detail-title {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.ticket-detail-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
}

.ticket-detail-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.ticket-detail-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.ticket-detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ticket-detail-value {
    font-size: 0.9rem;
    color: var(--color-text);
}

.ticket-description {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
    white-space: pre-wrap;
    line-height: 1.7;
}

.reply-thread {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.reply-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
}

.reply-item.internal-note {
    border-left: 3px solid var(--color-warning);
    background: rgba(251, 191, 36, 0.03);
}

.reply-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.reply-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    color: white;
    flex-shrink: 0;
}

.reply-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.reply-author {
    font-weight: 500;
    font-size: 0.9rem;
}

.reply-time {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-left: auto;
}

.reply-internal-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-warning);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reply-message {
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 0.9rem;
}

.reply-attachments {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

.attachment-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: border-color 0.15s;
}

.attachment-thumb:hover {
    border-color: var(--color-primary);
}

.attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--color-text);
    text-decoration: none;
    transition: border-color 0.15s;
}

.attachment-file:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.attachment-file-icon {
    width: 16px;
    height: 16px;
    opacity: 0.6;
}

.attachment-file-size {
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.reply-composer {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.reply-composer textarea {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 0.75rem;
}

/* ============================================================
   Private Messaging
   ------------------------------------------------------------
   Layout invariants:
   - .messages-page is a 2-column grid filling the viewport
     vertically. The right column (.messages-thread) is a flex
     column, so .messages-thread-active can flex its body
     region to fill the remaining height between header and
     composer.
   - The [hidden] attribute is authoritative for showing/hiding
     .messages-thread-empty and .messages-thread-active. Without
     `!important` here, the explicit `display: flex` on those
     rules would beat the user-agent's [hidden] { display: none }
     and the hidden panel would still claim layout space (the
     cause of the original "empty area eats the thread" bug).
   ============================================================ */
.messages-page [hidden] { display: none !important; }

.messages-page {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: 1fr;
    gap: 1px;
    background: var(--color-border);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    overflow: hidden;
    height: calc(100vh - 200px);
    height: calc(100dvh - 200px);   /* match the visible viewport on mobile */
    min-height: 480px;
    max-width: 1100px;
    margin: 1.5rem auto;
}
.messages-sidebar {
    background: var(--color-surface);
    display: flex; flex-direction: column; min-height: 0;
    min-width: 0;
}
.messages-sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.875rem 1rem; border-bottom: 1px solid var(--color-border);
}
.messages-sidebar-header h1 {
    font-size: 0.78rem; font-weight: 700; letter-spacing: 0.14em;
    text-transform: uppercase; color: var(--color-text-muted);
    margin: 0;
}
.messages-search { padding: 0.75rem; border-bottom: 1px solid var(--color-border); }
.messages-search input {
    width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--color-border);
    border-radius: 6px; background: var(--color-bg); color: var(--color-text); font: inherit;
}
.messages-search-results { margin-top: 0.5rem; max-height: 240px; overflow-y: auto; }
.messages-search-result {
    display: flex; align-items: center; gap: 0.5rem; width: 100%; padding: 0.5rem;
    border: 0; background: none; color: var(--color-text); cursor: pointer; border-radius: 6px; text-align: left;
}
.messages-search-result:hover { background: var(--color-surface-hover); }
.messages-search-result .messages-conversation-avatar { width: 28px; height: 28px; }
.messages-conversation-list { flex: 1; overflow-y: auto; min-height: 0; }
.messages-empty { padding: 2rem 1rem; text-align: center; color: var(--color-text-muted); font-size: 0.85rem; }
.messages-thread-empty {
    display: flex; align-items: center; justify-content: center; height: 100%;
    color: var(--color-text-muted); font-size: 0.9rem; letter-spacing: 0.02em;
}
.messages-thread-empty p::before {
    content: ""; display: block; width: 32px; height: 1px;
    background: var(--color-border); margin: 0 auto 0.875rem;
}
.messages-conversation {
    display: flex; align-items: center; gap: 0.75rem; width: 100%;
    padding: 0.7rem 1rem; border: 0; border-bottom: 1px solid var(--color-border);
    background: none; color: var(--color-text); cursor: pointer; text-align: left;
    position: relative;
}
.messages-conversation:hover { background: var(--color-surface-hover); }
.messages-conversation.active {
    background: var(--color-surface-hover);
}
.messages-conversation.active::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0;
    width: 2px; background: var(--color-primary);
}
.messages-conversation.unread .messages-conversation-name { font-weight: 700; }
.messages-conversation-avatar {
    width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-primary); color: #fff; font-weight: 600;
    border: 1px solid transparent;
}
.messages-conversation-avatar img { width: 100%; height: 100%; object-fit: cover; }
.messages-conversation-meta { flex: 1; min-width: 0; }
.messages-conversation-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.messages-conversation-name {
    font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.messages-conversation-time {
    font-size: 0.7rem; color: var(--color-text-muted); flex-shrink: 0;
    font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}
.messages-conversation-preview {
    font-size: 0.82rem; color: var(--color-text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 0.15rem;
}
.messages-conversation-dot {
    flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--color-primary); color: #fff; font-size: 0.7rem;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}

/* Thread column. The grid row is 1fr so the thread fills the
   full height of the page; inside, header (auto) and composer
   (auto) are pinned, body (flex:1) takes the rest. */
.messages-thread {
    background: var(--color-bg);
    display: flex; flex-direction: column;
    height: 100%; min-height: 0; min-width: 0;
    position: relative;
}
.messages-thread-active {
    display: flex; flex-direction: column;
    flex: 1 1 auto; min-height: 0; width: 100%;
}
.messages-thread-header {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    flex: 0 0 auto;
}
.messages-thread-avatar {
    width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-primary); color: #fff; font-weight: 600;
    position: relative;
    border: 1px solid var(--color-border);
}
.messages-thread-avatar img { width: 100%; height: 100%; object-fit: cover; }
.messages-thread-avatar::after {
    /* Status dot. Green = online. Purely visual; we don't track
       presence in v1, so it's a static "reachable" indicator. */
    content: ""; position: absolute; right: 0; bottom: 0;
    width: 9px; height: 9px; border-radius: 50%;
    background: #34d399; border: 2px solid var(--color-surface);
}
.messages-thread-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.messages-thread-name {
    font-weight: 600; font-size: 0.95rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.2;
}
.messages-thread-role {
    font-size: 0.7rem; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: 0.1em;
    font-weight: 500;
    margin-top: 0.1rem;
}
.messages-back-btn {
    display: none; border: 0; background: none;
    color: var(--color-text-muted); font-size: 1.25rem;
    cursor: pointer; padding: 0.25rem 0.5rem; margin-left: -0.5rem;
    border-radius: 4px;
}
.messages-back-btn:hover { color: var(--color-text); background: var(--color-surface-hover); }

.messages-thread-body {
    flex: 1 1 0;
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;   /* momentum scrolling on iOS */
    overscroll-behavior: contain;        /* don't drag the whole page */
    padding: 1.25rem 1rem;
    display: flex; flex-direction: column; gap: 0.4rem;
    min-height: 0;
    scroll-behavior: smooth;
}

/* Day separators — added by the JS as messages are rendered.
   Visually a hairline rule with the date sitting on top in
   small-caps monospace. The `position: relative` on the parent
   body lets the rule use negative margin to bleed edge-to-edge. */
.messages-day-sep {
    align-self: center;
    display: flex; align-items: center; gap: 0.75rem;
    margin: 0.5rem 0 0.25rem;
    color: var(--color-text-muted);
    font-size: 0.68rem; letter-spacing: 0.18em; text-transform: uppercase;
    font-variant-numeric: tabular-nums;
    width: 100%;
}
.messages-day-sep::before,
.messages-day-sep::after {
    content: ""; flex: 1; height: 1px; background: var(--color-border);
}

.messages-bubble-row {
    display: flex; flex-direction: column;
    max-width: min(560px, 75%);
    min-width: 0;
    transition: opacity 0.15s ease;
}
.messages-bubble-row.mine {
    align-self: flex-end; align-items: flex-end;
}
.messages-bubble-row.theirs {
    align-self: flex-start; align-items: flex-start;
    flex-direction: row; gap: 0.5rem;
}
.messages-bubble-row.theirs .messages-bubble-stack {
    display: flex; flex-direction: column; align-items: flex-start;
    min-width: 0; max-width: 100%;
}
.messages-bubble-row.theirs .messages-bubble-avatar {
    width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
    background: var(--color-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 0.75rem;
    align-self: flex-end; margin-bottom: 0.15rem;
    overflow: hidden;
}
.messages-bubble-row.theirs .messages-bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }

.messages-bubble {
    padding: 0.55rem 0.85rem;
    border-radius: 14px;
    white-space: pre-wrap; word-break: break-word;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    line-height: 1.4;
    font-size: 0.92rem;
    /* Subtle texture vs flat color */
    box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
.messages-bubble-row.mine .messages-bubble {
    background: var(--color-primary); color: #fff; border-color: var(--color-primary);
    border-bottom-right-radius: 4px;
}
.messages-bubble-row.theirs .messages-bubble {
    border-bottom-left-radius: 4px;
}
.messages-bubble-time {
    font-size: 0.68rem; color: var(--color-text-muted);
    margin-top: 0.2rem;
    font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
    padding: 0 0.25rem;
}
.messages-bubble-row.mine .messages-bubble-time { text-align: right; }

/* Optimistic outgoing message: muted until the server confirms it. .failed
   marks a send the server rejected or that never completed. */
.messages-bubble-row.pending { opacity: 0.55; }
.messages-bubble-row.pending .messages-bubble-time { font-style: italic; }
.messages-bubble-row.failed .messages-bubble-time { color: var(--color-danger); }

.messages-composer {
    display: flex; gap: 0.5rem; padding: 0.75rem 1rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    flex: 0 0 auto;
}
.messages-composer textarea {
    flex: 1; resize: none; max-height: 120px; padding: 0.55rem 0.85rem;
    border: 1px solid var(--color-border); border-radius: 10px;
    background: var(--color-bg); color: var(--color-text); font: inherit;
    line-height: 1.4;
}
.messages-composer textarea:focus {
    outline: none; border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.18);
}
.messages-avatar-initials { font-size: 0.95rem; }
.nav-messages-badge {
    display: none; margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; background: var(--color-primary); color: #fff; font-size: 0.7rem;
    align-items: center; justify-content: center;
}

@media (max-width: 900px) {
    .messages-page { grid-template-columns: 1fr; height: calc(100vh - 140px); height: calc(100dvh - 140px); margin: 0; border-radius: 0; border-left: 0; border-right: 0; }
    .messages-thread { display: none; }
    .messages-page.thread-open .messages-sidebar { display: none; }
    .messages-page.thread-open .messages-thread { display: flex; }
    .messages-back-btn { display: inline-block; }
}

.reply-composer textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.reply-composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.reply-type-toggle {
    display: flex;
    gap: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.reply-type-btn {
    padding: 0.4rem 0.75rem;
    border: none;
    background: var(--color-bg);
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.reply-type-btn.active {
    background: var(--color-primary);
    color: white;
}

.reply-type-btn:hover:not(.active) {
    background: var(--color-surface-hover);
}

.attachment-input-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    transition: color 0.15s;
}

.attachment-input-wrapper:hover {
    color: var(--color-primary);
}

.attachment-input-wrapper input[type="file"] {
    display: none;
}

.attachment-preview-list {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.attachment-preview-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 0.8rem;
}

.attachment-preview-remove {
    background: none;
    border: none;
    color: var(--color-danger);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}

.support-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 2rem;
    max-width: 700px;
    margin: 2rem auto;
}

.support-form h1 {
    font-size: 1.35rem;
    margin-bottom: 1.5rem;
}

.support-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.support-stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    text-align: center;
}

.support-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.support-stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.admin-ticket-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.admin-ticket-actions select {
    padding: 0.4rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.85rem;
}

.support-pagination {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 1.5rem;
}

.support-pagination button {
    padding: 0.4rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s, border-color 0.15s;
}

.support-pagination button:hover:not(:disabled) {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
}

.support-pagination button.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.support-pagination button:disabled {
    opacity: 0.4;
    cursor: default;
}

.support-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.support-empty p {
    margin-bottom: 1rem;
}

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

.category-table th,
.category-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.category-table th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.category-table td {
    font-size: 0.9rem;
}

.category-actions {
    display: flex;
    gap: 0.5rem;
}

/* Canned Response Dropdown */
.canned-response-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.canned-response-select select {
    padding: 0.4rem 2rem 0.4rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8fa3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    cursor: pointer;
    transition: border-color 0.15s;
}

.canned-response-select select:hover {
    border-color: var(--color-text-muted);
}

.canned-response-select select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.canned-response-select select option {
    background: var(--color-surface);
    color: var(--color-text);
}

@media (max-width: 640px) {
    .ticket-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .ticket-badges {
        width: 100%;
    }
    .support-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .ticket-detail-info {
        grid-template-columns: 1fr 1fr;
    }
}

/* Notification Bell */
.nav-notification-bell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-notification-bell:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}
.nav-notification-bell svg {
    width: 20px;
    height: 20px;
}
.nav-notification-bell.has-unread {
    color: var(--color-primary);
    border-color: var(--color-primary);
}
.nav-notification-bell.pulse svg {
    animation: bell-pulse 0.6s ease;
}
@keyframes bell-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.nav-notification-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--color-danger);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.nav-notification-badge:empty {
    display: none;
}

/* Notification Dropdown */
.nav-notification-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 360px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 200;
    display: none;
    overflow: hidden;
}
.nav-notification-dropdown.open {
    display: block;
}
.nav-notification-dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
}
.nav-notification-dropdown-header h3 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}
.nav-notification-dropdown-header a {
    font-size: 0.8rem;
    color: var(--color-primary);
    text-decoration: none;
    cursor: pointer;
}
.nav-notification-dropdown-header a:hover {
    text-decoration: underline;
}
.nav-notification-list {
    max-height: 320px;
    overflow-y: auto;
}
.nav-notification-item {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.1s;
    text-decoration: none;
    color: var(--color-text);
}
.nav-notification-item:last-child {
    border-bottom: none;
}
.nav-notification-item:hover {
    background: var(--color-surface-hover);
}
.nav-notification-item.unread {
    background: rgba(108, 141, 250, 0.08);
}
.nav-notification-item-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
}
.nav-notification-item-icon svg {
    width: 16px;
    height: 16px;
}
.nav-notification-item-content {
    flex: 1;
    min-width: 0;
}
.nav-notification-item-message {
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-notification-item.unread .nav-notification-item-message {
    font-weight: 500;
}
.nav-notification-item-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}
.nav-notification-item-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
    margin-top: 0.35rem;
}
.nav-notification-item:not(.unread) .nav-notification-item-dot {
    display: none;
}
.nav-notification-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}
.nav-notification-dropdown-footer {
    border-top: 1px solid var(--color-border);
    padding: 0.65rem 1rem;
    text-align: center;
}
.nav-notification-dropdown-footer a {
    font-size: 0.85rem;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}
.nav-notification-dropdown-footer a:hover {
    text-decoration: underline;
}

/* Notification Center Page */
.notification-center {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
}
.notification-center-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.notification-center-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}
.notification-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.notification-filters select {
    padding: 0.5rem 0.75rem;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: var(--font-sans);
}
.notification-filters select:focus {
    border-color: var(--color-primary);
    outline: none;
}
.notification-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.notification-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color 0.15s;
    text-decoration: none;
    color: var(--color-text);
}
.notification-row:hover {
    border-color: var(--color-primary);
}
.notification-row.unread {
    border-left: 3px solid var(--color-primary);
    background: rgba(108, 141, 250, 0.05);
}
.notification-row-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
}
.notification-row-icon svg {
    width: 18px;
    height: 18px;
}
.notification-row-content {
    flex: 1;
    min-width: 0;
}
.notification-row-message {
    font-size: 0.95rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.notification-row.unread .notification-row-message {
    font-weight: 500;
}
.notification-row-subject {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.notification-row-time {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    margin-top: 0.15rem;
}
.notification-row-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}
.notification-row-actions button {
    background: none;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.55rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.notification-row-actions button:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}
.notification-row-actions .btn-delete:hover {
    color: var(--color-danger);
    border-color: var(--color-danger);
}
.notification-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}
.notification-empty h2 {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--color-text);
    margin: 0 0 0.5rem;
}
.notification-empty p {
    font-size: 0.9rem;
    margin: 0;
}
.notification-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
    margin-top: 1.5rem;
}
.notification-pagination button {
    padding: 0.5rem 0.85rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
}
.notification-pagination button:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
}
.notification-pagination button:disabled {
    opacity: 0.4;
    cursor: default;
}
.notification-pagination .page-info {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    padding: 0 0.75rem;
}
