:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 64px;
    --topbar-height: 56px;

    /* Brite light palette */
    --bg-primary: #ffffff;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #f1f3f5;

    /* Aliases used by the public blog templates */
    --card-bg: var(--bg-secondary);
    --hover-bg: var(--bg-hover);

    --text-primary: #000000;
    --text-secondary: #212529;
    --text-tertiary: #495057;

    /* Brite uses 2px solid black borders everywhere */
    --border-color: #000000;
    --border-primary: #000000;

    /* Accent colors — primary is "normal blue", danger matches old app */
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-primary: #3b82f6;
    --accent: #3b82f6;
    --accent-green: #68d391;
    --accent-amber: #ffc700;
    --accent-red: rgb(255, 100, 100);
    --accent-purple: #be82fa;
    --accent-cyan: #22d2ed;

    /* Brite-style hard-edge offset shadow */
    --shadow-sm: 2px 2px 0 0 #000;
    --shadow-md: 3px 3px 0 0 #000;
    --shadow-lg: 4px 4px 0 0 #000;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ===== Dark mode overrides =====
   Brite's vendor CSS already swaps Bootstrap's --bs-* tokens when
   [data-bs-theme="dark"] is set on <html>. Here we mirror that for our own
   custom tokens (--bg-*, --text-*, --border-*, shadows) so non-Bootstrap
   components (sidebar, topbar, custom cards, modal-bodies styled by app.css)
   follow the same theme. */
html[data-bs-theme="dark"] {
    /* Dark backgrounds only — borders stay black like light mode. */
    --bg-primary: #1a1d21;
    --bg-secondary: #212529;
    --bg-tertiary: #2b3035;
    --bg-surface: #212529;
    --bg-elevated: #2b3035;
    --bg-hover: #343a40;

    --text-primary: #f8f9fa;
    --text-secondary: #dee2e6;
    --text-tertiary: #adb5bd;

    /* Borders + offset shadows stay pure black in both modes — only the
       surface color changes between light and dark. */
    --border-color: #000000;
    --border-primary: #000000;
    --bs-border-color: #000000;
    --bs-border-color-translucent: rgba(0, 0, 0, 0.6);

    --shadow-sm: 2px 2px 0 0 #000000;
    --shadow-md: 3px 3px 0 0 #000000;
    --shadow-lg: 4px 4px 0 0 #000000;
}

/* Bootstrap components define --bs-border-color on their own scope, so a
   :root-level override alone won't reach them. Force-cascade in dark mode. */
html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select,
html[data-bs-theme="dark"] .form-check-input,
html[data-bs-theme="dark"] .card,
html[data-bs-theme="dark"] .modal-content,
html[data-bs-theme="dark"] .modal-header,
html[data-bs-theme="dark"] .modal-footer,
html[data-bs-theme="dark"] .dropdown-menu,
html[data-bs-theme="dark"] .dropdown-divider,
html[data-bs-theme="dark"] .list-group-item,
html[data-bs-theme="dark"] .table,
html[data-bs-theme="dark"] .table > :not(caption) > * > *,
html[data-bs-theme="dark"] .nav-tabs,
html[data-bs-theme="dark"] .nav-tabs .nav-link,
html[data-bs-theme="dark"] .input-group-text,
html[data-bs-theme="dark"] .accordion-item,
html[data-bs-theme="dark"] .accordion-button,
html[data-bs-theme="dark"] .pagination .page-link,
html[data-bs-theme="dark"] hr {
    --bs-border-color: #000000;
    border-color: #000000;
}

/* Bootstrap's border-utility classes resolve --bs-secondary-rgb / --bs-light-rgb
   to white (255,255,255), producing harsh high-contrast white borders in dark
   mode (e.g. .card.border-secondary). Force them to the same black border used
   everywhere else so dark mode matches the light-mode look. Also covers
   outline-secondary/light buttons which derive their border from the same rgb. */
html[data-bs-theme="dark"] .border,
html[data-bs-theme="dark"] .border-secondary,
html[data-bs-theme="dark"] .border-light,
html[data-bs-theme="dark"] .border-white,
html[data-bs-theme="dark"] .btn-outline-secondary,
html[data-bs-theme="dark"] .btn-outline-light {
    border-color: #000000 !important;
}

