/*
 * StretchFluentUI — Brand Overrides for Fluent UI Blazor
 * ======================================================
 * Maps the Stretch brand system onto Fluent UI's design‐token CSS custom properties.
 * Supports both light and dark modes via [data-theme] or prefers-color-scheme.
 *
 * Consumed by adding <link> in the host page or via the StretchThemeProvider component.
 */

/* ──────────────────────────────────────────────
   Google Fonts import (Space Mono + Inter)
   ────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* ──────────────────────────────────────────────
   Brand tokens (single source-of-truth)
   ────────────────────────────────────────────── */
:root {
    /* ── Core palette ── */
    --stretch-almost-black: #000A0A;
    --stretch-white: #FFFFFF;
    --stretch-plastic-grey: #EBEDEF;
    --stretch-metal-grey: #1B1F1E;
    --stretch-primary: #00E8DA;
    --stretch-primary-rgb: 0, 232, 218;
    --stretch-secondary: #5909FF;
    --stretch-secondary-rgb: 89, 9, 255;
    --stretch-danger: #F0004C;
    --stretch-danger-rgb: 240, 0, 76;
    --stretch-warning: #FFB020;
    --stretch-success: #00C853;

    /* ── Typography ── */
    --stretch-font-display: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    --stretch-font-body: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

    /* ── Radii ── */
    --stretch-radius-sm: 10px;
    --stretch-radius-md: 14px;
    --stretch-radius-lg: 18px;
    --stretch-radius-pill: 999px;

    /* ── Spacing ── */
    --stretch-space-1: 4px;
    --stretch-space-2: 8px;
    --stretch-space-3: 12px;
    --stretch-space-4: 16px;
    --stretch-space-5: 24px;
    --stretch-space-6: 32px;

    /* ── Elevation ── */
    --stretch-shadow-1: 0 10px 30px rgba(0,0,0,0.35);
    --stretch-shadow-2: 0 18px 55px rgba(0,0,0,0.45);
}

/* ──────────────────────────────────────────────
   DARK MODE (default / preferred)
   ────────────────────────────────────────────── */
:root,
[data-theme="dark"],
.stretch-dark {
    --stretch-bg: var(--stretch-almost-black);
    --stretch-surface: var(--stretch-metal-grey);
    --stretch-surface-translucent: rgba(27, 31, 30, 0.76);
    --stretch-text: var(--stretch-white);
    --stretch-text-secondary: rgba(255, 255, 255, 0.70);
    --stretch-text-tertiary: rgba(255, 255, 255, 0.50);
    --stretch-border: rgba(255, 255, 255, 0.08);
    --stretch-border-strong: rgba(255, 255, 255, 0.16);
    --stretch-hover-bg: rgba(255, 255, 255, 0.08);
    --stretch-active-bg: rgba(0, 232, 218, 0.16);
    --stretch-active-border: rgba(0, 232, 218, 0.30);
    --stretch-focus-ring: 0 0 0 3px rgba(0, 232, 218, 0.18);
    --stretch-input-bg: rgba(27, 31, 30, 0.55);
}

/* ──────────────────────────────────────────────
   LIGHT MODE
   ────────────────────────────────────────────── */
