/* SEE optical finish: decoration only, on explicitly qualified elements.
   Existing palettes, geometry, hit targets and semantic states remain owned
   by their component styles. No transformed containers or clipping layers. */
html[data-ui-finish] {
  --finish-glass: #ffffffa8;
  --finish-edge: #ffffffdb;
  --finish-wash: #ffffff38;
  --finish-shadow: #07131d24;
  --finish-shadow-hover: #07131d38;
  --finish-inner-shadow: #00000008;
  --finish-ease: cubic-bezier(.2, .7, .25, 1);
}
html.dark[data-ui-finish] {
  --finish-glass: #ffffff0c;
  --finish-edge: #ffffff2e;
  --finish-wash: #ffffff06;
  --finish-shadow: #00000059;
  --finish-shadow-hover: #00000080;
  --finish-inner-shadow: #00000029;
}

html[data-ui-finish] :is(.finish-surface, .finish-control, .finish-nav, .finish-popover, .finish-field) {
  --finish-accent: var(--accent, var(--skin-focus, var(--safety-accent, var(--chat-accent, currentColor))));
  --finish-line: var(--border, var(--chat-line, currentColor));
  --finish-x: 50%;
  --finish-y: 0%;
  --finish-light: transparent;
  --finish-base-image: none;
}

/* Optical depth: two static glass planes and a fine illuminated rim.
   The pointer updates only a soft local reflection, never the content.
   !important is limited to this qualified image because module cards have
   an existing background shorthand marked important. Base colour is intact. */
html[data-ui-finish] .finish-surface {
  background-image:
    radial-gradient(ellipse 390px 245px at var(--finish-x) var(--finish-y), var(--finish-light), transparent 76%),
    linear-gradient(118deg, var(--finish-glass), transparent 38%, transparent 70%, var(--finish-wash)),
    linear-gradient(180deg, var(--finish-wash), transparent 24%),
    var(--finish-base-image) !important;
  box-shadow:
    inset 0 1px 0 var(--finish-edge),
    inset 0 -1px 0 var(--finish-inner-shadow),
    0 2px 4px -2px var(--finish-shadow),
    0 17px 38px -25px var(--finish-shadow);
  transition: box-shadow 280ms var(--finish-ease), border-color 240ms var(--finish-ease);
}
html[data-ui-finish] .finish-surface:is([data-finish-hover="true"], :focus-within) {
  --finish-light: color-mix(in srgb, var(--finish-accent) 11%, transparent);
  border-color: color-mix(in srgb, var(--finish-accent) 31%, var(--finish-line));
  box-shadow:
    inset 0 1px 0 var(--finish-edge),
    inset 0 -1px 0 var(--finish-inner-shadow),
    0 0 0 1px color-mix(in srgb, var(--finish-accent) 6%, transparent),
    0 5px 12px -8px var(--finish-shadow),
    0 24px 48px -29px var(--finish-shadow-hover);
}
html.dark[data-ui-finish] .finish-surface:is([data-finish-hover="true"], :focus-within) {
  --finish-light: color-mix(in srgb, var(--finish-accent) 10%, transparent);
}

/* Control reflections keep primary gradients, danger colours and dimensions
   in their original components. Only safe, enabled controls are qualified. */
html[data-ui-finish] .finish-control:not(:disabled):not([aria-disabled="true"]) {
  background-image:
    linear-gradient(180deg, var(--finish-wash), transparent 76%),
    var(--finish-base-image);
  transition: box-shadow 180ms var(--finish-ease), border-color 180ms var(--finish-ease), background-color 180ms var(--finish-ease), color 180ms var(--finish-ease);
}
html[data-ui-finish] .finish-control:is(.primary, .primary-control, .jaica-button):not(:disabled):not([aria-disabled="true"]) {
  /* White text needs the original uninterrupted colour field. Reflection
     stays on the edge rather than passing through the label. */
  --finish-wash: transparent;
  box-shadow: inset 0 1px 0 #ffffff3b, inset 0 -1px 0 #00000016, 0 5px 15px -10px var(--finish-shadow-hover);
}
html[data-ui-finish] .guest-header-controls .finish-control {
  --finish-wash: transparent;
}
html[data-ui-finish] .finish-control:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]) {
  box-shadow:
    inset 0 1px 0 var(--finish-edge),
    inset 0 -1px 0 var(--finish-inner-shadow),
    0 3px 9px -5px var(--finish-shadow),
    0 0 0 3px color-mix(in srgb, var(--finish-accent) 10%, transparent);
}
html[data-ui-finish] .finish-control:active:not(:disabled):not([aria-disabled="true"]) {
  box-shadow: inset 0 2px 7px #00000024, inset 0 0 0 1px #ffffff12;
}

/* A glass stroke follows the navigation; labels and icons never shift. */
html[data-ui-finish] .finish-nav {
  transition: box-shadow 220ms var(--finish-ease), background-color 180ms var(--finish-ease), border-color 180ms var(--finish-ease), color 180ms var(--finish-ease);
}
html[data-ui-finish] .finish-nav:is(.selected, .active, [aria-current="page"]) {
  box-shadow: inset 0 1px 0 #ffffff40, inset 0 -1px 0 #00000012, 0 5px 15px -12px var(--finish-shadow-hover);
}
html[data-ui-finish] .finish-nav:is(:hover, :focus-visible) {
  box-shadow:
    inset 0 1px 0 #ffffff29,
    inset 0 -1px 0 #0000000c,
    inset 3px 0 0 color-mix(in srgb, var(--finish-accent) 64%, transparent),
    0 4px 16px -12px var(--finish-shadow-hover);
}
html[data-ui-finish] .sidebar .finish-nav {
  --finish-accent: var(--blue);
}

