/* Common styles for all sub-projects */

/* === MD3 Indigo Tonal Palette — Dark Scheme (default) === */
:root {
    --bg-color: #f9fafb;
    --text-color: #1f1f1f;
    --card-bg: #ffffff;
    --border-color: #dadce0;

    /* MD3 Color Tokens */
    --md-primary: #BEC2FF;
    --md-on-primary: #262479;
    --md-primary-container: #3D3F90;
    --md-on-primary-container: #E0E0FF;
    --md-secondary: #C5C4DD;
    --md-on-secondary: #2E2D42;
    --md-secondary-container: #44435A;
    --md-on-secondary-container: #E1E0F9;
    --md-surface-dim: #141218;
    --md-surface: #141218;
    --md-surface-container-lowest: #0F0D13;
    --md-surface-container-low: #1D1B20;
    --md-surface-container: #211F26;
    --md-surface-container-high: #2B2930;
    --md-surface-container-highest: #36343B;
    --md-on-surface: #E6E1E5;
    --md-on-surface-variant: #CAC4D0;
    --md-outline: #938F99;
    --md-outline-variant: #49454F;

    /* MD3 Motion */
    --md-easing-standard: cubic-bezier(0.2, 0, 0, 1.0);
    --md-easing-enter: cubic-bezier(0.05, 0.7, 0.1, 1.0);
    --md-easing-exit: cubic-bezier(0.3, 0, 0.8, 0.15);
    --md-easing-emphasized: cubic-bezier(0.2, 0, 0, 1.0); /* alias of standard, for intent clarity */
    --md-duration-xs: 100ms;
    --md-duration-s: 150ms;
    --md-duration-ms: 200ms; /* intermediate — the most common real-world value */
    --md-duration-m: 300ms;
    --md-duration-l: 500ms;
    --md-stagger: 40ms;      /* per-item stagger step for reveals */

    /* Unified focus ring (see :focus-visible block below) */
    --md-focus-ring-width: 2px;
    --md-focus-ring-color: var(--md-primary);
    --md-focus-ring-danger: #ef4444; /* red-500 — destructive / admin inputs */

    /* MD3 Shape */
    --md-shape-xs: 4px;
    --md-shape-sm: 8px;
    --md-shape-md: 12px;
    --md-shape-lg: 16px;
    --md-shape-xl: 28px;
    --md-shape-full: 9999px;

    /* MD3 Spacing Scale (4px baseline grid) */
    --md-space-0: 0;
    --md-space-1: 4px;
    --md-space-2: 8px;
    --md-space-3: 12px;
    --md-space-4: 16px;
    --md-space-5: 20px;
    --md-space-6: 24px;
    --md-space-8: 32px;
    --md-space-10: 40px;
    --md-space-12: 48px;
    --md-space-16: 64px;
    --md-space-20: 80px;

    /* MD3 Content Width */
    --md-content-max: 1280px;
    --md-content-narrow: 640px;
    --md-content-medium: 1024px;

    /* MD3 Extended Color Roles — Dark Scheme (default, matches tokens above) */
    --md-tertiary: #EFB8C8;
    --md-on-tertiary: #492532;
    --md-tertiary-container: #633B48;
    --md-on-tertiary-container: #FFD8E4;
    --md-error: #F2B8B5;
    --md-on-error: #601410;
    --md-error-container: #8C1D18;
    --md-on-error-container: #F9DEDC;
    --md-surface-variant: #49454F;
    --md-inverse-surface: #E6E1E5;
    --md-inverse-on-surface: #313033;
    --md-inverse-primary: #5657AC;
    --md-scrim: rgba(0, 0, 0, 0.5);
    --md-shadow: #000000;

    /* Semantic extensions (not core MD3, shared success/warning states) */
    --md-success: #8BD99F;
    --md-on-success: #00391A;
    --md-success-container: #0F5223;
    --md-on-success-container: #A7F5B7;
    --md-warning: #F2C14B;
    --md-on-warning: #402D00;
    --md-warning-container: #5E4200;
    --md-on-warning-container: #FFDF9E;

    /* MD3 Elevation (dark-friendly umbra+penumbra pairs) */
    --md-elevation-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
    --md-elevation-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
    --md-elevation-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
}
/* === Motion Utilities (shared) === */
.fade-in {
    animation: md-fade-in var(--md-duration-m) var(--md-easing-enter) both;
}

