/* style.css - SudaRads PACS Dashboard Styles - UPDATED */

/* =========================================
   1. CSS CUSTOM PROPERTIES (VARIABLES)
   ========================================= */
:root { 
    /* Base Colors */
    --suda-bg: #000000;
    --suda-surface: #0d0d0d;
    --suda-surface-elevated: #151515;
    --suda-surface-hover: #1a1a1a;
    --suda-border: rgba(255, 255, 255, 0.08);
    --suda-border-light: rgba(255, 255, 255, 0.12);
    
    /* Text */
    --suda-text: #e8e8e8;
    --suda-text-secondary: #888;
    --suda-text-muted: #555;
    
    /* Soothing Accent Colors (matching worklist) */
    --accent-indigo: 99, 102, 241;
    --accent-teal: 6, 182, 212;
    --accent-amber: 245, 158, 11;
    --accent-emerald: 16, 185, 129;
    --accent-violet: 139, 92, 246;
    --accent-soft-red: 239, 68, 68;
    --accent-pink: 236, 72, 153;
    --accent-cyan: 34, 211, 238;
    
    /* Primary/Secondary (updated to match) */
    --suda-primary: rgb(var(--accent-indigo));
    --suda-primary-rgb: var(--accent-indigo);
    --suda-secondary: #1e1e1e;
    --suda-success: rgb(var(--accent-emerald));
    --suda-danger: rgb(var(--accent-soft-red));
    --suda-warning: rgb(var(--accent-amber));
    --suda-info: rgb(var(--accent-teal));
    
    /* Glassmorphism */
    --glass-bg: rgba(15, 15, 15, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    
    /* Spacing */
    --navbar-height: 60px;
    --container-padding: 1.5rem;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* =========================================
   2. BASE STYLES
   ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow-y: auto !important;
    scroll-behavior: smooth;
}

body { 
    background-color: var(--suda-bg) !important;
    color: var(--suda-text);
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
    height: auto !important; 
    overflow-y: auto !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Main Container */
.main-container, #main-container {
    background-color: transparent !important;
    padding: var(--container-padding);
    padding-top: calc(var(--navbar-height) + 1rem);
    min-height: calc(100vh - var(--navbar-height));
    max-width: 1400px;
    margin: 0 auto;
}

/* =========================================
   3. NAVIGATION & HEADER - GLOSSY BLACK
   ========================================= */
.top-navbar { 
    background: linear-gradient(180deg, rgba(20, 20, 20, 0.95), rgba(10, 10, 10, 0.98));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 0.5rem 1rem;
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.5),
        0 1px 0 rgba(255, 255, 255, 0.03) inset;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    height: var(--navbar-height);
}

/* Rounded bottom corners for navbar */
@supports (backdrop-filter: blur(12px)) {
    .top-navbar {
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
        margin: 0 8px;
        width: calc(100% - 16px);
        top: 8px;
    }
    
    .main-container, #main-container {
        padding-top: calc(var(--navbar-height) + 1.5rem);
    }
}

/* ─────────────────────────────────────────────────────────────────────────────
   [NAV-ELECTRON-FIX 2026-06-24] When these pages render INSIDE the SudaRads Electron
   shell, its custom titlebar (#electron-titlebar, 42px) is injected at the very top and
   adds `has-electron-titlebar` to <body>. Our own .top-navbar is position:fixed, so it
   ignores the body's titlebar padding and renders UNDER the Electron titlebar (overlap).
   Drop the fixed navbar by the 42px titlebar height so the menu sits BELOW it — matching
   the Electron app's offline pages. The body already adds 42px padding, so content
   clearance is preserved automatically (no content-padding change needed). In a normal
   browser the class is never present, so this is a no-op there.
   RESTORE: delete this block.
   ───────────────────────────────────────────────────────────────────────────── */
body.has-electron-titlebar .top-navbar { top: var(--tb-height, 42px); z-index: calc(var(--z-titlebar, 13000) - 1); }
@supports (backdrop-filter: blur(12px)) {
    body.has-electron-titlebar .top-navbar { top: calc(var(--tb-height, 42px) + 8px); }
}
/* Electron titlebar collapsed → its bar height is 0; return the navbar to the top. */
body.has-electron-titlebar.titlebar-collapsed .top-navbar { top: 0; z-index: calc(var(--z-titlebar, 13000) - 1); }
@supports (backdrop-filter: blur(12px)) {
    body.has-electron-titlebar.titlebar-collapsed .top-navbar { top: 8px; }
}
/* Hide duplicate titlebar user/network when the app navbar is visible; keep update pill */
body.has-electron-titlebar:not(.titlebar-collapsed) #electron-titlebar .tb-user,
body.has-electron-titlebar:not(.titlebar-collapsed) #electron-titlebar .tb-network {
    display: none !important;
}
body.has-electron-titlebar #electron-titlebar .tb-update {
    display: inline-flex !important;
}

