/**
 * ADM - Main Stylesheet
 *
 * Design system: brand tokens live in css/tokens.css (the portable contract
 * shared with the future real app). This file imports them, then BRIDGES the
 * legacy variable names below to the tokens so every existing rule re-skins at
 * once. ADM-specific component overrides live in the "ADM THEME" section at the
 * foot of this file.
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
@import url('tokens.css');

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* ---- Bridge: legacy names → ADM tokens (css/tokens.css) -------------- *
     * Grey ramp (--gray-50..900) and brand values come straight from tokens; *
     * the names below map old component CSS onto the new palette.            */
    --primary-color: var(--brand-ink);
    --primary-hover: var(--gray-800);
    --secondary-color: var(--gray-500);
    --success-color: var(--status-complete);
    --danger-color: var(--danger);
    --warning-color: var(--status-started);
    --warning-bg: var(--status-started-bg);
    --info-color: var(--brand-blue);

    /* Layout */
    --sidebar-width: 232px;
    --sidebar-collapsed-width: 0px;
    --header-height: 56px;
    --border-radius: var(--radius-sm);
    --border-radius-sm: 4px;
    --border-radius-lg: var(--radius-md);
    --box-shadow: var(--shadow-sm);
    --box-shadow-lg: var(--shadow-md);

    /* Typography */
    --font-family: var(--font-sans);
    --font-size-xs: var(--text-xs);
    --font-size-sm: var(--text-sm);
    --font-size-base: var(--text-base);
    --font-size-lg: var(--text-lg);
    --font-size-xl: var(--text-xl);
    --font-size-2xl: var(--text-2xl);
}

/* Dark theme: brand-ink is unreadable as text on dark surfaces, so the legacy
   bridge name that points at it re-points to the themed text colour. */
.theme-dark {
    --primary-color: var(--color-text);
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background-color: var(--color-bg);

}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

#headerBackSlot .btn {
    font-size: 0.85rem;
    padding: 0.3rem 0.75rem;
}

.app-header h1 {
    font-family: var(--font-family);
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: #000;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.app-header h1 img {
    height: 32px;
    width: 32px;
    filter: invert(1);
}

/* Sidebar */
.app-sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    width: var(--sidebar-width);
    background-color: var(--color-surface);
    border-right: 1px solid var(--gray-200);
    overflow: hidden; /* the nav scrolls; the user menu stays pinned at the foot */
    padding: 0;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, transform 0.25s ease;
    z-index: 90;
}
.app-sidebar > nav {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding: 1rem 0;
}

/* Bottom-left user menu */
.sidebar-user {
    flex: 0 0 auto;
    position: relative;
    border-top: 1px solid var(--gray-200);
    padding: 0.5rem;
}
.sidebar-user-trigger {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem 0.5rem;
    border-radius: var(--border-radius);
    text-align: left;
}
.sidebar-user-trigger:hover { background-color: var(--gray-100); }
.sidebar-user-avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--brand-blue, #017EFF);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.78rem;
}
.sidebar-user-name {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1 1 auto;
    min-width: 0;
}
.sidebar-user-fullname {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-800);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-tenant { font-size: 0.72rem; color: var(--gray-500); }
.sidebar-user-caret { flex: 0 0 auto; color: var(--gray-500); font-size: 0.8rem; }
.sidebar-user-menu {
    position: absolute;
    bottom: calc(100% - 0.25rem);
    left: 0.5rem;
    right: 0.5rem;
    background: var(--color-surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    box-shadow: 0 6px 20px rgba(0, 1, 45, 0.14);
    padding: 0.35rem;
    z-index: 95;
}
.sidebar-user-menu.hidden { display: none; }
.sidebar-user-menu a {
    display: block;
    padding: 0.5rem 0.6rem;
    border-radius: 4px;
    color: var(--gray-800);
    text-decoration: none;
    font-size: 0.85rem;
}
.sidebar-user-menu a:hover { background-color: var(--gray-100); }

/* Theme row: "Theme" label left, a Light/Dark switch right. The switch is a
   functional control (not decoration); checked = dark. */
.sidebar-user-theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: 4px;
    color: var(--gray-800);
    font-size: 0.85rem;
}
.sidebar-user-theme:hover { background-color: var(--gray-100); }
.theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    font: inherit;
    color: var(--gray-500);
}
.theme-switch-side { font-size: 0.7rem; letter-spacing: 0.02em; }
.theme-switch[aria-checked="false"] .theme-switch-side:first-child,
.theme-switch[aria-checked="true"] .theme-switch-side:last-child {
    color: var(--gray-800);
    font-weight: 600;
}
.theme-switch-track {
    width: 30px;
    height: 16px;
    border-radius: 8px;
    background: var(--gray-300);
    position: relative;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.theme-switch[aria-checked="true"] .theme-switch-track { background: var(--primary-color); }
.theme-switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-surface, #fff);
    box-shadow: 0 1px 2px rgba(0, 1, 45, 0.25);
    transition: left 0.15s ease;
}
.theme-switch[aria-checked="true"] .theme-switch-knob { left: 16px; }