.stagger-item {
    animation: md-fade-in var(--md-duration-m) var(--md-easing-enter) both;
    animation-delay: var(--stagger-delay, 0s);
}

.skeleton-shimmer {
    background: linear-gradient(
        90deg,
        var(--md-surface-container-high) 0%,
        var(--md-surface-container-highest) 50%,
        var(--md-surface-container-high) 100%
    );
    background-size: 200% 100%;
    animation: md-shimmer 1.4s linear infinite;
}

.content-visibility-auto {
    content-visibility: auto;
    contain-intrinsic-size: auto 88px;
}

/* Pressable list rows / cards — CSS-only feedback; keep focus rings intact */
.pressable {
    touch-action: manipulation;
    transition: transform var(--md-duration-xs) var(--md-easing-standard),
                opacity var(--md-duration-s) var(--md-easing-standard);
}
.pressable:active {
    transform: scale(0.98);
}
.pressable:focus-visible {
    outline: var(--md-focus-ring-width) solid var(--md-focus-ring-color);
    outline-offset: 2px;
}

/* List rows that opt into staggered enter + content-visibility */
.list-row-enter {
    transition: opacity var(--md-duration-m) var(--md-easing-enter),
                transform var(--md-duration-m) var(--md-easing-enter);
}

.img-fade-in {
    opacity: 0;
    transition: opacity var(--md-duration-m) var(--md-easing-standard);
}

.img-fade-in.loaded {
    opacity: 1;
}

@keyframes md-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes md-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* === Motion System (shared, MD3) ====================================
   Canonical keyframes + utility classes. Per-app CSS should reference these
   instead of redefining local spin / pulse / fade / slide variants. All keyframes
   are `md-` prefixed to avoid clashing with Tailwind's own spin/pulse keyframes. */
.fade-in-up     { animation: md-fade-in-up    var(--md-duration-m) var(--md-easing-enter) both; }
.fade-in-down   { animation: md-fade-in-down  var(--md-duration-m) var(--md-easing-enter) both; }
.scale-in       { animation: md-scale-in      var(--md-duration-m) var(--md-easing-enter) both; }
.slide-in-up    { animation: md-slide-in-up   var(--md-duration-m) var(--md-easing-enter) both; }
.slide-in-down  { animation: md-slide-in-down var(--md-duration-m) var(--md-easing-enter) both; }
.slide-in-right { animation: md-slide-in-right var(--md-duration-m) var(--md-easing-enter) both; }
.slide-in-left  { animation: md-slide-in-left  var(--md-duration-m) var(--md-easing-enter) both; }
.animate-pulse-md { animation: md-pulse var(--md-duration-l) var(--md-easing-standard) infinite; }

/* Canonical circular spinner — replaces ad-hoc spin-once / tx-spin / slides spin.
   Inherits currentColor so it tints to the surrounding text. */
.spinner {
    display: inline-block;
    width: 1.25em;
    height: 1.25em;
    border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: md-spin 0.7s linear infinite;
}

@keyframes md-spin  { to { transform: rotate(360deg); } }
@keyframes md-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes md-fade-in-up   { from { opacity: 0; transform: translateY(8px);  } to { opacity: 1; transform: none; } }
@keyframes md-fade-in-down { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes md-scale-in     { from { opacity: 0; transform: scale(0.96);      } to { opacity: 1; transform: none; } }
@keyframes md-slide-in-up    { from { transform: translateY(100%);  } to { transform: none; } }
@keyframes md-slide-in-down  { from { transform: translateY(-100%); } to { transform: none; } }
@keyframes md-slide-in-right { from { opacity: 0; transform: translateX(24px);  } to { opacity: 1; transform: none; } }
@keyframes md-slide-in-left  { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }

/* Global reduced-motion kill-switch. Replaces the old per-class opt-in (which
   left every per-app keyframe still animating). Near-instant instead of hard
   `none` so JS that waits on transition/animation end events still fires. */
@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;
    }

    .skeleton-shimmer {
        background: var(--md-surface-container-high);
    }

    .img-fade-in {
        opacity: 1;
    }
}