.navbar {
    padding: 0;
}

.navbar-brand { 
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--suda-text) !important;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.navbar-brand:hover {
    color: rgb(var(--accent-teal)) !important;
}

.navbar-brand img {
    border-radius: 6px;
}

/* Hamburger Menu */
.navbar-toggler {
    border: 1px solid var(--suda-border-light);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 3px rgba(var(--accent-indigo), 0.25);
}

.navbar-toggler-icon {
    filter: invert(0.8);
}

/* Nav Links */
.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.main-nav .nav-link { 
    color: var(--suda-text-secondary);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    position: relative;
}

.main-nav .nav-link:hover { 
    color: var(--suda-text);
    background: rgba(255, 255, 255, 0.05);
}

.main-nav .nav-link.active,
.main-nav .nav-link:active {
    background: linear-gradient(135deg, rgba(var(--accent-indigo), 0.2), rgba(var(--accent-indigo), 0.1));
    color: rgb(var(--accent-indigo));
}

.main-nav .nav-link i {
    margin-right: 6px;
}

/* User Dropdown */
.user-dropdown .btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--suda-border);
    color: var(--suda-text);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    transition: all 0.2s ease;
}

.user-dropdown .btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--suda-border-light);
}

.user-dropdown .dropdown-menu { 
    background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--glass-shadow);
    min-width: 220px;
    padding: 8px;
    margin-top: 8px;
}

.user-dropdown .dropdown-item {
    color: var(--suda-text);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: all 0.15s ease;
}

.user-dropdown .dropdown-item:hover {
    background: rgba(var(--accent-indigo), 0.15);
    color: rgb(var(--accent-indigo));
}

.user-dropdown .dropdown-item i {
    margin-right: 8px;
    opacity: 0.7;
}

.user-dropdown .dropdown-item-text {
    color: var(--suda-text-secondary);
    font-size: 12px;
    padding: 8px 14px;
}

.user-dropdown .dropdown-divider {
    border-color: var(--suda-border);
    margin: 6px 0;
}

/* Fullscreen Button */
#mainFullscreenToggle {
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--suda-border) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--suda-text-secondary) !important;
    transition: all 0.2s ease !important;
}

#mainFullscreenToggle:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    color: var(--suda-text) !important;
}

/* =========================================
   4. BUTTONS - SOOTHING COLORS
   ========================================= */
.btn {
    font-weight: 500;
    font-size: 13px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    padding: 8px 16px;
}

.btn-primary {
    background: linear-gradient(135deg, rgb(var(--accent-indigo)), rgba(var(--accent-indigo), 0.8));
    border: none;
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(135deg, rgba(var(--accent-indigo), 0.9), rgba(var(--accent-indigo), 0.7));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--accent-indigo), 0.3);
}

.btn-outline-primary { 
    border-color: rgba(var(--accent-indigo), 0.5);
    color: rgb(var(--accent-indigo));
    background: transparent;
}

.btn-outline-primary:hover { 
    background: rgba(var(--accent-indigo), 0.1);
    border-color: rgb(var(--accent-indigo));
    color: rgb(var(--accent-indigo));
    transform: translateY(-1px);
}

.btn-success {
    background: linear-gradient(135deg, rgb(var(--accent-emerald)), rgba(var(--accent-emerald), 0.8));
    border: none;
}

.btn-success:hover {
    background: linear-gradient(135deg, rgba(var(--accent-emerald), 0.9), rgba(var(--accent-emerald), 0.7));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--accent-emerald), 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, rgb(var(--accent-soft-red)), rgba(var(--accent-soft-red), 0.8));
    border: none;
}

.btn-danger:hover {
    background: linear-gradient(135deg, rgba(var(--accent-soft-red), 0.9), rgba(var(--accent-soft-red), 0.7));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--accent-soft-red), 0.3);
}

.btn-warning {
    background: linear-gradient(135deg, rgb(var(--accent-amber)), rgba(var(--accent-amber), 0.8));
    border: none;
    color: #000;
}