/* Sidebar toggle button */
.sidebar-toggle {
    position: fixed;
    top: var(--header-height);
    left: var(--sidebar-width);
    width: 24px;
    height: 40px;
    background: var(--color-surface);
    border: 1px solid var(--gray-200);
    border-left: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 91;
    transition: left 0.25s ease;
    color: var(--gray-500);
    font-size: 0.75rem;
    padding: 0;
    margin-top: 8px;
}

.sidebar-toggle:hover {
    background: var(--gray-100);
    color: var(--primary-color);
}

/* Collapsed state */
.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
    overflow: hidden;
}

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

.sidebar-collapsed .app-main {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

/* Expand/Collapse All Toggle */
.menu-expand-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.15rem 1rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--gray-500);
    transition: color 0.2s;
    user-select: none;
    line-height: 1;
}

.menu-expand-toggle:hover {
    color: var(--primary-color);
}

.expand-toggle-icon {
    font-size: 0.6rem;
    letter-spacing: -2px;
}

.sidebar-nav {
    list-style: none;
}

.sidebar-nav li {
    margin: 0;
}

/* Menu Section Header */
.menu-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    color: var(--gray-900);
    font-weight: 600;
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    background-color: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    border-bottom: 1px solid var(--gray-200);
    margin-top: 0.5rem;
}

.menu-section-header:first-child {
    margin-top: 0;
}

.menu-section-header:hover {
    background-color: var(--gray-100);
}

.menu-section-header .section-icon {
    font-size: 0.875rem;
    transition: transform 0.2s;
}

.menu-section.collapsed .section-icon {
    transform: rotate(-90deg);
}

/* Menu Section Content */
.menu-section-content {
    display: block;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.menu-section.collapsed .menu-section-content {
    display: none;
}

/* Menu Items */
.sidebar-nav a {
    display: block;
    padding: 0.75rem 1.5rem 0.75rem 2.5rem;
    color: var(--gray-700);
    text-decoration: none;
    transition: all 0.2s;
    font-size: var(--font-size-sm);
}

.sidebar-nav a:hover {
    background-color: var(--gray-100);
    color: var(--primary-color);
}

.sidebar-nav a.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 500;
    border-left: 3px solid var(--primary-hover);
}

/* Menu Subgroups */
.menu-subgroup {
    margin: 0;
}

.menu-subgroup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    color: var(--gray-700);
    font-weight: 500;
    font-size: 0.8rem;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--gray-100);
}

.menu-subgroup-header:hover {
    background-color: var(--gray-100);
    color: var(--primary-color);
}

.menu-subgroup-header .subgroup-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-subgroup-header .subgroup-icon {
    font-size: 0.65rem;
    color: var(--gray-400);
    transition: transform 0.2s;
}

.menu-subgroup.collapsed .subgroup-icon {
    transform: rotate(-90deg);
}

.menu-subgroup-content {
    display: block;
    overflow: hidden;
    background-color: var(--gray-50);
}

.menu-subgroup.collapsed .menu-subgroup-content {
    display: none;
}

.menu-subgroup-content a {
    padding-left: 3.5rem;
    font-size: 0.85rem;
}

.menu-subgroup-content a:hover {
    background-color: var(--gray-100);
}

/* Main Content */
.app-main {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    padding: 2rem;
    flex: 1;
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.25s ease, width 0.25s ease;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h2 {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    color: var(--gray-900);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: var(--font-size-base);
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: #4b5563; /* mid/dark grey — default action button */
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #374151;
}

.btn-secondary {
    background-color: var(--gray-500);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--gray-600);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: var(--font-size-sm);
}

/* Cards */
.card {
    background-color: var(--color-surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: var(--font-size-lg);
}

.card-body {
    padding: 1.5rem;
}

/* Table */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--color-surface);
}

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

.table th {
    background-color: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tbody tr:hover {
    background-color: var(--gray-50);
}

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

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group.form-inline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.form-group.form-inline > .form-label {
    min-width: 110px;
    margin-bottom: 0;
    white-space: nowrap;
}
.form-group.form-inline > .form-input,
.form-group.form-inline > .form-select,
.form-group.form-inline > .form-textarea {
    flex: 1;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--gray-700);
    font-size: var(--font-size-sm);
}
.form-filter-label {
    
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--gray-700);
    font-size: var(--font-size-sm);
}