/* MD3 Light Scheme Override */
html:not(.dark):not(.dark-mode) {
    --md-primary: #5657AC;
    --md-on-primary: #FFFFFF;
    --md-primary-container: #E0E0FF;
    --md-on-primary-container: #09006E;
    --md-secondary: #5B5D72;
    --md-on-secondary: #FFFFFF;
    --md-secondary-container: #E1E0F9;
    --md-on-secondary-container: #181A2C;
    --md-surface-dim: #FEF7FF;
    --md-surface: #FEF7FF;
    --md-surface-container-lowest: #FFFFFF;
    --md-surface-container-low: #F3EDF7;
    --md-surface-container: #EDE7F1;
    --md-surface-container-high: #E7E2EB;
    --md-surface-container-highest: #E1DBE6;
    --md-on-surface: #1C1B1F;
    --md-on-surface-variant: #49454F;
    --md-outline: #79747E;
    --md-outline-variant: #CAC4D0;

    /* MD3 Extended Color Roles — Light Scheme */
    --md-tertiary: #7D5260;
    --md-on-tertiary: #FFFFFF;
    --md-tertiary-container: #FFD8E4;
    --md-on-tertiary-container: #31111D;
    --md-error: #B3261E;
    --md-on-error: #FFFFFF;
    --md-error-container: #F9DEDC;
    --md-on-error-container: #410E0B;
    --md-surface-variant: #E7E0EC;
    --md-inverse-surface: #313033;
    --md-inverse-on-surface: #F4EFF4;
    --md-inverse-primary: #BEC2FF;
    --md-scrim: rgba(0, 0, 0, 0.4);
    --md-shadow: #000000;

    --md-success: #1E7A3C;
    --md-on-success: #FFFFFF;
    --md-success-container: #B7F2C3;
    --md-on-success-container: #00210B;
    --md-warning: #7A5900;
    --md-on-warning: #FFFFFF;
    --md-warning-container: #FFDF9E;
    --md-on-warning-container: #261A00;

    --md-elevation-1: 0 1px 2px rgba(0,0,0,.12), 0 1px 3px 1px rgba(0,0,0,.06);
    --md-elevation-2: 0 1px 2px rgba(0,0,0,.12), 0 2px 6px 2px rgba(0,0,0,.08);
    --md-elevation-3: 0 4px 8px 3px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.14);
}

html.dark,
body.dark-mode {
    --bg-color: #131314;
    --text-color: #e3e3e3;
    --card-bg: #1e1f20;
    --border-color: #3c4043;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.card {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Custom Scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.4) transparent;
    scroll-behavior: smooth;
}

.dark * {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.4);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.6);
    border: 2px solid transparent;
    background-clip: content-box;
}

.dark ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid transparent;
    background-clip: content-box;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid transparent;
    background-clip: content-box;
}