.btn-info {
    background: linear-gradient(135deg, rgb(var(--accent-teal)), rgba(var(--accent-teal), 0.8));
    border: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--suda-border);
    color: var(--suda-text);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--suda-border-light);
}

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

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--suda-text);
}

/* =========================================
   5. CARDS - GLOSSY BLACK
   ========================================= */
.card {
    background: linear-gradient(145deg, var(--suda-surface-elevated), var(--suda-surface));
    border: 1px solid var(--suda-border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.card:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    border-color: var(--suda-border-light);
}

.card-header {
    background: linear-gradient(135deg, #1a1a1a, #141414);
    border-bottom: 1px solid var(--suda-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
    font-weight: 600;
    font-size: 14px;
    padding: 14px 18px;
}

.card-body {
    color: var(--suda-text);
    padding: 18px;
}

.card-footer {
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--suda-border);
    border-radius: 0 0 var(--radius-md) var(--radius-md) !important;
}

/* =========================================
   6. FORMS - DARK THEME
   ========================================= */
.form-control, .form-select {
    background: var(--suda-surface);
    border: 1px solid var(--suda-border);
    color: var(--suda-text);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    background: var(--suda-surface-elevated);
    border-color: rgb(var(--accent-indigo));
    color: var(--suda-text);
    box-shadow: 0 0 0 3px rgba(var(--accent-indigo), 0.15);
}

.form-control::placeholder {
    color: var(--suda-text-muted);
}

.form-label {
    color: var(--suda-text);
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 6px;
}

.form-text {
    color: var(--suda-text-muted);
    font-size: 12px;
}

.form-check-input {
    background-color: var(--suda-surface);
    border-color: var(--suda-border);
}

.form-check-input:checked {
    background-color: rgb(var(--accent-indigo));
    border-color: rgb(var(--accent-indigo));
}

.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(var(--accent-indigo), 0.15);
}

/* =========================================
   7. ALERTS - SOOTHING COLORS
   ========================================= */
.alert {
    border-radius: var(--radius-md);
    border: none;
    padding: 14px 18px;
    font-size: 13px;
}

.alert-success {
    background: rgba(var(--accent-emerald), 0.1);
    color: rgb(var(--accent-emerald));
    border-left: 4px solid rgb(var(--accent-emerald));
}

.alert-danger {
    background: rgba(var(--accent-soft-red), 0.1);
    color: rgb(var(--accent-soft-red));
    border-left: 4px solid rgb(var(--accent-soft-red));
}

.alert-warning {
    background: rgba(var(--accent-amber), 0.1);
    color: rgb(var(--accent-amber));
    border-left: 4px solid rgb(var(--accent-amber));
}

.alert-info {
    background: rgba(var(--accent-teal), 0.1);
    color: rgb(var(--accent-teal));
    border-left: 4px solid rgb(var(--accent-teal));
}

/* =========================================
   8. BADGES
   ========================================= */
.badge {
    font-weight: 500;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
}

.badge.bg-primary { background: rgba(var(--accent-indigo), 0.2) !important; color: rgb(var(--accent-indigo)); }
.badge.bg-success { background: rgba(var(--accent-emerald), 0.2) !important; color: rgb(var(--accent-emerald)); }
.badge.bg-danger { background: rgba(var(--accent-soft-red), 0.2) !important; color: rgb(var(--accent-soft-red)); }
.badge.bg-warning { background: rgba(var(--accent-amber), 0.2) !important; color: rgb(var(--accent-amber)); }
.badge.bg-info { background: rgba(var(--accent-teal), 0.2) !important; color: rgb(var(--accent-teal)); }
.badge.bg-secondary { background: rgba(255, 255, 255, 0.1) !important; color: var(--suda-text-secondary); }

/* =========================================
   9. MODALS & OFFCANVAS - GLOSSY
   ========================================= */
.modal-content {
    background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.modal-header {
    border-bottom: 1px solid var(--suda-border);
    padding: 18px 24px;
}

.modal-title {
    font-weight: 600;
    font-size: 16px;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    border-top: 1px solid var(--suda-border);
    padding: 16px 24px;
}

.btn-close {
    filter: invert(0.7);
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-close:hover {
    opacity: 1;
}

.offcanvas { 
    background: linear-gradient(145deg, #1a1a1a, #0a0a0a);
    border-color: var(--glass-border) !important;
    color: var(--suda-text);
}

.offcanvas-header {
    border-bottom: 1px solid var(--suda-border);
    background: linear-gradient(145deg, #0f0f0f, #000);
    padding: 16px 20px;
}

.offcanvas-title {
    color: rgb(var(--accent-teal));
    font-weight: 600;
}

.offcanvas-body {
    padding: 16px;
}

/* =========================================
   10. TABLES
   ========================================= */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--suda-text);
    --bs-table-border-color: var(--suda-border);
    font-size: 13px;
}

.table > thead {
    background: rgba(0, 0, 0, 0.3);
}

.table > thead th {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--suda-text-muted);
    padding: 12px 16px;
    border-bottom: 1px solid var(--suda-border);
}

.table > tbody > tr {
    transition: background 0.15s ease;
}

.table > tbody > tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.table > tbody td {
    padding: 12px 16px;
    vertical-align: middle;
}

.table-striped > tbody > tr:nth-of-type(odd) {
    background: rgba(255, 255, 255, 0.02);
}

/* =========================================
   11. SPINNERS & INDICATORS
   ========================================= */
.spinner-border {
    color: rgb(var(--accent-indigo));
}

.htmx-indicator {
    display: none;
    position: fixed;
    top: calc(var(--navbar-height) + 20px);
    right: 20px;
    background: linear-gradient(135deg, rgb(var(--accent-indigo)), rgba(var(--accent-indigo), 0.8));
    color: white;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    z-index: 1050;
    box-shadow: 0 4px 15px rgba(var(--accent-indigo), 0.3);
    font-size: 13px;
}

.htmx-request .htmx-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Global loading indicator (#loading, driven by /js/globalLoader.js):
   a thin moving bar at the top edge, plus a small pill for slow requests. */
.global-loader {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.global-loader.is-active { opacity: 1; }
.global-loader.is-finishing { opacity: 0; transition-delay: 0.1s; }
.global-loader-bar {
    height: 3px;
    width: 100%;
    overflow: hidden;
    background: rgba(var(--accent-indigo), 0.15);
}
.global-loader-bar::before {
    content: "";
    display: block;
    height: 100%;
    width: 40%;
    border-radius: 3px;
    background: linear-gradient(90deg, transparent, rgb(var(--accent-indigo)) 35%, rgb(var(--dl-teal, 6, 182, 212)) 100%);
    box-shadow: 0 0 8px rgba(var(--accent-indigo), 0.6);
    animation: global-loader-slide 1.1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.global-loader:not(.is-active) .global-loader-bar::before,
.global-loader:not(.is-active) .global-loader-ring { animation-play-state: paused; }
.global-loader-pill {
    position: absolute;
    top: calc(var(--navbar-height) + 12px);
    left: 50%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    color: #fff;
    background: rgba(17, 24, 39, 0.88);
    border: 1px solid rgba(var(--accent-indigo), 0.45);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    opacity: 0;
    transform: translate(-50%, -8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.global-loader.is-slow .global-loader-pill { opacity: 1; transform: translate(-50%, 0); }
.global-loader-ring {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: rgb(var(--accent-indigo));
    animation: global-loader-spin 0.7s linear infinite;
}
@keyframes global-loader-slide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(260%); }
}
@keyframes global-loader-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .global-loader-bar::before { animation: none; width: 100%; opacity: 0.7; }
    .global-loader-ring { animation-duration: 1.6s; }
}
@media print { .global-loader { display: none !important; } }

/* =========================================
   12. TOAST NOTIFICATIONS
   ========================================= */
#toastContainer { 
    z-index: 1100;
}

.toast {
    background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    color: var(--suda-text);
}

.toast-header {
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid var(--suda-border);
    color: var(--suda-text);
}

/* =========================================
   13. IMAGE VIEWER MODAL
   ========================================= */
#imageViewerModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1050;
}

#imageViewerModal > div {
    background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    position: relative;
    width: 95%;
    height: 95%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#imageViewerModal button {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 1.75rem;
    color: var(--suda-text-secondary);
    cursor: pointer;
    border: none;
    background: none;
    z-index: 1051;
    transition: color 0.2s ease;
    line-height: 1;
}

#imageViewerModal button:hover {
    color: var(--suda-text);
}