/* In dark mode the close icon glyph must be white to be visible. */
html[data-bs-theme="dark"] .modal-header .btn-close,
html[data-bs-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Dark-mode form inputs: dark background, white text. Covers Bootstrap
   .form-control / .form-select, native input/textarea/select, and the
   project's custom .table-filter-input. */
html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select,
html[data-bs-theme="dark"] .form-control-plaintext,
html[data-bs-theme="dark"] .table-filter-input,
html[data-bs-theme="dark"] input[type="text"],
html[data-bs-theme="dark"] input[type="search"],
html[data-bs-theme="dark"] input[type="email"],
html[data-bs-theme="dark"] input[type="url"],
html[data-bs-theme="dark"] input[type="tel"],
html[data-bs-theme="dark"] input[type="password"],
html[data-bs-theme="dark"] input[type="number"],
html[data-bs-theme="dark"] input[type="date"],
html[data-bs-theme="dark"] input[type="datetime-local"],
html[data-bs-theme="dark"] input[type="time"],
html[data-bs-theme="dark"] input[type="month"],
html[data-bs-theme="dark"] input[type="week"],
html[data-bs-theme="dark"] input[type="file"],
html[data-bs-theme="dark"] input[type="color"],
html[data-bs-theme="dark"] input[type="range"],
html[data-bs-theme="dark"] textarea,
html[data-bs-theme="dark"] select {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border-color: #000000 !important;
}

/* Restore distinct disabled / readonly affordance — without this, the
   rule above forces every state to look editable. */
html[data-bs-theme="dark"] .form-control:disabled,
html[data-bs-theme="dark"] .form-select:disabled,
html[data-bs-theme="dark"] input:disabled,
html[data-bs-theme="dark"] textarea:disabled,
html[data-bs-theme="dark"] select:disabled {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-tertiary) !important;
    opacity: 0.65;
    cursor: not-allowed;
}

html[data-bs-theme="dark"] .form-control[readonly],
html[data-bs-theme="dark"] input[readonly],
html[data-bs-theme="dark"] textarea[readonly] {
    background-color: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
}

html[data-bs-theme="dark"] .form-control::placeholder,
html[data-bs-theme="dark"] .table-filter-input::placeholder,
html[data-bs-theme="dark"] input::placeholder,
html[data-bs-theme="dark"] textarea::placeholder {
    color: var(--text-tertiary) !important;
    opacity: 1;
}

/* The "Choose File" button on file inputs is rendered by the browser as a
   pseudo-element; Bootstrap exposes a separate selector for its own styling. */
html[data-bs-theme="dark"] .form-control[type="file"]::file-selector-button,
html[data-bs-theme="dark"] input[type="file"]::file-selector-button {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border: 0;
    border-right: 1px solid #000000;
}

/* Autofill: Chrome paints a yellow background unless we mask it. */
html[data-bs-theme="dark"] input:-webkit-autofill,
html[data-bs-theme="dark"] textarea:-webkit-autofill,
html[data-bs-theme="dark"] select:-webkit-autofill {
    -webkit-text-fill-color: var(--text-primary) !important;
    -webkit-box-shadow: 0 0 0 1000px var(--bg-primary) inset !important;
    caret-color: var(--text-primary);
}

* { box-sizing: border-box; }

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    height: 100vh;
}

.app-wrapper {
    display: flex;
    height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    overflow: hidden;
    z-index: 100;
    transition: width .25s ease;
}

.app-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.app-sidebar.collapsed .brand-text,
.app-sidebar.collapsed .brand-version {
    display: none;
}

.app-sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 16px 10px;
}

.app-sidebar.collapsed .nav-section-label {
    opacity: 0;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    transition: opacity .15s ease, height .15s ease;
}

.app-sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px;
}

.app-sidebar.collapsed .nav-item span {
    display: none;
}

.app-sidebar.collapsed .nav-item .badge {
    display: none;
}

.app-sidebar.collapsed .nav-item i {
    font-size: 18px;
    width: auto;
}

.app-sidebar.collapsed .sidebar-footer {
    padding: 12px 8px;
}

.app-sidebar.collapsed .user-info,
.app-sidebar.collapsed .user-card > i {
    display: none;
}

.app-sidebar.collapsed .user-card {
    justify-content: center;
    padding: 8px;
}

.app-sidebar.collapsed .sidebar-nav {
    padding: 12px 8px;
}

.sidebar-brand {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--topbar-height);
}

.sidebar-brand .brand-link,
.sidebar-brand .brand-link:hover,
.sidebar-brand .brand-link:focus,
.sidebar-brand .brand-link:active {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
    color: inherit;
    min-width: 0;
}

/* Never add border-radius/rounded to logos — they should always render with sharp corners */
.sidebar-brand .brand-logo {
    height: 1.4em;
    width: auto;
    border-radius: 0;
    flex-shrink: 0;
    object-fit: contain;
}

.sidebar-brand .brand-text {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    letter-spacing: -.3px;
}

.sidebar-brand .brand-version {
    font-size: 10px;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.nav-section {
    margin-bottom: 20px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-tertiary);
    padding: 0 10px;
    margin-bottom: 6px;
}

