html, body {
    font-family: var(--brand-font), 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* Brand Colors - Multi-tenant theming via CSS custom properties */
:root {
    --brand-primary: #4A90D9;
    --brand-primary-dark: #2a5f9e;
    --brand-on-primary: #ffffff;
    --brand-secondary: #6BB54A;
    --brand-secondary-dark: #4a8b32;
    --brand-accent: #606062;
    --brand-font: 'Inter', sans-serif;

    /* Surface colors for light mode (used by Tailwind @theme) */
    --surface-bg: #ffffff;
    --surface-card: #ffffff;
    --surface-border: #e5e7eb;
    --surface-input: #ffffff;
    --surface-muted: #f3f4f6;
    --surface-dropdown: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
}

/* Dark mode surfaces — activated by .dark on <html> */
.dark {
    --surface-bg: #1e1e2d;
    --surface-card: #1e293b;
    --surface-border: #334155;
    --surface-input: #273044;
    --surface-muted: #1e293b;
    --surface-dropdown: #2a3a50;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    color-scheme: dark;
}

/* ===== Dark mode overrides for Tailwind gray utilities ===== */
/* Tailwind utilities live in @layer and get overridden by unlayered CSS.
   These remap light-only bg/text grays to dark-friendly equivalents. */
.dark .bg-gray-50 {
    background-color: rgba(255, 255, 255, 0.03);
}
.dark .bg-gray-100 {
    background-color: rgba(255, 255, 255, 0.06);
}
.dark .hover\:bg-gray-50:hover {
    background-color: rgba(255, 255, 255, 0.05);
}
.dark .hover\:bg-gray-100:hover {
    background-color: rgba(255, 255, 255, 0.08);
}
/* Alert/status backgrounds in dark mode */
.dark .bg-red-50 {
    background-color: rgba(239, 68, 68, 0.1);
}
.dark .bg-green-50 {
    background-color: rgba(34, 197, 94, 0.1);
}
.dark .bg-yellow-50 {
    background-color: rgba(234, 179, 8, 0.1);
}
.dark .bg-blue-50 {
    background-color: rgba(59, 130, 246, 0.1);
}
/* Alert/status text in dark mode */
.dark .text-red-800 {
    color: #fca5a5;
}
.dark .text-green-800 {
    color: #86efac;
}
.dark .text-yellow-800 {
    color: #fde047;
}
.dark .text-blue-800 {
    color: #93c5fd;
}
/* Alert/status borders in dark mode */
.dark .border-red-300 {
    border-color: rgba(239, 68, 68, 0.3);
}
.dark .border-green-300 {
    border-color: rgba(34, 197, 94, 0.3);
}
.dark .border-yellow-300 {
    border-color: rgba(234, 179, 8, 0.3);
}
.dark .border-blue-300 {
    border-color: rgba(59, 130, 246, 0.3);
}
/* Badge backgrounds in dark mode */
.dark .bg-gray-100,
.dark .bg-red-100,
.dark .bg-green-100,
.dark .bg-yellow-100,
.dark .bg-blue-100 {
    background-color: rgba(255, 255, 255, 0.08);
}
.dark .text-gray-800 {
    color: #cbd5e1;
}
/* Hover on gray buttons in dark mode */
.dark .hover\:bg-gray-500:hover {
    background-color: rgba(255, 255, 255, 0.15);
}
.dark .hover\:bg-red-50:hover {
    background-color: rgba(239, 68, 68, 0.15);
}

/* White backgrounds → dark surface */
.dark .bg-white {
    background-color: var(--surface-card);
}

/* Gray text colors → lighter for dark mode readability */
.dark .text-gray-900 {
    color: #f1f5f9;
}
.dark .text-gray-700 {
    color: #cbd5e1;
}
.dark .text-gray-600 {
    color: #94a3b8;
}
.dark .text-gray-500 {
    color: #94a3b8;
}

/* Gray borders → subtle on dark surfaces */
.dark .border-gray-300 {
    border-color: var(--surface-border);
}
.dark .border-gray-400 {
    border-color: rgba(255, 255, 255, 0.2);
}

/* Additional gray backgrounds */
.dark .bg-gray-200 {
    background-color: rgba(255, 255, 255, 0.08);
}
.dark .bg-gray-300 {
    background-color: rgba(255, 255, 255, 0.1);
}
.dark .hover\:bg-gray-200:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Dividers */
.dark .divide-gray-200 > :not(:last-child) {
    border-color: var(--surface-border);
}

/* Form styling */
.section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #f8f9fa;
}