#modal-viewer-content {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* =========================================
   14. VIEWER & GRID STYLES
   ========================================= */
.futuristic-container {
    position: relative;
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.8);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: move;
    box-shadow:
        0 0 20px rgba(var(--accent-teal), 0.2),
        0 0 40px rgba(var(--accent-teal), 0.1);
    border: 1px solid rgba(var(--accent-teal), 0.3);
    animation: backlightPulse 3s ease-in-out infinite;
    user-select: none;
}

.main-view-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
    gap: 15px;
    margin-bottom: 15px;
    min-height: 450px;
    border: 2px solid rgba(var(--accent-indigo), 0.3);
    border-radius: var(--radius-md);
    padding: 20px;
    background: transparent !important;
    transition: all 0.3s ease;
    max-width: 100%;
    box-sizing: border-box;
}

.viewport-content {
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.viewport-content img,
.viewport-content canvas {
    position: absolute !important;
    top: 5px !important;
    left: 5px !important;
    width: calc(100% - 10px) !important;
    height: calc(100% - 10px) !important;
    object-fit: contain !important;
    object-position: center !important;
}

.thumbnail-container {
    transition: all 0.3s ease;
    white-space: nowrap;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--accent-indigo), 0.5) rgba(0, 0, 0, 0.1);
}