.nav-select-project-alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 8px 4px 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: rgba(40, 167, 69, 0.12);
    border: 1px solid rgba(40, 167, 69, 0.4);
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.4;
}

.nav-select-project-alert i {
    color: #28a745;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 1px;
}

.app-sidebar.collapsed .nav-select-project-alert span {
    display: none;
}

.app-sidebar.collapsed .nav-select-project-alert {
    justify-content: center;
    padding: 10px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all .15s ease;
    cursor: pointer;
    margin-bottom: 1px;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-blue);
    color: #fff;
}

.nav-item.active:hover {
    background: var(--accent-blue-hover);
}

.nav-item.nav-info {
    color: #17a2b8;
}
.nav-item.nav-info:hover {
    background: rgba(23, 162, 184, 0.15);
    color: #138496;
}
.nav-item.nav-info.active {
    background: #17a2b8;
    color: #fff;
}
.nav-item.nav-info.active:hover {
    background: #138496;
}

.nav-item.nav-success {
    color: #28a745;
}
.nav-item.nav-success:hover {
    background: rgba(40, 167, 69, 0.15);
    color: #1e7e34;
}
.nav-item.nav-success.active {
    background: #28a745;
    color: #fff;
}
.nav-item.nav-success.active:hover {
    background: #1e7e34;
}

.nav-item.nav-warning {
    color: #e6a817;
}
.nav-item.nav-warning:hover {
    background: rgba(255, 193, 7, 0.15);
    color: #d49a10;
}
.nav-item.nav-warning.active {
    background: #e6a817;
    color: #fff;
}
.nav-item.nav-warning.active:hover {
    background: #d49a10;
}

.nav-item.nav-danger {
    color: #ff6464;
}
.nav-item.nav-danger:hover {
    background: rgba(255, 100, 100, 0.15);
    color: #c82333;
}
.nav-item.nav-danger.active {
    background: #ff6464;
    color: #fff;
}
.nav-item.nav-danger.active:hover {
    background: #c82333;
}

.nav-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-item .badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 12px 10px;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .15s;
}

.user-card:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    color: #fff;
    flex-shrink: 0;
}

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

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: var(--text-tertiary);
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.app-topbar {
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    flex-shrink: 0;
}

.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.topbar-breadcrumb a {
    color: var(--text-secondary);
    text-decoration: none;
}

.topbar-breadcrumb a:hover {
    color: var(--text-primary);
}

.topbar-breadcrumb .separator {
    color: var(--text-tertiary);
    font-size: 10px;
}

.topbar-breadcrumb .current {
    color: var(--text-primary);
    font-weight: 500;
}

.topbar-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.topbar-back-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.app-content::-webkit-scrollbar {
    width: 6px;
}

.app-content::-webkit-scrollbar-track {
    background: transparent;
}

.app-content::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.hierarchy-path {
    display: flex;
    align-items: center;
    gap: 0;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 6px 4px;
    background: transparent;
    border: none;
    border-radius: 0;
}

.hierarchy-segment {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all .15s ease;
    white-space: nowrap;
}

a.hierarchy-segment:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.hierarchy-segment.current {
    color: var(--text-primary);
    font-weight: 600;
}

.hierarchy-segment i {
    font-size: 14px;
    flex-shrink: 0;
}

/* Never add border-radius/rounded to logos — they should always render with sharp corners */
.hierarchy-segment .tenant-logo {
    height: 1.4em;
    width: auto;
    object-fit: contain;
    border-radius: 0;
    flex-shrink: 0;
    vertical-align: middle;
}

.tenant-segment .tenant-name-text {
    display: inline-block;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    vertical-align: middle;
    transition: max-width 0.3s ease, margin-left 0.3s ease;
    margin-left: 0;
}

.tenant-segment:hover .tenant-name-text {
    max-width: 200px;
    margin-left: 6px;
}

.hierarchy-separator {
    color: var(--text-tertiary);
    font-size: 10px;
    display: inline-flex;
    align-items: center;
    padding: 0 2px;
}

.hierarchy-segment-group {
    display: inline-flex;
    align-items: center;
    gap: 0;
    position: relative;
}

.tenant-switcher {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.tenant-switcher-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .15s ease;
    padding: 0;
    font-size: 14px;
}

.tenant-switcher-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tenant-switcher-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    min-width: 240px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    overflow: hidden;
}

.tenant-switcher-dropdown.open {
    display: block;
}

.tenant-switcher-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.tenant-switcher-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s ease;
    text-align: left;
}

.tenant-switcher-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tenant-switcher-item.active {
    color: var(--accent);
    font-weight: 500;
}