.form-label.required::after {
    content: ' *';
    color: var(--danger-color);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: var(--font-size-base);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    transition: border-color 0.2s;
}
.form-filter-input,
.form-filter-select,
.form-filter-textarea {
    padding:  0.5rem 0.75rem;
    margin-right:5px;
    font-size: var(--font-size-base);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    transition: border-color 0.2s;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-error {
    margin-top: 0.25rem;
    font-size: var(--font-size-sm);
    color: var(--danger-color);
}

.form-help {
    margin-top: 0;
    font-size: var(--font-size-sm);
    color: var(--gray-500);
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-checkbox input {
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

/* Modal Footer */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    background-color: var(--gray-50);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: 9999px;
    line-height: 1;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-secondary {
    background-color: var(--gray-200);
    color: var(--gray-700);
}

.badge-primary {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-info {
    background-color: #e0f2fe;
    color: #0369a1;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background-color: var(--color-surface);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: var(--font-size-xl);
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.modal-close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: 1.5rem;
}

/* Alert */
.alert {
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
}

.loading.active {
    display: block;
}

.spinner {
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-500); }
.text-primary { color: var(--primary-color); }
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.hidden { display: none !important; }

/* Horizontal Form Layout */
.form-group-horizontal {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1.5rem;
}

.form-group-horizontal .form-label {
    text-align: right;
    padding-top: 0.5rem;
    font-weight: 500;
}

.form-group-horizontal .form-input,
.form-group-horizontal .form-select,
.form-group-horizontal .form-textarea {
    width: 100%;
    max-width: 500px;
}

/* Inline Form Layout (label and input side by side) */
.form-group-inline {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.form-group-inline .form-label {
    font-weight: 500;
    white-space: nowrap;
    margin-bottom: 0;
}

.form-group-inline .form-input,
.form-group-inline .form-select,
.form-group-inline .form-textarea {
    flex: 1;
}

.form-group-inline .form-text {
    display: block;
    margin-top: 0.25rem;
}

.section-divider {
    border-top: 2px solid #ddd;
    margin: 2rem 0;
    padding-top: 2rem;
}

.section-divider h4 {
    margin-bottom: 1.5rem;
    color: #333;
    font-size: 1.1rem;
}

h4 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--gray-900);
    font-weight: 600;
}

.expand-icon:hover {
    cursor: pointer;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    gap: 0.5rem;
    padding: 0 1rem;
    background-color: var(--gray-50);
}

.tab-button {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--gray-600);
    transition: all 0.2s;
    margin-bottom: -2px;
}

.tab-button:hover {
    color: var(--primary-color);
    background-color: var(--gray-100);
}

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

/* Artefact-editor inner tabs (distinct from .tabs so the outer modal tabs that
   contain this editor don't clash). */
.ae-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1rem;
}
.ae-tab-btn {
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--gray-600);
    margin-bottom: -2px;
}
.ae-tab-btn:hover { color: var(--primary-color); }
.ae-tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
/* Stack all panels in one grid cell so the container is always as tall as the
   tallest tab — the editor keeps a constant size when switching tabs. Inactive
   panels stay laid out (for sizing) but hidden + non-interactive. */
.ae-panels { display: grid; }
.ae-tab-panel { grid-column: 1; grid-row: 1; min-width: 0; visibility: hidden; }
.ae-tab-panel.active { visibility: visible; }

/* Read-only formatted artefact view (artefact-view-modal.js). */
.view-box {
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    background-color: var(--gray-50);
}

.tab-content {
    display: none;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    /* Reset leftovers from the earlier .modal rule (max-height:90vh capped the
       backdrop ~10% short of full height; border-radius is moot full-screen). */
    max-height: none;
    border-radius: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    overflow-y: auto;
}

.modal.hidden {
    display: none !important;
}

/* Modals can open over each other (the content editor over the list-items modal
   when editing a child; the list-items modal over the content editor via a ref
   field's "Edit list"). showModalFresh() lifts each freshly shown modal above the
   last via an inline z-index, so the last-opened is always on top regardless of
   DOM order. This static lift is a fallback baseline for these stackable modals.
   The content editor is instance-scoped (a fresh `.artefact-content-modal` per
   open), so it's targeted by class, not id. */
.artefact-content-modal,
#reusableContentModal,
#artefactViewModal {
    z-index: 10001;
}