.thumbnail-container::-webkit-scrollbar {
    height: 6px;
}

.thumbnail-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.thumbnail-container::-webkit-scrollbar-thumb {
    background: rgba(var(--accent-indigo), 0.5);
    border-radius: 3px;
}

/* Sortable Styles */
.sortable-ghost {
    opacity: 0.4;
    background: rgba(var(--accent-teal), 0.1) !important;
    border: 2px dashed rgba(var(--accent-teal), 0.4) !important;
}

.sortable-chosen {
    opacity: 0.8;
    transform: scale(1.05);
    z-index: 1000;
    box-shadow: 0 0 30px rgba(var(--accent-teal), 0.3) !important;
}

.sortable-drag {
    opacity: 0.9;
    transform: rotate(3deg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3) !important;
}

.drop-zone-active {
    border-color: rgb(var(--accent-emerald)) !important;
    background: rgba(var(--accent-emerald), 0.05) !important;
    animation: dropZonePulse 1s ease-in-out infinite;
}

/* Overlays & Indicators */
.wl-indicator, .measurement-indicator, .wl-values {
    position: absolute;
    background: rgba(0, 0, 0, 0.75);
    padding: 4px 8px;
    border-radius: 4px;
    z-index: 1000;
    pointer-events: none;
    font-size: 11px;
    font-family: 'SF Mono', Monaco, monospace;
}

.wl-indicator { top: 10px; right: 10px; color: rgb(var(--accent-amber)); font-weight: 600; }
.measurement-indicator { top: 10px; right: 10px; color: rgb(var(--accent-emerald)); }
.wl-values { bottom: 10px; left: 10px; color: rgb(var(--accent-teal)); }

.controls .wl-indicator, .controls .wl-values, .controls .measurement-indicator {
    font-size: 8px !important;
    padding: 2px 4px !important;
}

/* =========================================
   15. DRAGGABLE REPORT CONTAINER
   ========================================= */
.draggable-container {
    position: fixed;
    z-index: 1040;
    min-width: 300px;
    min-height: 200px;
    display: none;
}

.draggable-container.active {
    display: block;
}

.draggable-header {
    cursor: move;
}

/* =========================================
   16. AI CONFIG TOGGLE
   ========================================= */
#ai-config-toggle {
    background: linear-gradient(135deg, rgb(var(--accent-indigo)), rgba(var(--accent-indigo), 0.8)) !important;
    border: none !important;
    box-shadow: 0 4px 15px rgba(var(--accent-indigo), 0.3);
    transition: all 0.2s ease;
}

#ai-config-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(var(--accent-indigo), 0.4);
}

/* =========================================
   17. ANIMATIONS
   ========================================= */
@keyframes backlightPulse {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 1; }
}