.section h5 {
    color: var(--brand-primary-dark);
    border-bottom: 2px solid var(--brand-secondary);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--brand-primary);
}

/* Modal overlay backdrop */
.modal-overlay {
    background-color: rgba(0, 0, 0, 0.5);
}

.content {
    padding-top: 1.1rem;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

/* UX Improvements - Phase 1 */

/* Auto-save indicator */
.autosave-indicator {
    position: fixed;
    top: 70px;
    right: 20px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.autosave-indicator .autosave-icon {
    display: flex;
    align-items: center;
}

.autosave-indicator .autosave-text {
    font-weight: 500;
}

.autosave-indicator .autosave-time {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-left: 4px;
}

.autosave-saving {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
}

.autosave-saved {
    background-color: #d1f2eb;
    border: 1px solid var(--brand-secondary);
    color: #0f5132;
}

.autosave-error {
    background-color: #f8d7da;
    border: 1px solid #dc3545;
    color: #842029;
}

/* Required field indicator */
.required-field::after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

.required-count {
    font-size: 0.875rem;
    color: #6c757d;
    font-weight: normal;
}

/* Field help tooltip icon */
.field-help-icon {
    color: var(--brand-primary);
    cursor: help;
    margin-left: 6px;
    font-size: 0.875rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.field-help-icon:hover {
    opacity: 1;
}

/* Real-time validation styling */
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #dc3545;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-valid,
.form-select.is-valid {
    border-color: var(--brand-secondary);
    padding-right: calc(1.5em + 0.75rem);
    /* Note: SVG data URIs cannot use CSS custom properties; update %236BB54A for tenant theming */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%236BB54A' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.invalid-feedback {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #dc3545;
}

.invalid-feedback.show {
    display: block;
}

/* Landing page styles */
.landing-hero {
    background: linear-gradient(135deg, var(--brand-primary-dark) 0%, var(--brand-primary) 100%);
    color: white;
    padding: 4rem 2rem;
    text-align: center;
    margin-bottom: 3rem;
    border-radius: 0.5rem;
}

.landing-hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.landing-hero p {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.95;
}

.landing-feature {
    text-align: center;
    padding: 2rem 1rem;
}

.landing-feature-icon {
    font-size: 3rem;
    color: var(--brand-secondary);
    margin-bottom: 1rem;
}

.landing-feature h3 {
    color: var(--brand-primary-dark);
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.landing-cta {
    text-align: center;
    padding: 3rem 2rem;
    background-color: #f8f9fa;
    border-radius: 0.5rem;
    margin-top: 3rem;
}

.landing-cta h2 {
    color: var(--brand-primary-dark);
    margin-bottom: 1.5rem;
}

.btn-landing-primary {
    background-color: var(--brand-secondary);
    border-color: var(--brand-secondary);
    color: white;
    padding: 0.75rem 2rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-radius: 0.375rem;
    transition: all 0.3s;
}

.btn-landing-primary:hover {
    background-color: var(--brand-secondary-dark);
    border-color: var(--brand-secondary-dark);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNy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has occurred."
    }

/* Blazor error UI - hidden by default, shown on JS errors */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}


.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* Form cards on home page */
.form-card {
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #dee2e6;
}

.form-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-color: var(--brand-primary);
}

.form-card .card-title {
    color: var(--brand-primary-dark);
}

/* Text utilities */
.text-on-brand {
    color: var(--brand-on-primary, #ffffff) !important;
}

/* Sortable table headers */
.sortable-header {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.sortable-header:hover {
    color: var(--brand-primary, #4A90D9);
}

/* ===== Clean sidebar overrides ===== */
/* When .sidebar-clean is applied (MainLayout), override NavMenu's
   white-on-gradient defaults with theme-aware colors.
   Uses .sidebar.sidebar-clean for extra specificity over scoped CSS. */

.sidebar.sidebar-clean .top-row {
    background-color: transparent;
    border-bottom: 1px solid var(--surface-border, #e5e7eb);
}

.sidebar.sidebar-clean .navbar-toggler {
    color: var(--text-primary, #1f2937);
    border-color: var(--surface-border, #e5e7eb);
}

.sidebar.sidebar-clean .nav-section-label {
    color: var(--text-secondary, #6b7280);
}

.sidebar.sidebar-clean .nav-category-header {
    color: var(--text-primary, #1f2937);
}

.sidebar.sidebar-clean .nav-category-header:hover {
    background-color: var(--surface-border, #e5e7eb);
}

.sidebar.sidebar-clean .category-chevron {
    border-color: var(--text-secondary, #6b7280);
}

.sidebar.sidebar-clean .nav-item .nav-link {
    color: var(--text-secondary, #6b7280);
}

.sidebar.sidebar-clean .nav-item .nav-link:hover {
    background-color: var(--surface-border, #e5e7eb);
    color: var(--text-primary, #1f2937);
}

.sidebar.sidebar-clean .nav-item a.active {
    background-color: var(--brand-primary, #4A90D9);
    color: white;
}

.sidebar.sidebar-clean .nav-category-items .nav-link {
    color: var(--text-secondary, #6b7280);
}

.sidebar.sidebar-clean .nav-category-items .nav-link:hover {
    background-color: var(--surface-border, #e5e7eb);
    color: var(--text-primary, #1f2937);
}

.sidebar.sidebar-clean .nav-category-items .nav-link.active {
    background-color: var(--brand-primary, #4A90D9);
    color: white;
}

.sidebar.sidebar-clean .version-info {
    color: var(--text-secondary, #6b7280);
}

/* Clean sidebar light mode: convert white SVG icons to dark */
.sidebar.sidebar-clean .bi {
    filter: brightness(0) saturate(100%) invert(40%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(90%);
}

/* Clean sidebar dark mode: keep icons light (white SVGs on dark bg) */
.dark .sidebar.sidebar-clean .bi {
    filter: none;
    opacity: 0.7;
}

/* Active item icons: always white on brand-primary background */
.sidebar.sidebar-clean .nav-item a.active .bi,
.sidebar.sidebar-clean .nav-category-items .nav-link.active .bi {
    filter: brightness(0) invert(1);
    opacity: 1;
}

/* ===== Collapsed sidebar adjustments ===== */
/* Center icons in the 68px rail when text is hidden */

.sidebar.sidebar-collapsed .nav-category-header {
    justify-content: center;
    padding: 0.5rem;
}

.sidebar.sidebar-collapsed .nav-item .nav-link {
    justify-content: center;
    padding: 0 0.5rem;
}

.sidebar.sidebar-collapsed .bi {
    margin-right: 0;
}

.sidebar.sidebar-collapsed .version-info {
    font-size: 0.6rem;
    padding: 0.25rem;
}

/* Reconnect modal fallback styling (global).
   Ensures dark theme applies even when scoped CSS isn't attached during reconnect UI rendering. */
#components-reconnect-modal {
    background-color: var(--surface-card, #ffffff) !important;
    color: var(--text-primary, #1f2937) !important;
    border: 1px solid var(--surface-border, #e5e7eb) !important;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45) !important;
}

#components-reconnect-modal::backdrop {
    background-color: rgba(0, 0, 0, 0.6) !important;
}

#components-reconnect-modal .components-rejoining-animation div {
    border-color: var(--brand-primary, #4A90D9) !important;
}

.dark #components-reconnect-modal {
    background-color: var(--surface-card, #1e293b) !important;
    color: var(--text-primary, #f1f5f9) !important;
    border-color: var(--surface-border, #334155) !important;
}

.dark #components-reconnect-modal p,
.dark #components-reconnect-modal button {
    color: var(--text-primary, #f1f5f9) !important;
}