/* Drag-to-reorder rows: artefact rows in a stage, list-item rows in the
   children modal. */
tr.artefact-row[draggable="true"],
tr.ach-row[draggable="true"] {
    cursor: move;
}
tr.artefact-row.dragging,
tr.ach-row.dragging {
    opacity: 0.5;
    background: var(--gray-100);
}

.modal-content {
    background-color: var(--color-surface);
    border-radius: var(--border-radius);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Flex column so the header stays put and only the body scrolls. The drag
       offset (set by modal-drag.js) combines with the centering transform. */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    flex: 0 0 auto;
    cursor: move;        /* drag handle (see modal-drag.js) */
    user-select: none;
}

/* The body is the only scrolling region; header (above) and any action bar
   (below, sticky) stay visible. */
.modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
}

/* Keep a modal's action bar (e.g. Save/Cancel) visible at the foot while the
   body scrolls. Works wherever the actions are the last block in the body.
   z-index: scrolling content (buttons with hover transforms, the markdown
   editor) creates stacking contexts that would otherwise paint THROUGH the
   bar; the border-top + negative bottom margin close the see-through seams
   at the scroll container's bottom padding. */
.modal-body .form-actions,
.modal-body .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background-color: var(--color-surface);
    border-top: 1px solid var(--gray-200);
    margin-bottom: -1.5rem;     /* cover the .modal-body bottom padding */
    padding-bottom: 1.5rem;
}

.modal-header h3 {
    margin: 0;
    font-size: var(--font-size-xl);
    color: var(--gray-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background-color: var(--gray-100);
    color: var(--gray-700);
}

.modal-body {
    padding: 1.5rem;
}

/* Alert Info Style */
.alert.alert-info {
    background-color: #e0f2fe;
    color: #0369a1;
    border-left: 4px solid var(--info-color);
}

/* =====================================================
   Document Cards
   ===================================================== */

.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.document-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    padding: 1rem;
    transition: all 0.2s;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
}

.document-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.doc-type-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    display: block;
}

.doc-type-icon.pdf { color: #dc3545; }
.doc-type-icon.word { color: #0066cc; }
.doc-type-icon.excel { color: #198754; }
.doc-type-icon.image { color: #6f42c1; }
.doc-type-icon.generic { color: var(--gray-500); }

.document-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--gray-900);
    font-size: 0.95rem;
    word-break: break-word;
}

.document-meta {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}

.document-meta div {
    margin-bottom: 0.125rem;
}

.document-notes {
    font-size: 0.8rem;
    color: var(--gray-600);
    margin-top: 0.5rem;
    line-height: 1.4;
    text-align: left;
}

.document-actions {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    gap: 0.35rem;
}

.document-actions .btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: var(--border-radius);
}

/* Document Filter Bar */
.document-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.document-filters .form-input,
.document-filters .form-select {
    min-width: 150px;
}

/* File Drop Zone */
.file-drop-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
    background: var(--gray-50);
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.file-drop-zone .drop-icon {
    font-size: 3rem;
    color: var(--gray-400);
    margin-bottom: 1rem;
}

.file-drop-zone p {
    margin: 0;
    color: var(--gray-600);
}

.file-drop-zone .browse-link {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}

/* Document Card Layout (Enhanced) */
.document-card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    text-align: left;
    margin-bottom: 0.75rem;
}

.document-icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}

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

.document-card-body {
    text-align: left;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-100);
}

.document-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem 1rem;
    font-size: 0.8rem;
}

.document-card-actions {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-100);
    justify-content: center;
}

.document-card-actions .btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: var(--border-radius);
}

/* Specification Details in PO Lines */
.line-row.expanded {
    background-color: var(--gray-50);
}

.line-row .expand-btn {
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--gray-600);
    width: 24px;
    height: 24px;
}

.line-row .expand-btn:hover {
    color: var(--primary);
}

.spec-details-row td {
    padding: 0 !important;
    background-color: var(--gray-50);
}

.spec-details-container {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.spec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.spec-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--gray-800);
}

.spec-category {
    margin-bottom: 1.5rem;
}

.spec-category h5 {
    margin: 0 0 0.75rem 0;
    font-size: 0.9rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.spec-params-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.spec-params-table th,
.spec-params-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}

.spec-params-table th {
    background-color: var(--gray-100);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.8rem;
}

.spec-params-table tr:hover {
    background-color: var(--gray-50);
}

.spec-params-table tr.acceptance-criterion {
    background-color: rgba(245, 158, 11, 0.05);
}

.spec-params-table tr.acceptance-criterion:hover {
    background-color: rgba(245, 158, 11, 0.1);
}