@keyframes dropZonePulse {
    0%, 100% { 
        border-color: rgb(var(--accent-emerald)); 
        box-shadow: 0 0 10px rgba(var(--accent-emerald), 0.2); 
    }
    50% { 
        border-color: rgba(var(--accent-emerald), 0.7); 
        box-shadow: 0 0 20px rgba(var(--accent-emerald), 0.3); 
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

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

/* =========================================
   18. CUSTOM SCROLLBAR
   ========================================= */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* =========================================
   19. UTILITY CLASSES
   ========================================= */
.text-muted { color: var(--suda-text-muted) !important; }
.text-secondary { color: var(--suda-text-secondary) !important; }

.bg-surface { background: var(--suda-surface) !important; }
.bg-surface-elevated { background: var(--suda-surface-elevated) !important; }

.border-subtle { border-color: var(--suda-border) !important; }

.rounded-lg { border-radius: var(--radius-lg) !important; }
.rounded-md { border-radius: var(--radius-md) !important; }

/* Force z-index for offcanvas */
.offcanvas-backdrop { z-index: 999998 !important; }
#templateOffcanvas { z-index: 999999 !important; }
.offcanvas-backdrop.show { pointer-events: none; }

/* =========================================
   20. RESPONSIVE BREAKPOINTS
   ========================================= */

/* Large screens */
@media (min-width: 1200px) {
    .main-container { max-width: 1320px; }
}

/* Medium screens (tablets) */
@media (max-width: 991px) {
    .top-navbar {
        padding: 0.5rem;
    }
    
    .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 8px;
        right: 8px;
        background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
        border: 1px solid var(--glass-border);
        border-radius: var(--radius-md);
        padding: 16px;
        margin-top: 8px;
        box-shadow: var(--glass-shadow);
    }
    
    .main-nav {
        flex-direction: column;
        width: 100%;
        gap: 4px;
    }
    
    .main-nav .nav-link {
        width: 100%;
        padding: 12px 16px;
    }
    
    .user-dropdown {
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--suda-border);
    }
}

/* Small screens (phones) */
@media (max-width: 767px) {
    :root {
        --navbar-height: 56px;
        --container-padding: 1rem;
    }
    
    .top-navbar {
        margin: 0 !important;
        width: 100% !important;
        border-radius: 0 !important;
        top: 0 !important;
    }
    
    .main-container {
        padding: 1rem;
        padding-top: calc(var(--navbar-height) + 0.5rem);
    }
    
    .navbar-brand {
        font-size: 1rem;
    }
    
    .navbar-brand span {
        display: none; /* Hide text, show only logo on mobile */
    }
    
    .card {
        border-radius: var(--radius-sm);
    }
    
    .card-header, .card-body {
        padding: 12px 14px;
    }
    
    .modal-content {
        border-radius: var(--radius-md);
        margin: 8px;
    }
    
    .main-view-container { 
        padding: 10px; 
        gap: 10px; 
        min-height: 350px;
        border-radius: var(--radius-sm);
    }
    
    .image-container { 
        height: 350px !important; 
        max-width: 100%; 
    }
    
    .viewport-content { 
        height: 300px !important; 
    }
    
    .thumbnail-container { 
        min-height: 100px; 
        padding: 8px; 
        gap: 8px; 
    }
    
    .controls { 
        width: 80px !important; 
        height: 100px !important; 
    }
    
    #mainFullscreenToggle { 
        display: none !important; 
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .htmx-indicator {
        top: auto;
        bottom: 20px;
        right: 20px;
        left: 20px;
        text-align: center;
    }
}

/* Extra small screens */
@media (max-width: 575px) {
    .top-navbar { 
        padding: 0.375rem 0.5rem; 
    }
    
    .navbar-brand img {
        height: 22px;
    }
    
    .user-dropdown .btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .user-dropdown .dropdown-menu {
        min-width: 100%;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
        border-radius: var(--radius-sm);
    }
    
    .alert {
        padding: 12px 14px;
        font-size: 12px;
    }
    
    .toast {
        width: calc(100vw - 32px);
        max-width: none;
    }
}

/* =========================================
   21. PRINT STYLES
   ========================================= */
@media print {
    .top-navbar, 
    .offcanvas, 
    #toastContainer, 
    .htmx-indicator, 
    #imageViewerModal,
    #ai-config-toggle,
    #outermodal,
    .download-widget-wrapper { 
        display: none !important; 
    }
    
    .main-container { 
        padding: 0;
        max-width: none;
    }
    
    body { 
        background: white !important; 
        color: black !important; 
    }
    
    .thumbnail-container { 
        display: none; 
    }
    
    .main-view-container { 
        grid-template-columns: 1fr !important; 
        border: none; 
        padding: 0; 
        background: white; 
    }
    
    .image-container { 
        page-break-inside: avoid; 
        max-width: 100%; 
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* =========================================
   22. VIEWER MODE OVERRIDES
   ========================================= */
body.viewer-mode {
    overflow: hidden !important;
    background-color: var(--suda-bg) !important;
}

body.viewer-mode .top-navbar {
    background: rgba(10, 10, 10, 0.95);
}

body.viewer-mode #container {
    background-color: var(--suda-bg) !important;
}

body.viewer-mode .main-container {
    padding: 0;
    max-width: none;
}

/* =========================================
   23. ELECTRON-SPECIFIC STYLES
   ========================================= */
body.electron-app .cache-btn-container {
    display: flex !important;
}

body.electron-app #mainFullscreenToggle {
    display: inline-flex !important;
}