.tenant-switcher-item .tenant-check {
    margin-left: auto;
    color: var(--accent);
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -.3px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: border-color .15s;
}

.stat-card:hover {
    border-color: var(--accent-blue);
}

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

.stat-icon.blue { background: rgba(59,130,246,.15); color: var(--accent-blue); }
.stat-icon.green { background: rgba(34,197,94,.15); color: var(--accent-green); }
.stat-icon.amber { background: rgba(245,158,11,.15); color: var(--accent-amber); }
.stat-icon.purple { background: rgba(139,92,246,.15); color: var(--accent-purple); }
.stat-icon.cyan { background: rgba(6,182,212,.15); color: var(--accent-cyan); }
.stat-icon.red { background: rgba(255, 100, 100,.15); color: var(--accent-red); }

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.content-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
}

.content-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.content-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.content-card-body {
    padding: 0;
}

.content-card-body.padded {
    padding: 20px;
}

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

.data-table thead th {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-tertiary);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    white-space: nowrap;
}

.data-table tbody td {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

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

.data-table tbody tr {
    transition: background .1s;
}

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

.listing-thumb {
    max-width: 72px;
    max-height: 52px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid var(--border-primary);
    background: var(--bg-primary);
    display: block;
}
.listing-thumb-placeholder {
    width: 52px;
    height: 52px;
    border-radius: 4px;
    border: 1px solid var(--border-primary);
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 18px;
}

.data-table tbody tr td:first-child {
    color: var(--text-primary);
    font-weight: 500;
}

.table-filter-row {
    overflow: hidden;
    height: 0;
    transition: height 300ms ease;
}

.table-filter-cell {
    padding: 0 !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.table-filter-input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 10px;
    margin: 4px 6px;
    width: calc(100% - 12px);
    font-size: 12px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.table-filter-input::placeholder {
    color: var(--text-tertiary);
}

.table-filter-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-badge.active, .status-badge.ready, .status-badge.accepted, .status-badge.approved {
    background: rgba(34,197,94,.12);
    color: var(--accent-green);
}
.status-badge.active::before, .status-badge.ready::before, .status-badge.accepted::before, .status-badge.approved::before {
    background: var(--accent-green);
}

.status-badge.completed {
    background: rgba(245,158,11,.12);
    color: var(--accent-amber);
}
.status-badge.completed::before {
    background: var(--accent-amber);
}

.status-badge.planning, .status-badge.draft, .status-badge.pending, .status-badge.uploaded {
    background: rgba(148,163,184,.12);
    color: var(--text-secondary);
}
.status-badge.planning::before, .status-badge.draft::before, .status-badge.pending::before, .status-badge.uploaded::before {
    background: var(--text-secondary);
}

.status-badge.in_progress, .status-badge.processing, .status-badge.review, .status-badge.testing, .status-badge.open, .status-badge.extracting {
    background: rgba(59,130,246,.12);
    color: var(--accent-blue);
}
.status-badge.in_progress::before, .status-badge.processing::before, .status-badge.review::before, .status-badge.testing::before, .status-badge.open::before, .status-badge.extracting::before {
    background: var(--accent-blue);
}

.status-badge.on_hold, .status-badge.rejected, .status-badge.cancelled, .status-badge.failed, .status-badge.error {
    background: rgba(255, 100, 100,.12);
    color: var(--accent-red);
}
.status-badge.on_hold::before, .status-badge.rejected::before, .status-badge.cancelled::before, .status-badge.failed::before, .status-badge.error::before {
    background: var(--accent-red);
}

.status-badge.archived {
    background: rgba(139,92,246,.12);
    color: var(--accent-purple);
}
.status-badge.archived::before {
    background: var(--accent-purple);
}

.btn-primary-custom {
    background: var(--accent-blue);
    border: 2px solid var(--border-color);
    color: #fff;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    /* Brite 3D press-effect: offset shadow + translate, collapses on hover */
    margin: 3px 0 0 3px;
    box-shadow: var(--shadow-md);
    transform: translate(-3px, -3px);
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.btn-primary-custom:hover,
.btn-primary-custom:focus-visible {
    background: var(--accent-blue-hover);
    color: #fff;
    box-shadow: none;
    transform: translate(0, 0);
}

.btn-secondary-custom {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    /* Brite 3D press-effect */
    margin: 3px 0 0 3px;
    box-shadow: var(--shadow-md);
    transform: translate(-3px, -3px);
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.btn-secondary-custom:hover,
.btn-secondary-custom:focus-visible {
    background: var(--bg-hover);
    color: var(--text-primary);
    box-shadow: none;
    transform: translate(0, 0);
}

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s;
    font-size: 14px;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.empty-state {
    padding: 60px 20px;
    text-align: center;
}

.empty-state > i {
    font-size: 48px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.empty-state .btn-primary-custom {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.empty-state .btn-primary-custom i {
    font-size: 24px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 300px;
    margin: 0 auto 20px;
}

.form-control, .form-select {
    background: #fff !important;
    border: 2px solid #000 !important;
    color: #000 !important;
    font-size: 13px;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.form-control:focus, .form-select:focus {
    border-color: #000 !important;
    box-shadow: 0 0 0 2px rgba(59,130,246,.2) !important;
}

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

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

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 12px 20px;
}

/* On the light Brite theme the close icon should stay dark (no invert).
   Bootstrap's btn-close-white still inverts via its own class if needed. */
.modal-header .btn-close {
    filter: none;
}

.activity-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: background .1s;
}

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

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

.activity-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.activity-icon.create { background: rgba(34,197,94,.15); color: var(--accent-green); }
.activity-icon.update { background: rgba(59,130,246,.15); color: var(--accent-blue); }
.activity-icon.delete { background: rgba(255, 100, 100,.15); color: var(--accent-red); }
.activity-icon.upload { background: rgba(139,92,246,.15); color: var(--accent-purple); }

.activity-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.activity-text strong {
    color: var(--text-primary);
    font-weight: 500;
}

.activity-time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.detail-field {
    padding: 12px 0;
}

.detail-grid-compact {
    gap: 4px 24px;
}

.detail-grid-compact .detail-field {
    padding: 5px 0;
}

.detail-grid-compact .detail-label {
    margin-bottom: 1px;
}

.detail-grid-compact .detail-value {
    font-size: 13px;
}

.detail-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.detail-value {
    font-size: 14px;
    color: var(--text-primary);
}

.tabs-bar {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    gap: 0;
}

.tab-btn {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all .15s;
}

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

.tab-btn.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.search-advanced-link:hover {
    color: var(--accent-blue-hover);
}

.search-results-list {
    padding: 6px;
}

.search-result-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s ease;
    text-decoration: none;
    color: inherit;
}

.search-result-card:hover {
    background: var(--bg-hover);
    color: inherit;
    text-decoration: none;
}

.search-result-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    color: #fff;
}

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

.search-result-top {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.search-result-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-type-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    color: #fff;
}

.search-result-subtitle {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-score {
    font-size: 10px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    margin-left: auto;
    padding-top: 2px;
}

.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

.search-empty {
    text-align: center;
    padding: 20px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.priority-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.priority-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.priority-dot.high { background: var(--accent-red); }
.priority-dot.medium { background: var(--accent-amber); }
.priority-dot.low { background: var(--accent-green); }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    overflow: auto;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: #ffffff;
    border: 2px solid #000;
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: 3px 3px 0 0 #000;
}

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

/* Never add border-radius/rounded to logos — they should always render with sharp corners */
.login-brand .brand-logo {
    height: 1.4em;
    width: auto;
    border-radius: 0;
    object-fit: contain;
}

.login-brand h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -.5px;
}

.login-subtitle {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 28px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-tertiary);
}

@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-sidebar.collapsed {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }
    .app-sidebar.collapsed.open {
        transform: translateX(0);
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.clickable-row {
    cursor: pointer;
}

.text-truncate-custom {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-bar-custom {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-custom .fill {
    height: 100%;
    border-radius: 2px;
    background: var(--accent-blue);
    transition: width .3s ease;
}

.code-text {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--accent-cyan);
}

.admin-section {
    margin-bottom: 32px;
}

.admin-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.admin-section-title i {
    color: var(--accent-blue);
}

.dropdown-menu {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 4px;
}

.dropdown-item {
    color: var(--text-secondary);
    font-size: 13px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
}

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

.dropdown-divider {
    border-color: var(--border-color);
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.perm-checkbox {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    outline: 2px solid var(--border-color);
    outline-offset: -2px;
    border-radius: 3px;
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
}

.perm-checkbox:checked {
    background: var(--accent-blue, #3b82f6);
    outline-color: var(--accent-blue, #3b82f6);
}

.perm-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.toast-header {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

/* Photo Controls */
.photo-controls {
    display: inline-flex;
    align-items: center;
}
.photo-controls .btn-group {
    display: inline-flex;
    gap: 0;
}
.photo-controls .btn-group .btn-icon {
    padding: 0;
    min-width: 26px;
    height: 22px;
    font-size: 12px;
    border-radius: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.photo-controls .btn-group .btn-icon.photo-upload-btn {
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
.photo-controls .btn-group .btn-icon + .btn-icon {
    border-left: none;
}
.photo-controls .btn-group .btn-icon:first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}
.photo-controls .btn-group .btn-icon:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}
.photo-controls .btn-group .btn-icon:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}
.photo-controls .btn-group .btn-icon.photo-upload-btn:hover {
    opacity: 0.85;
}
.photo-count-badge {
    font-size: 11px;
    font-weight: 600;
    min-width: 16px;
    display: inline-block;
    text-align: center;
}

/* Photo Gallery Modal */
.photo-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}
.photo-gallery-card {
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    position: relative;
}
.photo-gallery-card.is-thumbnail {
    border-color: var(--accent-blue);
}
.photo-gallery-img-wrap {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
}
.photo-gallery-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.photo-thumbnail-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--accent-blue);
    color: #fff;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 3px;
}
.photo-gallery-actions {
    display: flex;
    gap: 4px;
    padding: 6px;
    justify-content: flex-end;
}
.photo-gallery-actions .btn-icon {
    padding: 2px 6px;
    font-size: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}
.photo-gallery-actions .btn-icon:hover {
    color: var(--text-primary);
}
.photo-gallery-caption {
    padding: 0 6px 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Photo Folder Gallery */
.photo-folder-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.photo-folder-card {
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
}
.photo-folder-img-wrap {
    aspect-ratio: 4/3;
    overflow: hidden;
}
.photo-folder-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.photo-folder-info {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.photo-folder-link {
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-blue);
    text-decoration: none;
}
.photo-folder-link:hover {
    text-decoration: underline;
}
.photo-folder-date {
    font-size: 11px;
    color: var(--text-tertiary);
}

/* Pagination */
.pagination .page-link {
    background: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-secondary);
    font-size: 12px;
}
.pagination .page-item.active .page-link {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

/* Reference Controls */
.ref-controls {
    display: inline-flex;
    align-items: center;
}
.ref-controls .btn-group {
    display: inline-flex;
    gap: 0;
}
.ref-controls .btn-group .btn-icon {
    padding: 0 7px;
    height: 22px;
    font-size: 12px;
    border-radius: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.ref-controls .btn-group .btn-icon + .btn-icon {
    border-left: none;
}
.ref-controls .btn-group .btn-icon:first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}
.ref-controls .btn-group .btn-icon:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    padding-right: 8px;
    min-width: 38px;
}
.ref-controls .btn-group .btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.ref-count-badge {
    font-size: 11px;
    font-weight: 600;
    min-width: 16px;
    display: inline-block;
    text-align: center;
}
.ref-count-glow-red {
    color: #ff6464;
    text-shadow: 0 0 6px rgba(255, 100, 100, 0.6);
    animation: refGlowPulse 2s ease-in-out infinite;
}
@keyframes refGlowPulse {
    0%, 100% { text-shadow: 0 0 4px rgba(255, 100, 100, 0.4); }
    50% { text-shadow: 0 0 10px rgba(255, 100, 100, 0.8); }
}
.ref-request-badge {
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    display: inline-block;
    text-align: center;
}
.ref-request-glow-yellow {
    color: #eab308;
    text-shadow: 0 0 6px rgba(234, 179, 8, 0.6);
    animation: refRequestGlowPulse 2s ease-in-out infinite;
}
.ref-request-glow-yellow-bg {
    background: rgba(234, 179, 8, 0.08) !important;
    border-color: rgba(234, 179, 8, 0.3) !important;
}
@keyframes refRequestGlowPulse {
    0%, 100% { text-shadow: 0 0 4px rgba(234, 179, 8, 0.4); }
    50% { text-shadow: 0 0 10px rgba(234, 179, 8, 0.8); }
}
.note-count-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--bg-tertiary, #374151);
    color: var(--text-secondary, #9ca3af);
    text-align: center;
    pointer-events: none;
}
.note-count-badge.note-glow-yellow {
    background: rgba(234, 179, 8, 0.18);
    color: #eab308 !important;
    text-shadow: 0 0 6px rgba(234, 179, 8, 0.6);
    animation: refRequestGlowPulse 2s ease-in-out infinite;
}
.note-glow-yellow-bg {
    background: rgba(234, 179, 8, 0.08) !important;
    border-color: rgba(234, 179, 8, 0.3) !important;
}
.dim_found {
    opacity: 0.8;
    transition: opacity 0.15s ease;
    cursor: grab;
}
.dim_found:hover {
    opacity: 1;
}
.dim_found:active {
    cursor: grabbing;
}
.ref-request-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
}
.ref-request-item:last-child { border-bottom: none; }
.ref-schema-item:hover { background: var(--bg-tertiary, rgba(255,255,255,0.05)) !important; }
.ref-schema-item:last-child { border-bottom: none !important; }
.ref-type-btn:hover { opacity: 0.85; }
.ref-type-btn.active:hover { opacity: 1; }
.ref-status-inline-select { appearance: auto; -webkit-appearance: menulist; outline: none; }
.ref-status-inline-select option { background: var(--bg-secondary); color: var(--text-primary); }
.ref-request-status-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}
.ref-request-status-open { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.ref-request-status-fulfilled { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.ref-request-status-cancelled { background: rgba(107, 114, 128, 0.15); color: #6b7280; }

/* Reference Search Results */
.ref-search-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-color);
}
.ref-search-result:hover {
    background: var(--bg-hover);
}
.ref-search-result.ref-result-selected {
    background: rgba(34, 197, 94, 0.08);
}
.ref-result-icon {
    font-size: 16px;
    color: var(--text-secondary);
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}
.ref-result-info {
    flex: 1;
    min-width: 0;
}
.ref-result-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ref-result-subtitle {
    font-size: 11px;
    color: var(--text-tertiary);
}
.ref-result-check {
    flex-shrink: 0;
    font-size: 14px;
}

/* Reference Selected Items */
.ref-selected-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 4px;
}

/* Reference Listing */
.ref-listing-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    margin-bottom: 2px;
    transition: background 0.15s;
}
.ref-listing-item:hover {
    background: var(--bg-hover);
}
.ref-listing-item.ref-status-pass {
    border-left: 3px solid #22c55e;
}
.ref-listing-item.ref-status-fail {
    border-left: 3px solid #ff6464;
}
.ref-status-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}
.ref-status-pass, .ref-status-compliant {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}
.ref-status-fail, .ref-status-noncompliant {
    background: rgba(255, 100, 100, 0.15);
    color: #ff6464;
}
.ref-delete-btn,
.revref-delete-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 10px;
    opacity: 0.4;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}