.spec-params-table .btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
}

/* Inventory Expandable Rows */
.btn-expand {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-500);
    transition: color 0.2s;
}

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

.inventory-row.expanded {
    background-color: var(--gray-50);
}

.inventory-row.expanded td {
    border-bottom: none;
}

/* Grouped inventory styles */
.group-row {
    cursor: pointer;
    background-color: var(--color-surface);
}

.group-row:hover {
    background-color: var(--gray-50);
}

.group-row.expanded {
    background-color: #e3f2fd;
}

.group-row .expand-icon {
    display: inline-block;
    width: 1rem;
    text-align: center;
    font-size: 0.8rem;
}

.batches-row {
    background-color: var(--gray-50);
}

.batches-row.hidden {
    display: none;
}

.batch-row {
    cursor: pointer;
    background-color: var(--color-surface);
}

.batch-row:hover {
    background-color: #f0f7ff;
}

.batch-row.expanded {
    background-color: #e8f4fd;
}

.batch-row .expand-icon {
    display: inline-block;
    width: 1rem;
    text-align: center;
}

.expand-cell {
    width: 40px;
    text-align: center;
}

.movements-row {
    background-color: var(--gray-50);
}

.movements-row.hidden {
    display: none;
}

.movements-cell {
    padding: 0 !important;
}

.movements-container {
    padding: 1rem 1.5rem 1.5rem 3rem;
    border-bottom: 2px solid var(--gray-200);
}

.movements-header {
    margin-bottom: 0.75rem;
    color: var(--gray-700);
}

.movements-count {
    color: var(--gray-500);
    font-weight: normal;
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.movements-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background-color: var(--color-surface);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.movements-table th {
    background-color: var(--gray-100);
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.movements-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}

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

.movements-table tr:hover {
    background-color: var(--gray-50);
}

.movement-date {
    color: var(--gray-600);
    white-space: nowrap;
}

.movement-direction {
    font-weight: 500;
}

.movement-quantity {
    text-align: right;
    font-weight: 600;
    font-family: monospace;
}

td.movement-in,
.movement-in .movement-quantity {
    color: var(--success-color);
}

.movement-in .movement-quantity::before {
    content: '+';
}

td.movement-out,
.movement-out .movement-quantity {
    color: var(--danger-color);
}

.movement-out .movement-quantity::before {
    content: '-';
}

.movement-adj .movement-quantity {
    color: var(--warning-color);
}

.movements-loading,
.movements-empty,
.movements-error {
    padding: 1rem;
    text-align: center;
    color: var(--gray-500);
}

.movements-error {
    color: var(--danger-color);
}

/* =====================================================
   Leg Group Styles (Activity List)
   ===================================================== */

.leg-parent-row {
    cursor: pointer;
    background-color: var(--gray-100);
}

.leg-parent-row:hover {
    background-color: var(--gray-200);
}

.leg-parent-row.expanded {
    background-color: var(--gray-50);
    border-bottom: 2px solid var(--primary-color);
}

.leg-parent-row td {
    font-weight: 600;
}

.leg-toggle {
    display: inline-block;
    width: 1.25rem;
    text-align: center;
    margin-right: 0.25rem;
}

.leg-child-row {
    background-color: var(--gray-50);
}

.leg-child-row.hidden {
    display: none;
}

.leg-child-row td:first-child {
    border-left: 3px solid var(--primary-color);
    padding-left: 1.5rem;
}

.leg-route {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.leg-activity-count {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-left: 0.5rem;
}

.leg-date-range {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Activity Action Rows */
.activity-toggle {
    display: inline-block;
    padding: 2px 3px;
    font-size: 0.8em;
    background: transparent;
    border: 1px solid var(--gray-300);
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 3px;
}

.activity-toggle:hover {
    background-color: var(--gray-100);
    border-color: var(--gray-400);
}

.activity-action-row {
    background-color: #fafafa;
    border-left: 3px solid #90caf9;
}

.activity-action-row td {
    font-size: 0.95em;
    padding: 8px 12px;
}

.action-batch-row {
    background-color: #f5f5f5;
    border-left: 3px solid #c5cae9;
}

.action-batch-row td {
    font-size: 0.9em;
    padding: 6px 12px;
    color: #555;
}

.activity-action-row.hidden,
.action-batch-row.hidden {
    display: none;
}

/* Sequence Position Selector */
.sequence-position-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: var(--border-radius);
    border: 1px solid var(--gray-200);
}

.sequence-position-selector .form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.sequence-position-selector .form-check input[type="radio"] {
    margin: 0;
    flex-shrink: 0;
}

.sequence-position-selector .form-check label {
    margin: 0;
    font-weight: normal;
    white-space: nowrap;
}

.sequence-position-selector .form-check select {
    flex: 1;
    min-width: 150px;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.sequence-position-selector .form-check select:disabled {
    background-color: var(--gray-100);
    cursor: not-allowed;
}

/* Standalone activity row (no leg) */
.standalone-activity-row {
    background-color: var(--color-surface);
}

.standalone-activity-row:hover {
    background-color: var(--gray-50);
}

/* =====================================================
   Popup / Modal Overlays
   ===================================================== */

.popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-in-out;
}

.popup.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.popup-content {
    background: var(--color-surface);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

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

.popup-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}

.popup-header h3 {
    margin: 0;
    font-size: var(--font-size-xl);
    color: var(--gray-900);
}

.popup-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    padding: 0;
}

.popup-close:hover {
    background-color: var(--gray-100);
    color: var(--gray-700);
}

.popup-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.popup-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* =====================================================
   Transit Inventory Styles
   ===================================================== */

.transit-row {
    background-color: #fefefe;
}

.transit-row.expanded {
    background-color: #f0f9ff;
}

.transit-details-row {
    background-color: #f8fafc;
}

.transit-details-row.hidden {
    display: none;
}

.transit-details-cell {
    padding: 0 !important;
}

.transit-details-container {
    padding: 1rem;
    background-color: #f8fafc;
}

.transit-details-header {
    font-weight: 600;
    margin-bottom: 1rem;
    font-size: var(--font-size-lg);
    color: var(--gray-800);
}

.transit-details-loading,
.transit-details-empty,
.transit-details-error {
    padding: 1rem;
    text-align: center;
    color: var(--gray-500);
}

.transit-details-error {
    color: var(--danger-color);
}

/* ============================================
   Activity Detail Tabbed View
   ============================================ */

/* Popup size override */
.activity-detail-popup {
    max-width: 90% !important;
    width: 90% !important;
    height: 90vh;
    display: flex;
    flex-direction: column;
}

.activity-detail-popup .popup-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    padding: 1rem 1.5rem;
}