/* =========================================
   24. ACCESSIBILITY
   ========================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

:focus-visible {
    outline: 2px solid rgb(var(--accent-indigo));
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --suda-border: rgba(255, 255, 255, 0.3);
        --suda-text: #ffffff;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}
/* =========================================
   23. MAIN MENU FIXES (owner request 2026-11-27)
   ========================================= */

/* The menu floats 8px in from the edges with round corners, so a scrolled
   page showed above it, beside it and through its corners. A strip in the
   page colour now sits behind it. */
body:has(> .top-navbar)::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--navbar-height) + 14px);
    background: linear-gradient(180deg, var(--suda-bg) 0, var(--suda-bg) calc(100% - 6px), transparent 100%);
    z-index: 1029;                       /* just under the menu (1030) */
    pointer-events: none;
}
body.has-electron-titlebar:has(> .top-navbar)::before {
    top: var(--tb-height, 42px);
    z-index: calc(var(--z-titlebar, 13000) - 2);
}
body.has-electron-titlebar.titlebar-collapsed:has(> .top-navbar)::before { top: 0; }
body.viewer-mode::before { display: none; }
@media print { body::before { display: none !important; } }

/* The menu itself no longer lets the page show through. */
.top-navbar {
    background: linear-gradient(180deg, #141414, #0a0a0a);
}

/* Notices open under the menu, never over the user button. */
#toastContainer.top-0 { top: calc(var(--navbar-height) + 16px) !important; }

/* "More": the same surface as the user menu (it was Bootstrap's grey). */
.main-nav .dropdown-menu {
    background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--glass-shadow);
    min-width: 230px;
    padding: 8px;
    margin-top: 8px;
}
.main-nav .dropdown-item {
    color: var(--suda-text);
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.main-nav .dropdown-item i { width: 20px; color: var(--suda-text-secondary); }
.main-nav .dropdown-item:hover,
.main-nav .dropdown-item:focus {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}
.main-nav .dropdown-item.active,
.main-nav .dropdown-item:active {
    background: linear-gradient(135deg, rgba(var(--accent-indigo), 0.22), rgba(var(--accent-indigo), 0.1));
    color: #c7c9ff;
}
.main-nav .dropdown-item.active i { color: rgb(var(--accent-indigo)); }
.main-nav .nav-link.active { color: #c7c9ff; }
.main-nav .nav-link:focus-visible,
.main-nav .dropdown-item:focus-visible,
.user-dropdown .btn:focus-visible {
    outline: 2px solid rgb(var(--accent-indigo));
    outline-offset: 2px;
}
.main-nav > li { list-style: none; }

/* Phone and tablet: the opened panel scrolls inside the screen, and "More"
   opens in place inside it instead of floating over the page. */
@media (max-width: 991px) {
    .navbar-collapse {
        max-height: calc(100vh - var(--navbar-height) - 32px);
        overflow-y: auto;
        overscroll-behavior: contain;
        background: #111;
        z-index: 1031;
    }
    .main-nav { align-items: stretch; }
    .main-nav > li { width: 100%; }
    .main-nav .nav-link { text-align: left; }
    .navbar-collapse .dropdown-menu,
    .navbar-collapse .user-dropdown .dropdown-menu {
        position: static !important;
        transform: none !important;
        inset: auto !important;
        width: 100%;
        min-width: 0;
        margin: 4px 0 8px;
        box-shadow: none;
        background: rgba(255, 255, 255, 0.03);
    }
    .navbar-collapse .d-flex.ms-auto { width: 100%; }
    .navbar-collapse .user-dropdown { width: 100%; }
    .navbar-collapse .user-dropdown .btn { width: 100%; text-align: left; }
    .main-nav .dropdown-item { padding: 11px 14px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .main-nav .dropdown-item, .main-nav .nav-link { transition: none; }
}
