html,
body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    height: 100%;
}

/* Skip navigation link (WCAG 2.4.1) */
.skip-nav {
    position: absolute;
    top: -100%;
    left: var(--spacing-md);
    z-index: 1001;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--accent-fill-rest, #0078d4);
    color: #fff;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 600;
}

.skip-nav:focus {
    top: var(--spacing-sm);
}

/* Visually hidden — accessible to screen readers (WCAG) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Headings are not interactive — suppress focus outline from programmatic focus */
h1[tabindex="-1"]:focus,
h1[tabindex="-1"]:focus-visible {
    outline: none;
}

/* Focus-visible fallback for all interactive elements (WCAG 2.4.7) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
fluent-button:focus-visible,
fluent-text-field:focus-visible,
fluent-select:focus-visible,
fluent-switch:focus-visible,
fluent-checkbox:focus-visible,
fluent-radio:focus-visible {
    outline: 2px solid var(--accent-fill-rest, #0078d4);
    outline-offset: 2px;
}

a,
.btn-link {
    color: var(--accent-foreground-rest, #0071c1);
}

.content {
    padding-top: 1.1rem;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
    box-sizing: border-box;
}

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

.invalid {
    outline: 1px solid var(--error-foreground, #d13438);
}

.validation-message {
    color: var(--error-foreground, #d13438);
}

#blazor-error-ui {
    background: var(--warning-background, #fffacd);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismi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TgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--neutral-stroke-divider-rest, #e0e0e0);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent-fill-rest, #1b6ec2);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

code {
    color: var(--code-foreground, #c02d76);
}

/* Listbox option rows — ensure adequate height for multi-line items */
.deploy-listbox fluent-option,
.request-history-listbox fluent-option {
    min-height: 50px;
    height: auto;
    padding: 8px 0;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest);
}

/* Remove default border and excess padding from listboxes inside cards and dialogs */
fluent-card fluent-listbox,
fluent-dialog fluent-listbox {
    border: none;
    padding: 0;
}

/* Remove default border from stealth anchors in navigation */
fluent-anchor[appearance="stealth"] {
    border: none;
    outline: none;
}

fluent-anchor[appearance="stealth"]::part(control) {
    border: none;
}

:root {
    --max-height: 200px;

    /* Layout height offset — accounts for header + footer + chrome.
       Adjust this single value if header/footer heights change. */
    --layout-chrome-height: 280px;
    --layout-chrome-height-lg: 350px;

    /* Spacing scale */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-xxl: 48px;

    /* Component-specific spacing */
    --card-padding: var(--spacing-lg);
    --section-gap: var(--spacing-xl);
    --form-field-gap: var(--spacing-md);
    --button-gap: var(--spacing-sm);

    /* Status colors */
    --success-background: rgba(16, 124, 16, 0.1);
    --success-foreground: #107c10;
    --warning-background: rgba(200, 112, 0, 0.1);
    --warning-foreground: #c87000;
    --error-background: rgba(209, 52, 56, 0.1);
    --error-foreground: #d13438;
    --info-background: rgba(0, 120, 212, 0.1);
    --info-foreground: #0078d4;

    /* Layer alpha for overlays */
    --neutral-layer-1-alpha: rgba(255, 255, 255, 0.9);

    /* Inline code color */
    --code-foreground: #c02d76;
}

/* Dark mode status colors — respond to both OS preference and FluentUI theme */
@media (prefers-color-scheme: dark) {
    :root {
        --success-background: rgba(16, 124, 16, 0.2);
        --success-foreground: #7ad97a;
        --warning-background: rgba(255, 185, 0, 0.2);
        --warning-foreground: #ffb900;
        --error-background: rgba(232, 17, 35, 0.2);
        --error-foreground: #ff6b6b;
        --info-background: rgba(0, 120, 212, 0.2);
        --info-foreground: #60cdff;
        --neutral-layer-1-alpha: rgba(32, 32, 32, 0.9);
        --code-foreground: #e491b2;
    }
}