.ref-delete-btn:hover,
.revref-delete-btn:hover {
    opacity: 1;
    color: var(--accent-red, #ff6464);
}

/* Self-contained reference listing popover (works in any context) */
.ref-listing-panel {
    position: fixed;
    z-index: 1080;
    min-width: 360px;
    max-width: 560px;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bg-secondary, #1a1d23);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.ref-listing-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    position: sticky;
    top: 0;
    background: var(--bg-secondary, #1a1d23);
}
.ref-listing-panel-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}
.ref-listing-panel-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 4px;
    line-height: 1;
}
.ref-listing-panel-close:hover {
    color: var(--text-primary);
}
.ref-listing-loading,
.ref-listing-empty {
    padding: 16px 12px;
    font-size: 12px;
    color: var(--text-tertiary);
    text-align: center;
}
.ref-listing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.ref-listing-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    vertical-align: top;
}
.ref-listing-table tr:last-child td {
    border-bottom: none;
}
.ref-listing-table .ref-prow:hover td {
    background: var(--bg-hover);
}
.ref-cell-status {
    white-space: nowrap;
    width: 1%;
}
.ref-cell-target {
    min-width: 160px;
}
.ref-target-link {
    color: var(--accent-blue);
    text-decoration: none;
    font-weight: 500;
    display: block;
}
.ref-target-link:hover {
    text-decoration: underline;
}
.ref-target-title {
    font-weight: 500;
    display: block;
    color: var(--text-primary);
}
.ref-target-sub {
    font-size: 10px;
    color: var(--text-tertiary);
    display: block;
}
.ref-cell-note {
    max-width: 140px;
    color: var(--text-tertiary);
}
.ref-cell-note span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ref-cell-by {
    white-space: nowrap;
    color: var(--text-tertiary);
    font-size: 10px;
}
.ref-cell-action {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}
.ref-listing-table .ref-delete-btn {
    opacity: 0.6;
}