[data-theme="light"],
.stretch-light {
    --stretch-bg: var(--stretch-white);
    --stretch-surface: var(--stretch-plastic-grey);
    --stretch-surface-translucent: rgba(235, 237, 239, 0.85);
    --stretch-text: var(--stretch-almost-black);
    --stretch-text-secondary: rgba(0, 10, 10, 0.65);
    --stretch-text-tertiary: rgba(0, 10, 10, 0.45);
    --stretch-border: rgba(0, 10, 10, 0.10);
    --stretch-border-strong: rgba(0, 10, 10, 0.20);
    --stretch-hover-bg: rgba(0, 10, 10, 0.06);
    --stretch-active-bg: rgba(0, 232, 218, 0.12);
    --stretch-active-border: rgba(0, 232, 218, 0.40);
    --stretch-focus-ring: 0 0 0 3px rgba(0, 232, 218, 0.25);
    --stretch-input-bg: rgba(235, 237, 239, 0.60);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not(.stretch-dark) {
        --stretch-bg: var(--stretch-white);
        --stretch-surface: var(--stretch-plastic-grey);
        --stretch-surface-translucent: rgba(235, 237, 239, 0.85);
        --stretch-text: var(--stretch-almost-black);
        --stretch-text-secondary: rgba(0, 10, 10, 0.65);
        --stretch-text-tertiary: rgba(0, 10, 10, 0.45);
        --stretch-border: rgba(0, 10, 10, 0.10);
        --stretch-border-strong: rgba(0, 10, 10, 0.20);
        --stretch-hover-bg: rgba(0, 10, 10, 0.06);
        --stretch-active-bg: rgba(0, 232, 218, 0.12);
        --stretch-active-border: rgba(0, 232, 218, 0.40);
        --stretch-focus-ring: 0 0 0 3px rgba(0, 232, 218, 0.25);
        --stretch-input-bg: rgba(235, 237, 239, 0.60);
    }
}

/* ──────────────────────────────────────────────
   Base element styling
   ────────────────────────────────────────────── */