/* Material Symbols */
.material-symbols-outlined {
    font-size: 1.5rem;
    vertical-align: middle;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.material-symbols-outlined.hidden {
    display: none;
}

.settings-label {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: #374151 !important;
    margin-bottom: 4px;
    margin-left: 6px;
    letter-spacing: 0.1px;
}

.dark .settings-label {
    color: #d2d5da !important;
}

.grecaptcha-badge {
    display: none !important;
}

/* === Unified focus ring (WCAG 2.4.7) — ONE stroke, never a double border ===
   The old "double border" had two causes, both fixed here:
     1. this global outline stacked on top of each element's own Tailwind
        `focus:ring-*` box-shadow, and
     2. some inputs ALSO flipped their border colour via `focus:border-*`.
   Fix: (a) the outline below is the single canonical ring and follows each
   element's own border-radius automatically (no hardcoded radius that used to
   clash with pill / rounded-xl shapes); (b) the `*:focus` rule zeroes Tailwind's
   ring box-shadow at its source so it can't render a second stroke. The handful
   of `focus:border-*` colour flips are removed at their callsites. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
[data-custom-select]:focus-visible {
    outline: var(--md-focus-ring-width) solid var(--md-focus-ring-color) !important;
    outline-offset: 0;
}

/* Neutralise Tailwind's per-element focus ring so it can't stack with the
   canonical outline above. Setting the ring CSS vars to transparent makes the
   utility's own `box-shadow` composite render nothing on focus. */
*:focus {
    --tw-ring-shadow: 0 0 #0000 !important;
    --tw-ring-offset-shadow: 0 0 #0000 !important;
}

/* Destructive / admin "View As" inputs: single RED ring (no border flip). */
.focus-ring-danger:focus-visible {
    outline-color: var(--md-focus-ring-danger) !important;
}

/* Opt-out for inner controls whose wrapper already shows a focus-within ring
   (e.g. the price field group) — prevents a ring on both wrapper and child. */
.focus-ring-none:focus-visible {
    outline: none !important;
}

/* === MD3 Type Scale (utility classes, opt-in) ===========================
   Font stack inherits from body (Inter). Sizes per m3.material.io type scale. */
.md-display-large  { font-size: 57px; line-height: 64px; font-weight: 400; letter-spacing: -0.25px; }
.md-display-medium { font-size: 45px; line-height: 52px; font-weight: 400; }
.md-display-small  { font-size: 36px; line-height: 44px; font-weight: 400; }
.md-headline-large  { font-size: 32px; line-height: 40px; font-weight: 600; letter-spacing: -0.02em; }
.md-headline-medium { font-size: 28px; line-height: 36px; font-weight: 600; }
.md-headline-small  { font-size: 24px; line-height: 32px; font-weight: 600; }
.md-title-large  { font-size: 22px; line-height: 28px; font-weight: 500; }
.md-title-medium { font-size: 16px; line-height: 24px; font-weight: 600; letter-spacing: 0.15px; }
.md-title-small  { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: 0.1px; }
.md-body-large  { font-size: 16px; line-height: 24px; font-weight: 400; letter-spacing: 0.5px; }
.md-body-medium { font-size: 14px; line-height: 20px; font-weight: 400; letter-spacing: 0.25px; }
.md-body-small  { font-size: 12px; line-height: 16px; font-weight: 400; letter-spacing: 0.4px; }
.md-label-large  { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: 0.1px; }
.md-label-medium { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.5px; }
.md-label-small  { font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: 0.5px; }

/* Screen-reader-only text (a11y helper — visually hidden, still announced) */
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* === Responsive Layout Utilities ========================================== */
.md-content {
    max-width: var(--md-content-max);
    margin-inline: auto;
    padding-inline: var(--md-space-4);
}
@media (min-width: 768px) {
    .md-content { padding-inline: var(--md-space-6); }
}
@media (min-width: 1024px) {
    .md-content { padding-inline: var(--md-space-8); }
}

.md-content-narrow { max-width: var(--md-content-narrow); margin-inline: auto; padding-inline: var(--md-space-4); }
.md-content-medium { max-width: var(--md-content-medium); margin-inline: auto; padding-inline: var(--md-space-4); }

/* === Pressable — generic tap-target for bindPressFeedback() ============== */
.pressable {
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
@media (prefers-reduced-motion: no-preference) {
    .pressable:active {
        transform: scale(0.96);
        transition: transform var(--md-duration-xs) var(--md-easing-exit);
    }
}

/* === content-visibility helper (applied by dom-batch.js) ================= */
.content-visibility-auto {
    content-visibility: auto;
    contain-intrinsic-size: auto 64px;
}

/* === Skip-to-content link (a11y) ========================================= */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    z-index: 9999;
    padding: var(--md-space-2) var(--md-space-4);
    background: var(--md-primary);
    color: var(--md-on-primary);
    border-radius: 0 0 var(--md-shape-md) 0;
    font-weight: 600;
    font-size: 14px;
    transition: top var(--md-duration-s) var(--md-easing-standard);
}
.skip-link:focus { top: 0; }

/* === Mermaid diagram full-screen preview ================================= */
/* Wired by js/shared/diagram-preview.js. A diagram is unreadable at chat-bubble
   or side-panel width, so a click opens the rendered SVG over the whole
   viewport with zoom + pan. Every colour carries a literal fallback — studio
   loads shared.css without md3.css, so the --md-* vars may be undefined. */
.diagram-host { position: relative; cursor: zoom-in; }
.diagram-expand {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.12));
    border-radius: 8px;
    background: var(--md-surface, #ffffff);
    color: var(--md-on-surface-variant, #6b7280);
    cursor: zoom-in;
    opacity: 0;
    transition: opacity 120ms ease, color 120ms ease;
}
.diagram-expand .material-symbols-outlined { font-size: 18px; }
.diagram-host:hover .diagram-expand,
.diagram-expand:focus-visible { opacity: 1; }
/* Touch has no hover — keep the affordance visible there. */
@media (hover: none) { .diagram-expand { opacity: 1; } }
.dark .diagram-expand {
    background: var(--md-surface-container, #211f26);
    border-color: var(--md-outline-variant, #49454f);
    color: #c4c7c5;
}
.diagram-preview {
    position: fixed;
    inset: 0;
    z-index: 2000;   /* above the shared modal scrim (1000), below toasts (9999) */
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: diagram-preview-fade 140ms ease both;
}
.diagram-preview.hidden { display: none !important; }
@keyframes diagram-preview-fade { from { opacity: 0; } to { opacity: 1; } }
.diagram-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex: 0 0 auto;
    padding: 0.5rem 0.75rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    background: var(--md-surface, #ffffff);
    border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, 0.12));
}
.dark .diagram-preview-bar {
    background: var(--md-surface-container, #211f26);
    border-color: var(--md-outline-variant, #49454f);
}
.diagram-preview-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--md-on-surface, #111827);
}
.dark .diagram-preview-title { color: var(--md-on-surface, #e3e3e3); }
.diagram-preview-actions { display: flex; align-items: center; gap: 0.15rem; }
.diagram-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 0.35rem;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--md-on-surface-variant, #6b7280);
    font-family: inherit;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}
.diagram-btn:hover {
    background: var(--md-surface-container-low, #f3f4f6);
    color: var(--md-on-surface, #111827);
}
.dark .diagram-btn:hover { background: rgba(255, 255, 255, 0.1); color: #e3e3e3; }
.diagram-btn .material-symbols-outlined { font-size: 20px; }
.diagram-zoom {
    min-width: 3.4rem;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.diagram-preview-stage {
    flex: 1 1 auto;
    display: flex;
    overflow: auto;
    padding: 1.25rem;
    overscroll-behavior: contain;
}
.diagram-preview-stage.is-panning { cursor: grabbing; }
/* min-width/height centre the sheet; margin:auto (not flex centring) so an
   oversized diagram still scrolls to its left/top edge. */
.diagram-preview-canvas { display: flex; min-width: 100%; min-height: 100%; }
.diagram-sheet {
    margin: auto;
    padding: 1rem;
    border-radius: 14px;
    background: var(--md-surface, #ffffff);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.dark .diagram-sheet { background: var(--md-surface-container-low, #1b1b1f); }
.diagram-sheet svg { display: block; }
body.diagram-preview-open { overflow: hidden; }

/* === File preview (fullscreen media / document viewer) ==================
   Wired by js/shared/file-preview.js. Self-injects overlay — no page markup. */
.file-preview {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: file-preview-fade 140ms ease both;
}
.file-preview.hidden { display: none !important; }
@keyframes file-preview-fade { from { opacity: 0; } to { opacity: 1; } }
.file-preview-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 64rem;
    max-height: 100%;
    min-height: 0;
}
.file-preview.is-wide .file-preview-shell { max-width: 95vw; }
.file-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-shrink: 0;
    margin-bottom: 0.75rem;
    color: #fff;
}
.file-preview-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.file-preview-bar-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}
.file-preview-actions { display: flex; align-items: center; gap: 0.15rem; }
.file-preview-download-wrap { position: relative; }
.file-preview-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(255, 255, 255, 0.88);
    cursor: pointer;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease, opacity 120ms ease;
}
.file-preview-btn:hover,
.file-preview-btn:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    outline: none;
}
.file-preview-btn.is-busy,
.file-preview-btn:disabled {
    opacity: 0.55;
    pointer-events: none;
}
.file-preview-btn.hidden { display: none !important; }
.file-preview-btn .material-symbols-outlined { font-size: 24px; }
.file-preview-spin { animation: file-preview-spin 0.8s linear infinite; }
@keyframes file-preview-spin { to { transform: rotate(360deg); } }
.file-preview-format-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.25rem);
    min-width: 12.5rem;
    padding: 0.25rem 0;
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: #1e1e1e;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    z-index: 5;
}
.file-preview-format-menu.hidden { display: none !important; }
.file-preview-format-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.65rem 1rem;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}
.file-preview-format-item:hover,
.file-preview-format-item:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}
.file-preview-format-item .material-symbols-outlined { font-size: 18px; opacity: 0.85; }
.file-preview-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.28);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
}
.file-preview-stage.is-flush {
    display: block;
    overflow: hidden;
    padding: 0;
}
.file-preview-media {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 0.5rem;
}
.file-preview-frame {
    width: 100%;
    height: 100%;
    min-height: min(80vh, 720px);
    border: 0;
    border-radius: 0.75rem;
    background: #fff;
}
.file-preview-frame--video { background: #000; aspect-ratio: 16 / 9; min-height: auto; max-height: 80vh; }
.file-preview-pdf { width: 100%; height: 100%; min-height: min(80vh, 720px); background: #fff; border-radius: 0.75rem; }
.file-preview-text {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 1.25rem 1.5rem;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.55;
    color: #d4d4d8;
    background: #141416;
    white-space: pre-wrap;
    word-break: break-word;
}
.file-preview-audio {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    color: #fff;
}
.file-preview-audio audio { width: min(28rem, 90vw); }
.file-preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    padding: 3rem 1.5rem;
    color: rgba(255, 255, 255, 0.72);
}
.file-preview-empty-icon { font-size: 4.5rem !important; opacity: 0.35; }
.file-preview-empty-msg { margin: 0; font-size: 1.1rem; font-weight: 500; color: rgba(255, 255, 255, 0.88); }
.file-preview-empty-detail { margin: 0; font-size: 0.85rem; opacity: 0.7; }
.file-preview-cta {
    margin-top: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.7rem 1.4rem;
    border: 0;
    border-radius: 0.75rem;
    background: #E8623D;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.file-preview-cta:hover { filter: brightness(1.08); }
.file-preview-spinner {
    width: 3rem;
    height: 3rem;
    border: 4px solid rgba(232, 98, 61, 0.25);
    border-top-color: #E8623D;
    border-radius: 999px;
    animation: file-preview-spin 0.8s linear infinite;
}
.file-preview-footer {
    flex-shrink: 0;
    margin-top: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(20, 20, 22, 0.92);
}
.file-preview-footer.hidden { display: none !important; }
.file-preview-footer .file-preview-footer-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
}
.file-preview-footer a,
.file-preview-footer button.file-preview-footer-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: 0.7rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}
.file-preview-footer a:hover,
.file-preview-footer button.file-preview-footer-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}
.file-preview-footer a.is-primary,
.file-preview-footer button.file-preview-footer-btn.is-primary {
    background: #E8623D;
    border-color: transparent;
}
body.file-preview-open { overflow: hidden; }
@media (max-width: 640px) {
    .file-preview { padding: 0.65rem; }
    .file-preview-title { font-size: 0.95rem; }
    .file-preview-frame { min-height: min(70vh, 520px); }
}

/* === Theme transition (smooth scheme switching) ========================= */
html.theme-transition,
html.theme-transition * {
    transition: background-color var(--md-duration-s) var(--md-easing-standard),
                border-color var(--md-duration-s) var(--md-easing-standard),
                color var(--md-duration-s) var(--md-easing-standard) !important;
}

/* === High-contrast mode support ========================================= */
@media (prefers-contrast: high) {
    :root {
        --md-outline: var(--md-on-surface);
        --md-outline-variant: var(--md-on-surface-variant);
    }
}

/* === Forced-colors mode (Windows high contrast) =========================== */
@media (forced-colors: active) {
    .md-btn,
    .md-icon-btn,
    .md-chip,
    .md-card,
    .shell-icon-btn,
    .shell-btn {
        forced-color-adjust: none;
    }
}