/* Reference column header toggle */
.ref-col-toggle {
    cursor: pointer;
    user-select: none;
}
.ref-col-toggle:hover {
    color: var(--text-primary);
}
.ref-col-toggle .ref-toggle-icon {
    font-size: 9px;
    margin-left: 3px;
    transition: transform 0.2s;
}
.ref-col-toggle.expanded .ref-toggle-icon {
    transform: rotate(180deg);
}

/* Reverse Reference Controls (doc/form -> map items/list items) */
.revref-controls {
    display: inline-flex;
    align-items: center;
}
.revref-controls .btn-group {
    display: flex;
    align-items: center;
}
.revref-controls .btn-group .btn-icon {
    font-size: 13px;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    transition: color 0.15s, background 0.15s;
}
.revref-controls .btn-group .btn-icon:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.revref-count-badge {
    font-size: 11px;
    font-weight: 600;
    min-width: 16px;
    display: inline-block;
    text-align: center;
}

.text-ref-editor {
    min-height: 36px;
    padding: 6px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.6;
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    cursor: text;
    transition: border-color 0.15s ease;
}
.text-ref-editor:focus {
    border-color: var(--accent-primary);
}
.text-ref-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary);
    pointer-events: none;
}
.text-ref-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    margin: 0 2px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
    user-select: all;
    white-space: nowrap;
    vertical-align: middle;
    line-height: 1.4;
}
.text-ref-tag i {
    font-size: 11px;
}
.text-ref-remove {
    cursor: pointer;
    margin-left: 2px;
    font-size: 13px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.text-ref-remove:hover {
    opacity: 1;
}
.text-ref-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    margin: 0 2px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s;
}
.text-ref-chip:hover {
    background: rgba(59, 130, 246, 0.25);
    color: #60a5fa;
    text-decoration: none;
}
.text-ref-chip i {
    font-size: 11px;
}
.text-ref-dropdown {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}
.text-ref-dropdown-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.text-ref-dropdown-list {
    max-height: 240px;
    overflow-y: auto;
}
.text-ref-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border-primary);
}
.text-ref-dropdown-item:last-child {
    border-bottom: none;
}
.text-ref-dropdown-item:hover,
.text-ref-dropdown-item.highlighted {
    background: var(--bg-hover);
}
.text-ref-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.text-ref-item-schema {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
}
.text-ref-item-status {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    white-space: nowrap;
    text-transform: uppercase;
}
.text-ref-item-status.status-active {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}
.text-ref-item-status.status-inactive {
    background: rgba(100, 116, 139, 0.15);
    color: #94a3b8;
}
.text-ref-item-status.status-compliant {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}
.text-ref-item-status.status-non-compliant {
    background: rgba(255, 100, 100, 0.15);
    color: #ff6464;
}