body {
    font-family: var(--stretch-font-body);
    color: var(--stretch-text);
    background: var(--stretch-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ──────────────────────────────────────────────
   Typography
   ────────────────────────────────────────────── */
h1, .h1 {
    font-family: var(--stretch-font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
    font-size: clamp(2.2rem, 4vw, 4rem);
    line-height: 1.05;
}

h2, .h2 {
    font-family: var(--stretch-font-display);
    font-weight: 400;
    font-size: clamp(1.25rem, 2vw, 1.75rem);
    line-height: 1.2;
}

h3, .h3 {
    font-family: var(--stretch-font-body);
    font-weight: 600;
    font-size: 1.15rem;
}

p, .body {
    font-family: var(--stretch-font-body);
    font-size: 1rem;
    line-height: 1.55;
}

/* ──────────────────────────────────────────────
   Fluent UI Design Token Overrides
   ────────────────────────────────────────────── */

/*
 * Fluent UI Blazor uses a FluentDesignSystemProvider that sets
 * CSS custom properties on its host element. We override the
 * relevant tokens globally so all Fluent components inherit
 * Stretch branding.
 */

/* Body / typography tokens */
fluent-design-system-provider,
.fluent-design-system-provider,
[fluent-theme] {
    --body-font: var(--stretch-font-body);
    --font-family: var(--stretch-font-body);
    --corner-radius: 10;
    --design-unit: 4;
    --density: 0;
}

/* ──────────────────────────────────────────────
   FluentButton overrides
   ────────────────────────────────────────────── */
fluent-button,
.fluent-button {
    border-radius: var(--stretch-radius-pill) !important;
}

fluent-button::part(control) {
    border-radius: var(--stretch-radius-pill);
    font-family: var(--stretch-font-body);
    font-weight: 600;
    transition: all 0.15s ease;
}

/* Accent button → Stretch Primary */
fluent-button[appearance="accent"]::part(control) {
    background: var(--stretch-primary);
    color: #001010;
    border: none;
}

fluent-button[appearance="accent"]:hover::part(control) {
    background: #00d4c7;
    box-shadow: 0 4px 16px rgba(0, 232, 218, 0.30);
}

fluent-button[appearance="accent"]:active::part(control) {
    background: #00c0b4;
}

/* Optional destructive accent variant for high-risk actions */
fluent-button.buttons-danger::part(control) {
    background: var(--stretch-danger);
    border-color: var(--stretch-danger);
    color: var(--stretch-white);
}

fluent-button.buttons-danger:hover::part(control) {
    background: rgba(var(--stretch-danger-rgb), 0.90);
    box-shadow: 0 4px 16px rgba(var(--stretch-danger-rgb), 0.30);
}

fluent-button.buttons-danger:active::part(control) {
    background: rgba(var(--stretch-danger-rgb), 0.75);
}

/* Neutral / ghost button */
fluent-button[appearance="neutral"]::part(control),
fluent-button[appearance="stealth"]::part(control) {
    background: var(--stretch-hover-bg);
    color: var(--stretch-text);
    border: 1px solid var(--stretch-border);
}

fluent-button[appearance="neutral"]:hover::part(control),
fluent-button[appearance="stealth"]:hover::part(control) {
    background: var(--stretch-active-bg);
    border-color: var(--stretch-active-border);
}

/* Outline button */
fluent-button[appearance="outline"]::part(control) {
    background: transparent;
    color: var(--stretch-primary);
    border: 1px solid var(--stretch-primary);
}

fluent-button[appearance="outline"]:hover::part(control) {
    background: var(--stretch-active-bg);
}

/* ──────────────────────────────────────────────
   FluentCard overrides
   ────────────────────────────────────────────── */
fluent-card,
.fluent-card {
    border-radius: var(--stretch-radius-md) !important;
}

fluent-card::part(control) {
    border-radius: var(--stretch-radius-md);
    background: var(--stretch-surface-translucent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--stretch-border);
    box-shadow: var(--stretch-shadow-1);
}

/* ──────────────────────────────────────────────
   FluentTextField / FluentTextArea overrides
   ────────────────────────────────────────────── */
fluent-text-field::part(root),
fluent-text-area::part(root),
fluent-number-field::part(root),
fluent-search::part(root) {
    border-radius: var(--stretch-radius-sm);
    border: 1px solid var(--stretch-border-strong);
    background: var(--stretch-input-bg);
}

fluent-text-field:focus-within::part(root),
fluent-text-area:focus-within::part(root),
fluent-number-field:focus-within::part(root),
fluent-search:focus-within::part(root) {
    border-color: rgba(0, 232, 218, 0.60);
    box-shadow: var(--stretch-focus-ring);
}

fluent-text-field::part(control),
fluent-text-area::part(control),
fluent-number-field::part(control),
fluent-search::part(control) {
    font-family: var(--stretch-font-body);
    color: var(--stretch-text);
}

/* ──────────────────────────────────────────────
   FluentSelect / FluentCombobox overrides
   ────────────────────────────────────────────── */
fluent-select::part(control),
fluent-combobox::part(control) {
    border-radius: var(--stretch-radius-sm);
    border: 1px solid var(--stretch-border-strong);
    background: var(--stretch-input-bg);
    font-family: var(--stretch-font-body);
    color: var(--stretch-text);
}

fluent-select:focus-within::part(control),
fluent-combobox:focus-within::part(control) {
    border-color: rgba(0, 232, 218, 0.60);
    box-shadow: var(--stretch-focus-ring);
}

fluent-text-field[aria-invalid="true"]::part(root),
fluent-text-area[aria-invalid="true"]::part(root),
fluent-number-field[aria-invalid="true"]::part(root),
fluent-select[aria-invalid="true"]::part(control),
fluent-combobox[aria-invalid="true"]::part(control) {
    border-color: var(--stretch-danger);
    box-shadow: 0 0 0 3px rgba(var(--stretch-danger-rgb), 0.20);
}

/* ──────────────────────────────────────────────
   FluentCheckbox / FluentSwitch / FluentRadio
   ────────────────────────────────────────────── */
fluent-checkbox[checked]::part(control) {
    background: var(--stretch-primary);
    border-color: var(--stretch-primary);
}

fluent-switch:checked::part(switch) {
    background: var(--stretch-primary);
}

fluent-radio[checked]::part(control) {
    border-color: var(--stretch-primary);
}

fluent-radio[checked]::part(checked-indicator) {
    background: var(--stretch-primary);
}

/* ──────────────────────────────────────────────
   FluentTabs overrides
   ────────────────────────────────────────────── */
fluent-tabs::part(activeIndicator),
fluent-tab[aria-selected="true"]::part(content) {
    color: var(--stretch-primary);
}

fluent-tab[aria-selected="true"] {
    border-bottom-color: var(--stretch-primary) !important;
}

fluent-tab::part(content) {
    font-family: var(--stretch-font-body);
}

/* ──────────────────────────────────────────────
   FluentDialog overrides
   ────────────────────────────────────────────── */
fluent-dialog::part(control) {
    border-radius: var(--stretch-radius-lg);
    background: var(--stretch-surface);
    border: 1px solid var(--stretch-border);
    box-shadow: var(--stretch-shadow-2);
}

/* ──────────────────────────────────────────────
   FluentTooltip
   ────────────────────────────────────────────── */
fluent-tooltip::part(tooltip) {
    border-radius: var(--stretch-radius-sm);
    font-family: var(--stretch-font-body);
}

/* ──────────────────────────────────────────────
   FluentSlider
   ────────────────────────────────────────────── */
fluent-slider::part(track-start) {
    background: var(--stretch-primary);
}

fluent-slider::part(thumb-container) {
    background: var(--stretch-primary);
}

/* ──────────────────────────────────────────────
   FluentProgressRing / FluentProgress
   ────────────────────────────────────────────── */
fluent-progress-ring::part(indeterminate-indicator-1) {
    stroke: var(--stretch-primary);
}

fluent-progress::part(progress) {
    background: var(--stretch-primary);
}

fluent-progress::part(determinate) {
    background: var(--stretch-primary);
}

/* ──────────────────────────────────────────────
   FluentBadge
   ────────────────────────────────────────────── */
fluent-badge {
    border-radius: var(--stretch-radius-pill);
    font-family: var(--stretch-font-body);
}

/* ──────────────────────────────────────────────
   FluentAnchor overrides
   ────────────────────────────────────────────── */
fluent-anchor[appearance="hypertext"]::part(control) {
    color: var(--stretch-primary);
}

fluent-anchor[appearance="hypertext"]:hover::part(control) {
    color: #00d4c7;
}

/* ──────────────────────────────────────────────
   FluentNavMenu overrides
   ────────────────────────────────────────────── */
.fluent-nav-menu,
fluent-tree-item {
    font-family: var(--stretch-font-body);
}

fluent-tree-item[selected]::part(positioning-region),
fluent-tree-item[aria-selected="true"]::part(positioning-region) {
    background: var(--stretch-active-bg);
    box-shadow: 0 0 0 1px var(--stretch-active-border) inset;
}

fluent-tree-item:hover::part(positioning-region) {
    background: var(--stretch-hover-bg);
}

/* ──────────────────────────────────────────────
   FluentDataGrid overrides
   ────────────────────────────────────────────── */
.fluent-data-grid {
    font-family: var(--stretch-font-body);
}

/* ──────────────────────────────────────────────
   Utility classes
   ────────────────────────────────────────────── */

/* Surface containers */
.stretch-surface {
    border-radius: var(--stretch-radius-md);
    background: var(--stretch-surface-translucent);
    box-shadow: var(--stretch-shadow-1);
    border: 1px solid var(--stretch-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.stretch-surface--solid {
    border-radius: var(--stretch-radius-md);
    background: var(--stretch-surface);
    box-shadow: var(--stretch-shadow-1);
    border: 1px solid var(--stretch-border);
}

.stretch-surface--secondary {
    background: var(--stretch-secondary);
    color: #fff;
    border-radius: var(--stretch-radius-md);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

/* Grid texture overlay */
.stretch-grid-overlay {
    position: relative;
}

.stretch-grid-overlay::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.15;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.10) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.10) 1px, transparent 1px);
    background-size: 32px 32px;
    border-radius: inherit;
}

/* Glow blobs */
.stretch-glow {
    position: absolute;
    width: 540px;
    height: 540px;
    border-radius: 999px;
    filter: blur(90px);
    opacity: 0.55;
    background: var(--stretch-primary);
    pointer-events: none;
}

.stretch-glow--secondary {
    background: var(--stretch-secondary);
}

/* Danger / validation text */
.stretch-danger {
    color: var(--stretch-danger);
}

.stretch-warning {
    color: var(--stretch-warning);
}

.stretch-success {
    color: var(--stretch-success);
}