/* Two-column form grid */
.activity-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0;
}

.activity-detail-grid .form-group-inline {
    margin-bottom: 0;
}

.activity-detail-grid .form-group-inline label {
    min-width: 110px;
    font-size: var(--font-size-sm);
}

.activity-detail-grid .full-span {
    grid-column: 1 / -1;
}

/* Tab area */
.activity-detail-tabs {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    margin-top: 0.5rem;
}

.activity-detail-tabs .tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    flex-shrink: 0;
}

.activity-detail-tabs .tab-button {
    padding: 0.5rem 1.25rem;
    font-size: var(--font-size-sm);
}

.activity-detail-tabs .tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    display: none;
}

.activity-detail-tabs .tab-content.active {
    display: block;
}

/* Actions table */
.actions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.actions-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-600);
}

.actions-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}

.actions-table .action-row {
    cursor: pointer;
    transition: background 0.15s;
}

.actions-table .action-row:hover {
    background: var(--gray-50);
}

.actions-table .action-sub-rows {
    display: none;
}

.actions-table .action-sub-rows.expanded {
    display: table-row;
}

.actions-table .sub-row-cell {
    padding: 0.5rem 0.75rem 0.5rem 2rem;
    background: #f8fafc;
}

.sub-section-title {
    font-weight: 600;
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.sub-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    font-size: var(--font-size-sm);
}

.sub-item .btn {
    padding: 0.15rem 0.5rem;
    font-size: var(--font-size-xs);
}

/* Losses table */
.losses-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.losses-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-600);
}

.losses-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}

/* Document cards grid for activity detail */
.activity-doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.activity-doc-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    padding: 0.75rem;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    transition: all 0.2s;
}

.activity-doc-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.activity-doc-card .doc-title {
    font-weight: 600;
    font-size: var(--font-size-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-doc-card .doc-meta {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
}

.activity-doc-card .doc-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.doc-source-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: var(--border-radius-sm);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--gray-100);
    color: var(--gray-600);
}

/* Upload drop zone for activity docs/pics */
.activity-upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-500);
    margin-bottom: 0.75rem;
}

.activity-upload-zone:hover,
.activity-upload-zone.drag-over {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.04);
    color: var(--primary-color);
}

/* Picture thumbnail grid */
.picture-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.picture-thumbnail {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--gray-200);
    transition: all 0.2s;
}

.picture-thumbnail:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.picture-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.picture-thumbnail .pic-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
}