/* Readable floating glass. Existing dialog/menu sizing, positioning, backdrop
   and focus management remain untouched; no extra stacking context is added. */
html[data-ui-finish] .finish-popover {
  background-image:
    radial-gradient(ellipse at 0 0, color-mix(in srgb, var(--finish-accent) 6%, transparent), transparent 63%),
    linear-gradient(125deg, var(--finish-glass), transparent 42%),
    var(--finish-base-image);
  box-shadow:
    inset 0 1px 0 var(--finish-edge),
    inset 0 -1px 0 var(--finish-inner-shadow),
    0 0 0 1px color-mix(in srgb, var(--finish-accent) 9%, transparent),
    0 12px 22px -15px var(--finish-shadow-hover),
    0 32px 75px -31px var(--finish-shadow-hover);
}

/* Native top-layer transitions are progressive enhancement. Closing still
   happens immediately in the application: the browser retains only the last
   painted frame while opacity fades, with no delayed handlers or navigation.
   Unsupported browsers retain the existing instant close behaviour. */
@supports (transition-behavior: allow-discrete) and (overlay: auto) {
  html[data-ui-finish] :is(dialog, [popover]):is(.finish-popover, .finish-dialog-transition) {
    opacity: 0;
    animation: none;
    transition:
      opacity 190ms var(--finish-ease),
      display 190ms allow-discrete,
      overlay 190ms allow-discrete;
  }
  html[data-ui-finish] :is(dialog[open], [popover]:popover-open):is(.finish-popover, .finish-dialog-transition) {
    opacity: 1;
  }
  html[data-ui-finish] :is(dialog, [popover]):is(.finish-popover, .finish-dialog-transition)::backdrop {
    opacity: 0;
    transition:
      opacity 190ms var(--finish-ease),
      display 190ms allow-discrete,
      overlay 190ms allow-discrete;
  }
  html[data-ui-finish] :is(dialog[open], [popover]:popover-open):is(.finish-popover, .finish-dialog-transition)::backdrop {
    opacity: 1;
  }
  html[data-ui-finish] :is(dialog:not([open]), [popover]:not(:popover-open)):is(.finish-popover, .finish-dialog-transition),
  html[data-ui-finish] :is(dialog:not([open]), [popover]:not(:popover-open)):is(.finish-popover, .finish-dialog-transition)::backdrop {
    pointer-events: none;
  }
  @starting-style {
    html[data-ui-finish] :is(dialog[open], [popover]:popover-open):is(.finish-popover, .finish-dialog-transition),
    html[data-ui-finish] :is(dialog[open], [popover]:popover-open):is(.finish-popover, .finish-dialog-transition)::backdrop {
      opacity: 0;
    }
  }
}

/* Focus is immediate and semantic validation retains the last word. */
html[data-ui-finish] .finish-field {
  transition: border-color 180ms var(--finish-ease), box-shadow 220ms var(--finish-ease), background-color 180ms var(--finish-ease);
}
html[data-ui-finish] .finish-field:focus:not([aria-invalid="true"]):not(:disabled) {
  border-color: var(--skin-focus, var(--safety-accent, var(--chat-accent)));
  box-shadow:
    inset 0 1px 2px #0000000a,
    inset 0 -1px 0 var(--finish-edge),
    0 0 0 3px color-mix(in srgb, var(--finish-accent) 13%, transparent),
    0 5px 18px -12px color-mix(in srgb, var(--finish-accent) 40%, transparent);
}

/* Table rhythm is a light line, not a moving row or a replacement status fill. */
html[data-ui-finish] .finish-surface :where(tbody tr > td) {
  transition: box-shadow 150ms ease;
}
html[data-ui-finish] .finish-surface :where(tbody tr:hover > td) {
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--finish-accent) 10%, transparent), inset 0 -1px 0 color-mix(in srgb, var(--finish-accent) 10%, transparent);
}

/* Page and module navigation is immediate: no cross-document transitions. */

@media (hover: none), (pointer: coarse) {
  html[data-ui-finish] .finish-surface[data-finish-hover="true"] {
    --finish-light: transparent;
  }
}
@media (prefers-reduced-motion: reduce) {
  html[data-ui-finish] :is(.finish-surface, .finish-control, .finish-nav, .finish-popover, .finish-field),
  html[data-ui-finish] .finish-surface :where(tbody tr > td) {
    transition: none !important;
    animation: none !important;
  }
  html[data-ui-finish] .finish-surface { --finish-light: transparent !important; }
}
html[data-ui-finish][data-ui-paused="true"] :is(.finish-surface, .finish-control, .finish-nav, .finish-popover, .finish-field),
html[data-ui-finish][data-ui-paused="true"] .finish-surface :where(tbody tr > td) {
  transition: none !important;
  animation: none !important;
}
@media (prefers-reduced-motion: reduce), (forced-colors: active), print {
  html[data-ui-finish] :is(dialog, [popover]).finish-dialog-transition,
  html[data-ui-finish] :is(dialog, [popover]):is(.finish-popover, .finish-dialog-transition)::backdrop {
    transition: none !important;
    animation: none !important;
  }
}
html[data-ui-finish][data-ui-paused="true"] :is(dialog, [popover]).finish-dialog-transition,
html[data-ui-finish][data-ui-paused="true"] :is(dialog, [popover]):is(.finish-popover, .finish-dialog-transition)::backdrop {
  transition: none !important;
  animation: none !important;
}
@media (forced-colors: active), print {
  html[data-ui-finish] :is(.finish-surface, .finish-control, .finish-nav, .finish-popover, .finish-field),
  html[data-ui-finish] .finish-surface :where(tbody tr > td) {
    background-image: none !important;
    box-shadow: none !important;
    transition: none !important;
    animation: none !important;
  }
}