@keyframes spin-anim {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.spin-animation {
    animation: spin-anim 0.8s linear infinite;
}

.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ff6464;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 4px;
}

.notif-item {
    display: block;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-primary);
    cursor: pointer;
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.15s;
}
.notif-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    text-decoration: none;
}
.notif-item.unread {
    background: rgba(59, 130, 246, 0.06);
    border-left: 3px solid #3b82f6;
}
.notif-item .notif-title {
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-item .notif-msg {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-item .notif-time {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
}
.notif-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}
.notif-icon.map-item { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.notif-icon.itp-item { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
.notif-icon.ref-request { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.notif-icon.default { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

.bi-welded-globe-valve {
    display: inline-block;
    width: 1em;
    height: 1em;
    background: currentColor;
    -webkit-mask: url('/static/custom_svg_icons/welded_globe_valve.svg') no-repeat center;
    mask: url('/static/custom_svg_icons/welded_globe_valve.svg') no-repeat center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.view-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 15px;
    padding: 0;
}
.view-toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-tertiary);
}
.view-toggle-btn.active {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    padding: 16px;
}
.tile-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    display: flex;
    flex-direction: column;
}
.tile-card:hover {
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.tile-card-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
}
.tile-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px;
}
.tile-card-thumb .tile-placeholder {
    font-size: 48px;
    color: var(--text-tertiary);
    opacity: 0.5;
}
.tile-card-body {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tile-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile-card-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.pqs-filter-btn {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border-primary, #2d2d3d);
    background: var(--bg-secondary, #1e1e2e);
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    transition: all 0.2s ease;
}
.pqs-filter-btn:first-child {
    border-radius: 6px 0 0 6px;
}
.pqs-filter-btn:last-child {
    border-radius: 0 6px 6px 0;
}
.pqs-filter-btn:not(:first-child) {
    border-left: none;
}
.pqs-filter-btn:hover {
    background: var(--bg-tertiary, #2a2f3e);
    color: var(--text-primary, #f1f5f9);
}
.pqs-filter-btn.active {
    background: rgba(234, 179, 8, 0.15);
    color: #eab308;
    border-color: rgba(234, 179, 8, 0.4);
    box-shadow: 0 0 8px rgba(234, 179, 8, 0.3), inset 0 0 4px rgba(234, 179, 8, 0.1);
}
.pqs-filter-btn.active + .pqs-filter-btn {
    border-left-color: rgba(234, 179, 8, 0.4);
}

.manual-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    overflow-y: auto;
    backdrop-filter: blur(2px);
}
.manual-modal {
    position: relative;
    margin: 60px auto;
    background: var(--bg-secondary, #1e1e2e);
    border: 1px solid var(--border-primary, #2d2d3d);
    border-radius: 12px;
    padding: 24px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}