/* FluentUI theme-driven dark mode (user-selected via theme dropdown) */
[data-theme="dark"] :root,
.fluent-dark {
    --success-background: rgba(16, 124, 16, 0.2);
    --success-foreground: #7ad97a;
    --warning-background: rgba(255, 185, 0, 0.2);
    --warning-foreground: #ffb900;
    --error-background: rgba(232, 17, 35, 0.2);
    --error-foreground: #ff6b6b;
    --info-background: rgba(0, 120, 212, 0.2);
    --info-foreground: #60cdff;
    --neutral-layer-1-alpha: rgba(32, 32, 32, 0.9);
    --code-foreground: #e491b2;
}

/* FluentWizard stepper alignment - horizontal steps spread across top.
   FluentUI Blazor does not expose a horizontal mode prop, so layout
   overrides are required. Scoped to .fluent-wizard to avoid leaking. */
.fluent-wizard {
    align-items: flex-start;
    gap: var(--spacing-md);
    flex-direction: column;
}

.fluent-wizard > ol {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: flex-start;
    height: auto;
    flex-shrink: 0;
    padding: var(--spacing-md) 0;
    box-sizing: border-box;
    gap: var(--spacing-sm);
}

/* Step items in horizontal wizard */
.fluent-wizard > ol > li {
    flex: 0 1 auto;
    min-width: 100px;
    max-width: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Wizard content takes full width */
.fluent-wizard > div[class*="content"],
.fluent-wizard > .fluent-wizard-content {
    width: 100%;
}

/* ============================================
   Configuration Area Standardization
   Issue #52 - CSS Standardization
   ============================================ */

/* Standard scroll container for lists/grids */
.config-scroll-container {
    max-height: calc(100vh - var(--layout-chrome-height));
    overflow-y: auto;
    overflow-x: hidden;
}

/* Standard toolbar layout */
.config-toolbar {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    flex-wrap: wrap;
}

/* Standard grid/list container with card styling */
.config-grid-container {
    background: var(--neutral-layer-card-container);
    border: 1px solid var(--neutral-stroke-divider-rest);
    border-radius: 4px;
    overflow: hidden;
}

/* Pagination container */
.config-pagination {
    padding: var(--spacing-sm) 12px;
    border-top: 1px solid var(--neutral-stroke-divider-rest);
    background: var(--neutral-layer-card-container);
}

/* Data grid styling */
.config-data-grid {
    width: 100%;
    table-layout: auto;
}

.config-data-grid fluent-data-grid-cell {
    padding: 6px 10px;
}

.config-data-grid fluent-data-grid-cell[role="columnheader"] {
    font-weight: 600;
}

/* Section header label */
.config-section-header {
    padding-bottom: 5px;
    font-weight: 600;
}

/* Form field with vertical stacking for toggle + help text */
.config-field {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    padding-top: 10px;
}

/* Help text styling - appears below the control */
.config-help-text {
    color: var(--neutral-foreground-hint);
    font-size: 0.875rem;
}

/* Master-detail layout */
.config-master-panel {
    max-height: calc(100vh - var(--layout-chrome-height));
    overflow-y: auto;
}

.config-detail-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* Compact form labels for detail panels */
.config-compact-label {
    padding-top: 6px;
    padding-bottom: var(--spacing-xs);
    font-weight: 600;
}

/* Empty state styling */
.config-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xxl) var(--spacing-lg);
    text-align: center;
    color: var(--neutral-foreground-hint);
}

.config-empty-state h3 {
    margin: var(--spacing-md) 0 var(--spacing-sm) 0;
    color: var(--neutral-foreground-rest);
}

.config-empty-state p {
    margin: 0;
}

/* Tabbed settings container */
.config-tabs-container {
    background: var(--neutral-layer-card-container);
    border: 1px solid var(--neutral-stroke-divider-rest);
    border-radius: 4px;
    padding: var(--spacing-md);
}