.picture-thumbnail:hover .pic-delete {
    display: flex;
}

/* Lightbox overlay */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: pointer;
}

.lightbox-overlay img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: var(--border-radius-lg);
}

/* Vehicle map picker */
.vehicle-map-popup .popup-content {
    max-width: 800px;
    width: 90%;
}

/* Empty state */
.activity-tab-empty {
    text-align: center;
    padding: 2rem;
    color: var(--gray-400);
    font-style: italic;
}

/* Badge for loss types */
.loss-type-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
}

.loss-type-badge.SPILLAGE { background: #fef3c7; color: #92400e; }
.loss-type-badge.EVAPORATION { background: #dbeafe; color: #1e40af; }
.loss-type-badge.CONTAMINATION { background: #fce7f3; color: #9d174d; }
.loss-type-badge.THEFT { background: #fee2e2; color: #991b1b; }
.loss-type-badge.DAMAGE { background: #ffedd5; color: #9a3412; }
.loss-type-badge.OTHER { background: var(--gray-100); color: var(--gray-600); }

/* Batch Color Dots */
.batch-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.batch-color-dot.color-red { background-color: #ef4444; }
.batch-color-dot.color-blue { background-color: #3b82f6; }
.batch-color-dot.color-green { background-color: #22c55e; }
.batch-color-dot.color-orange { background-color: #f97316; }
.batch-color-dot.color-purple { background-color: #a855f7; }
.batch-color-dot.color-yellow { background-color: #eab308; }
.batch-color-dot.color-pink { background-color: #ec4899; }
.batch-color-dot.color-teal { background-color: #14b8a6; }
.batch-color-dot.color-brown { background-color: #a16207; }
.batch-color-dot.color-grey { background-color: #6b7280; }

/* Document view toggle */
.doc-view-toggle {
    display: flex;
    gap: 2px;
    margin-left: auto;
}
.btn-toggle {
    background: var(--gray-100);
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-toggle:first-child { border-radius: var(--border-radius) 0 0 var(--border-radius); }
.btn-toggle:last-child { border-radius: 0 var(--border-radius) var(--border-radius) 0; }
.btn-toggle.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Document list table */
.document-list { width: 100%; border-collapse: collapse; }
.document-list th,
.document-list td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--gray-200); font-size: 0.875rem; }
.document-list th { background: var(--gray-50); font-weight: 600; color: var(--gray-700); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.document-list tbody tr:hover { background: var(--gray-50); }
.document-list .doc-list-title { font-weight: 500; display: flex; align-items: center; gap: 0.5rem; }
.document-list .doc-list-actions { display: flex; gap: 0.25rem; justify-content: flex-end; }

/* Document AI summary spinner */
.doc-ai-spinner {
    cursor: default;
    opacity: 0.7;
}
.doc-spin-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Highlighted Notes Flyout */
.highlighted-notes-flyout {
    position: absolute;
    top: 100%;
    right: 0;
    width: 350px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
}
.flyout-header {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}
.flyout-body { padding: 0.5rem; }
.flyout-item {
    padding: 0.6rem 0.75rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    border-left: 3px solid var(--warning-color);
    margin-bottom: 0.4rem;
    background: #fffdf5;
}
.flyout-item:hover { background: var(--gray-100); }
.flyout-item-title {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
}
.flyout-item-body {
    font-size: 0.8rem;
    color: var(--gray-600);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
/* Star button active state */
.btn-star { color: var(--warning-color); font-size: 1.1rem; }

/* SO Allocation UI */
.so-dropdown {
    min-width: 160px;
    font-size: 0.875rem;
}
.so-dropdown-cell {
    min-width: 180px;
}
.so-alloc-subrow {
    background: #f9fafb;
}
.so-alloc-subrow td {
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    font-size: 0.875rem;
    color: #6b7280;
}
.so-alloc-subrow .form-input {
    width: 120px;
    font-size: 0.875rem;
}
.so-filter-bar {
    background: #eff6ff;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    border-left: 4px solid #3b82f6;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.so-filter-bar label {
    font-weight: 500;
    color: #1e40af;
    white-space: nowrap;
}
.so-filter-bar select {
    flex: 1;
    min-width: 200px;
}

/* ==========================================================================
   ADM THEME — component overrides on the token system (css/tokens.css)
   Everything above is the inherited base; these rules win by source order and
   give the app the ADM look (Inter + JetBrains Mono, navy ink, blue accent).
   ========================================================================== */

body {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    line-height: var(--leading-snug);
}

/* ---- Links: accent colour, visited === unvisited (no purple) ----
   Low-specificity base rule, so button-styled (.btn) and sidebar links keep
   their own colours; it only colours bare content anchors, for both states. */
a { color: var(--color-accent); }

/* ---- Breadcrumb: muted parent link before the current page title ---- */
#projectTitle .breadcrumb-parent { color: var(--gray-900); font-weight: 600; }
#projectTitle .breadcrumb-parent:hover { color: var(--color-accent); }

/* ---- Header + brand ---- */
.app-header { padding: 0 1.5rem; box-shadow: none; }
.app-header h1 {
    gap: 0.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
    font-size: var(--text-lg);
}
.app-header h1 img.brand-mark {
    height: 30px; width: 30px;
    filter: none;                 /* colour mark — do not invert */
    border-radius: var(--radius-md);
    background: #fff; padding: 3px;
    object-fit: contain;
    box-shadow: var(--shadow-sm);
}
.brand-dot { color: var(--brand-blue); }

/* ---- Buttons ---- */
.btn { font-size: var(--text-sm); font-weight: 500; border-radius: var(--radius-sm); }
.btn-primary { background-color: var(--color-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background-color: var(--color-accent-hover); }
.btn-secondary {
    background-color: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border-strong);
}
.btn-secondary:hover:not(:disabled) {
    background-color: var(--color-surface-alt);
    border-color: var(--color-text-faint);
}
.btn-danger { background-color: var(--danger); color: #fff; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---- Sidebar nav ---- */
.app-sidebar { padding: 0.75rem; }
.menu-section-header {
    background: transparent; border: none; margin-top: 0.75rem;
    padding: 0.4rem 0.7rem;
    font-family: var(--font-mono);
    font-size: var(--text-xs); letter-spacing: 0.06em;
    color: var(--color-text-faint);
}
.menu-section-header:first-child { margin-top: 0; }
.menu-section-header:hover { background: transparent; color: var(--color-text-muted); }
.sidebar-nav a {
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-weight: 500;
    border-left: 2px solid transparent;
}
.sidebar-nav a:hover { background: var(--color-surface-alt); color: var(--color-text); }
.sidebar-nav a.active {
    background: var(--color-accent-wash);
    color: var(--color-accent);
    border-left: 2px solid var(--color-accent);
    font-weight: 600;
}

/* ---- Inputs: themed surface (legacy rules leave the UA default, which stays
   white in dark mode) + accent focus ring ---- */
.form-input, .form-select, .form-textarea,
.form-filter-input, .form-filter-select, .form-filter-textarea {
    background-color: var(--color-surface);
    color: var(--color-text);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-accent);
    box-shadow: var(--ring);
}

/* ---- Tables: quiet column-titles bar ---- */
.table th {
    background: var(--color-surface-alt);
    color: var(--color-text-faint);
    font-size: var(--text-xs);
    font-weight: 600;
}
.table td { font-size: var(--text-sm); }
.table-actions { gap: 0.15rem; align-items: center; }

/* ---- Cards ---- */
.card { border-radius: var(--radius-lg); }
.card-header { background: transparent; }

/* ---- Status pills (read-only artefact / list statuses) ---- */
.status-pill {
    display: inline-flex; align-items: center; gap: 0.35rem;
    font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 500;
    letter-spacing: 0.03em;
    padding: 0.2rem 0.55rem; border-radius: var(--radius-full);
    white-space: nowrap;
}
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.status-waiting  { color: var(--status-waiting);  background: var(--status-waiting-bg); }
.status-pill.status-started  { color: var(--status-started);  background: var(--status-started-bg); }
.status-pill.status-review   { color: var(--status-review);   background: var(--status-review-bg); }
.status-pill.status-complete { color: var(--status-complete); background: var(--status-complete-bg); }
/* To-do tally — pastel purple, distinct from the artefact-status colours. */
.status-pill.status-todo     { color: #6d28d9; background: #ede9fe; }
.theme-dark .status-pill.status-todo { color: #B9A1FF; background: rgba(124, 58, 237, 0.20); }

/* ---- Outline icon buttons (row actions) ---- */
.icon-btn {
    border: none; background: transparent; cursor: pointer;
    padding: 0.3rem; border-radius: var(--radius-sm);
    color: var(--color-text-faint);
    display: inline-grid; place-items: center;
    transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--color-surface-alt); color: var(--color-text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn .ico { width: 17px; height: 17px; display: block; }

/* outline icon: stroke only, no fill */
.ico { fill: none; stroke: currentColor; stroke-width: 1.85; stroke-linecap: round; stroke-linejoin: round; }
.btn .ico { width: 15px; height: 15px; }   /* svg inside a filled .btn (e.g. delete) */