.config-tabs-container fluent-tabs {
    width: 100%;
}

.config-tabs-container fluent-tab-panel {
    padding: var(--spacing-md) 0 0 0;
}

/* Settings page container */
.config-settings-container {
    max-width: 900px;
}

.config-settings-card {
    padding: var(--spacing-md);
}

.config-tab-content {
    padding: var(--spacing-md) var(--spacing-sm);
    max-height: calc(100vh - var(--layout-chrome-height-lg));
    overflow-y: auto;
}

/* Info grid for read-only configuration display */
.config-info-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.config-info-row {
    display: grid;
    grid-template-columns: minmax(auto, 180px) 1fr;
    gap: 12px;
    align-items: start;
}

/* Button row alignment */
.config-button-row {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding-top: var(--spacing-md);
}

/* Copy button styling — 44px minimum for touch targets (WCAG 2.5.8) */
.config-copy-button {
    opacity: 0.5;
    transition: opacity 0.15s ease;
    min-width: 44px;
    min-height: 44px;
}

.config-copy-button:hover {
    opacity: 1;
}

/* Monospace text (serial numbers, IDs) */
.config-monospace {
    font-family: var(--font-family-monospace, monospace);
    font-size: 0.9em;
}

/* Dialog styling */
.config-dialog-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.config-dialog-header img {
    width: 48px;
    height: 48px;
    border-radius: 8px;
}

.config-dialog-section {
    padding: var(--spacing-md) 0;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest);
}

.config-dialog-section:last-child {
    border-bottom: none;
}

.config-dialog-info {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--spacing-sm) var(--spacing-md);
    color: var(--neutral-foreground-hint);
    font-size: 0.875rem;
}

.config-dialog-info dt {
    font-weight: 500;
}

.config-dialog-info dd {
    margin: 0;
}

/* Status text colors — use our controlled tokens instead of FluentUI's Color.Success/Warning/Error
   which don't adapt well to dark mode (green text on dark backgrounds has poor contrast) */
.status-text-success { color: var(--success-foreground) !important; }
.status-text-warning { color: var(--warning-foreground) !important; }
.status-text-error { color: var(--error-foreground) !important; }

/* Stale device legend - works in both light and dark mode */
.stale-device-legend {
    background: var(--neutral-layer-1);
    border: 1px solid var(--neutral-stroke-divider-rest);
}

/* Filter/list panel width constraint (used by config tab toolbars) */
.config-filter-panel {
    min-width: 200px;
    max-width: 300px;
}

/* ============================================
   Responsive Breakpoints
   ============================================ */

/* Tablet (≤ 768px) */
@media (max-width: 768px) {
    .content {
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }

    /* Blazor error UI should not obscure mobile form buttons */
    #blazor-error-ui {
        padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0px));
    }

    /* Config toolbar wraps on smaller screens */
    .config-toolbar {
        gap: var(--spacing-xs);
    }

    /* Make data grids scroll horizontally on tablets */
    .config-scroll-container {
        max-height: calc(100vh - var(--layout-chrome-height) - 60px);
    }

    /* Wizard steps shrink */
    .fluent-wizard > ol > li {
        min-width: 70px;
        max-width: 120px;
    }
}

/* Mobile (≤ 480px) */
@media (max-width: 480px) {
    .content {
        padding-left: var(--spacing-xs);
        padding-right: var(--spacing-xs);
    }

    /* Stack info rows vertically on mobile */
    .config-info-row {
        grid-template-columns: 1fr;
        gap: var(--spacing-xs);
    }

    /* Wizard steps stack vertically */
    .fluent-wizard > ol {
        flex-direction: column;
        align-items: stretch;
    }

    .fluent-wizard > ol > li {
        min-width: unset;
        max-width: unset;
    }
}

/* Respect user motion preferences (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
