/* ============================================================
   Singularidade child theme (singularidade-ui-vaadin)
   ============================================================

   This file extends the singularidade-base parent theme (provided by
   @singularidade/vaadin-bindings). The parent maps the design system tokens
   (tokens/theme.css: --color-*, --shadow-*, --radius-*, --font-*, ...) onto
   the Lumo tokens (--lumo-*) and the Vaadin 25 style properties (--vaadin-*):
   the light theme on :root, the dark one on [theme~='dark'] (the attribute
   Vaadin sets on <html>) and on [data-theme='dark'].

   Rules of this file:

   1. Every colour, shadow and radius is a design system token (DS v2) or a
      Lumo property the parent maps from one. No hex, rgb() or hsl() literal
      and no named colour: ThemeCssTest fails the build on one, and on a token
      the design system does not define or has deprecated.

   2. The --singularidade-* and --crud-* properties are this library's
      contract with the apps (integras-digital reads --singularidade-border,
      -active and -warning). They keep their names and read the tokens.

   3. Motion is a short colour or shadow transition, never transition: all,
      a movement or a blur, and none at all under prefers-reduced-motion.
   ============================================================ */

@import url('crud.css');

/* ---- Library properties, read from the tokens ----
   Declared again on every element that switches the theme, as the parent does
   with its mapping: a var() is resolved where it is declared, so a region with
   data-theme gets the values of its own theme instead of the page's. */
:root,
[data-theme],
[theme~='dark'] {
  --singularidade-nav-bg: var(--color-surface-sunken);
  --singularidade-drawer-bg: var(--color-surface-sunken);
  /* Containers (grid, drawer, header, code panel). The dark theme's subtle
     border (8% alpha) disappears, so both themes use the default one. */
  --singularidade-border: var(--color-border-default);
  /* Hover of a menu item or a grid row; the current item and the selected row. */
  --singularidade-hover: var(--color-interactive-secondary);
  --singularidade-active: var(--color-interactive-primary-subtle);
  /* Fill of a warning (the storage meter of integras-digital): 4.84:1 against
     the light base, 10.81:1 against the dark one. */
  --singularidade-warning: var(--color-feedback-warning-solid);
}

/* In the dark theme the header is the raised surface and the side navigation
   sits on the page's base: what is closer is lighter. */
[theme~='dark'],
[data-theme='dark'] {
  --singularidade-nav-bg: var(--color-surface-raised);
  --singularidade-drawer-bg: var(--color-surface-base);
}

html, body {
  background: var(--lumo-base-color);
}

/* ---- Skip link (BaseAdminLayout) ----
   The first stop of the keyboard: hidden until it has the focus, then shown at
   the start of the header. Hidden by clipping rather than by moving it away,
   so it never animates and never sits invisible over the header catching
   clicks. */
.ss-skip-link {
  position: absolute;
  inset-inline-start: var(--size-4);
  top: var(--size-2);
  z-index: var(--z-skip-link);
  padding: var(--size-2) var(--size-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-link);
  box-shadow: var(--shadow-md);
  font-weight: var(--font-weight-semibold);
  text-decoration: underline;
  white-space: nowrap;
}

.ss-skip-link:not(:focus) {
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  box-shadow: none;
}

.ss-skip-link:focus-visible {
  outline: var(--vaadin-focus-ring-width, 2px) solid var(--vaadin-focus-ring-color, var(--color-border-focus));
  outline-offset: 2px;
}

/* The content the skip link moves the focus to is a container, not a control:
   it takes the focus so that the next Tab lands inside it, without a ring
   around the whole page. */
vaadin-app-layout > :not([slot])[tabindex='-1']:focus {
  outline: none;
}

/* ---- Sidebar / Drawer ---- */

vaadin-app-layout::part(drawer) {
  background: var(--singularidade-drawer-bg);
  border-right: 1px solid var(--singularidade-border);
  /* As wide as the longest label of the current language, plus a fixed
     margin. A fixed width fits one menu in one language only: 240px, sized
     for one product's longest item, left an empty band beside a shorter menu
     and would clip a longer translation. vaadin-app-layout measures the
     drawer itself, so the page beside it follows. */
  width: max-content;
  flex: 0 0 auto;
  min-width: 0;
  padding-inline-end: var(--lumo-space-m);
}

vaadin-side-nav-item {
  border-radius: var(--radius-md);
  margin: 2px 10px;
  padding: 0 4px;
  font-weight: var(--font-weight-medium);
  font-size: var(--lumo-font-size-s);
  letter-spacing: -0.01em;
  color: var(--lumo-secondary-text-color);
}

/* Lumo paints the item's row (its content part) and already fades its colours
   in, so the row is what changes here. Vaadin 25 marks the item of the
   current route with the `current` attribute and aria-current="page". */
vaadin-side-nav-item::part(content) {
  border-radius: var(--radius-md);
}

vaadin-side-nav-item::part(content):hover {
  background-color: var(--singularidade-hover);
}

vaadin-side-nav-item[current] {
  color: var(--lumo-primary-text-color);
  font-weight: var(--font-weight-semibold);
}

/* Primary on primary-subtle: 5.01:1 in light, 5.25:1 in dark. */
vaadin-side-nav-item[current]::part(content) {
  background-color: var(--singularidade-active);
  color: var(--color-interactive-primary);
}

vaadin-side-nav-item[current]::part(content):hover {
  background-color: var(--color-interactive-primary-subtle-hover);
}

/* Icons in the label's colour at full strength (the 0.7 opacity of before
   took them under 3:1), in the primary colour on the current item. */
vaadin-side-nav-item > vaadin-icon {
  width: var(--icon-md);
  height: var(--icon-md);
  color: var(--lumo-secondary-text-color);
}

vaadin-side-nav-item[current] > vaadin-icon {
  color: var(--color-interactive-primary);
}

/* ---- Navbar ---- */

vaadin-app-layout::part(navbar) {
  background: var(--singularidade-nav-bg);
  border-bottom: 1px solid var(--singularidade-border);
  box-shadow: none;
}

/* Logo doubles as the drawer toggle — reinforce clickability. The
   cursor must be set on the toggle element itself because vaadin-button
   defaults to cursor:default in Lumo and covers the whole hit area. */
vaadin-drawer-toggle,
vaadin-drawer-toggle::part(button),
.ss-navbar-logo {
  cursor: pointer;
}

/* ---- User menu (avatar dropdown in the navbar) ----
   The avatar-menu should sit flush against the right edge of the navbar
   (GitHub/Notion/Linear pattern). Vaadin's overlay auto-flip doesn't
   reliably right-align in our navbar layout, so we pin the overlay to
   a fixed width wide enough to display a typical email address. With a
   predictable width we can also force the overlay to open leftward via
   a negative margin — the visual effect is a right-aligned dropdown. */
vaadin-menu-bar[theme~="ss-user-menu"] {
  margin-inline-end: 0;
}

vaadin-menu-bar[theme~="ss-user-menu"]::part(container) {
  padding: 0;
}

vaadin-menu-bar[theme~="ss-user-menu"] vaadin-menu-bar-button {
  padding-inline: var(--lumo-space-xs);
}

/* Vaadin propagates the `theme` attribute from the menu-bar to the
   detached overlay element. Target the overlay to pin width and to
   force right-alignment against the viewport edge. */
vaadin-menu-bar-overlay[theme~="ss-user-menu"]::part(overlay) {
  min-width: 260px;
  max-width: 320px;
}

vaadin-menu-bar-overlay[theme~="ss-user-menu"]::part(content) {
  padding: var(--lumo-space-xs) 0;
}

/* Vaadin sets `left: <computed>px` inline from its auto-positioner.
   We override with `!important` to snap the overlay to the viewport's
   right edge, roughly where the navbar's right padding ends. This is
   less precise than anchoring to the trigger but reliable across
   layout changes — the user-menu always sits flush-right in the
   navbar, so visually the overlay is right-aligned to the trigger. */
vaadin-menu-bar-overlay[theme~="ss-user-menu"] {
  left: auto !important;
  right: var(--lumo-space-m) !important;
}

/* Truncate overflowing labels (long emails) with ellipsis so the menu
   stays inside the fixed max-width. */
vaadin-menu-bar-overlay[theme~="ss-user-menu"] vaadin-menu-bar-item {
  max-width: 100%;
  overflow: hidden;
}

vaadin-menu-bar-overlay[theme~="ss-user-menu"] vaadin-menu-bar-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Grid ---- */

vaadin-grid {
  border: 1px solid var(--singularidade-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  --_lumo-grid-border-color: var(--singularidade-border);
  /* A selected row in primary-subtle (Lumo's was 10% of the primary). The
     status badges keep their contrast on it: they paint their tint over an
     opaque base (crud.css). */
  --_lumo-grid-selected-row-color: var(--singularidade-active);
}

vaadin-grid::part(header-cell) {
  font-weight: var(--font-weight-semibold);
  font-size: var(--lumo-font-size-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--lumo-secondary-text-color);
}

/* ---- Dialog ----
   Vaadin 25 renders the overlay inside the dialog's shadow root and exports
   its parts, so the overlay is reached through the dialog element (the old
   vaadin-dialog-overlay::part(overlay) selector no longer matched). */

vaadin-dialog::part(overlay),
vaadin-confirm-dialog::part(overlay) {
  box-shadow: var(--shadow-xl);
  border-radius: var(--dialog-radius);
  border: 1px solid var(--dialog-border);
}

/* ---- Buttons ---- */

/* Flat in both themes, as Lumo draws it: the drop shadow and the inner
   highlight of before are gone. No box-shadow here at all: Lumo draws the
   keyboard focus ring with box-shadow, and a rule on the button would hide it. */
vaadin-button[theme~="primary"] {
  border-radius: var(--button-radius);
  font-weight: var(--font-weight-semibold);
  letter-spacing: -0.01em;
}

vaadin-button[theme~="tertiary"] {
  font-weight: var(--font-weight-medium);
  letter-spacing: -0.01em;
}

/* Tertiary hover in primary-subtle, with the text in primary-hover (7.30:1 in
   light, 7.48:1 in dark; Lumo's 2% tint was all but invisible). Lumo paints
   the tertiary background with !important from inside the button, so the
   colour goes through the property it reads. A coloured tertiary (error,
   success, contrast) keeps its text colour and gets the matching surface. */
@media (any-hover: hover) {
  vaadin-button[theme~="tertiary"]:hover {
    --vaadin-button-tertiary-background: var(--button-tertiary-background-hover);
    --vaadin-button-tertiary-text-color: var(--color-interactive-primary-hover);
  }

  vaadin-button[theme~="tertiary"][theme~="error"]:hover {
    --vaadin-button-tertiary-background: var(--color-feedback-error-surface);
  }

  vaadin-button[theme~="tertiary"][theme~="success"]:hover {
    --vaadin-button-tertiary-background: var(--color-feedback-success-surface);
  }

  vaadin-button[theme~="tertiary"][theme~="contrast"]:hover {
    --vaadin-button-tertiary-background: var(--color-interactive-secondary);
  }
}

/* Pressed: primary-subtle-hover, with the text still in primary-hover (6.68:1
   in light, 5.88:1 in dark). The coloured tertiaries keep their hover surface. */
vaadin-button[theme~="tertiary"][active]:not([theme~="error"]):not([theme~="success"]):not([theme~="contrast"]) {
  --vaadin-button-tertiary-background: var(--color-interactive-primary-subtle-hover);
}

/* ---- Badges ----
   The design system's tones: a tinted surface painted over an opaque raised
   base, so that a badge reads the same on a selected row or on any tinted
   container. Text on each tone: 4.81:1 or more in both themes. The solid
   (primary) badges keep Lumo's fill with the on-status text the parent maps. */

span[theme~="badge"] {
  font-weight: var(--font-weight-semibold);
  font-size: var(--lumo-font-size-xs);
  letter-spacing: 0.02em;
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

span[theme~="badge"]:not([theme~="primary"]) {
  --_ss-badge-tint: var(--color-interactive-primary-subtle);
  background-color: var(--color-surface-raised);
  background-image: linear-gradient(var(--_ss-badge-tint), var(--_ss-badge-tint));
  color: var(--color-interactive-primary);
}

span[theme~="badge"][theme~="success"]:not([theme~="primary"]) {
  --_ss-badge-tint: var(--color-feedback-success-surface);
  color: var(--color-feedback-success-text);
}

span[theme~="badge"][theme~="error"]:not([theme~="primary"]) {
  --_ss-badge-tint: var(--color-feedback-error-surface);
  color: var(--color-feedback-error-text);
}

span[theme~="badge"][theme~="warning"]:not([theme~="primary"]) {
  --_ss-badge-tint: var(--color-feedback-warning-surface);
  color: var(--color-feedback-warning-text);
}

span[theme~="badge"][theme~="contrast"]:not([theme~="primary"]) {
  --_ss-badge-tint: var(--color-interactive-secondary);
  color: var(--color-text-secondary);
}

/* ---- Card ---- */

.material-card {
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  padding: var(--card-padding);
  background: var(--card-background);
  box-shadow: var(--shadow-xs);
  transition:
    box-shadow var(--duration-fast) var(--easing-ease-out),
    border-color var(--duration-fast) var(--easing-ease-out);
  cursor: pointer;
  min-width: 280px;
  flex: 1 1 300px;
  max-width: 400px;
}

/* A clickable card answers the pointer with its shadow and its border,
   without moving. */
.material-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-default);
}

/* ---- Tabs ---- */

vaadin-tab {
  font-weight: var(--font-weight-medium);
  letter-spacing: -0.01em;
}

vaadin-tab[selected] {
  font-weight: var(--font-weight-semibold);
}

/* ---- Text fields ---- */

vaadin-text-field::part(input-field),
vaadin-password-field::part(input-field),
vaadin-integer-field::part(input-field),
vaadin-select::part(input-field) {
  border-radius: var(--input-radius);
}

/* A field the browser autofilled (the login's e-mail and password) keeps the
   look of any other field. Vaadin 25.2 paints it with
   --vaadin-input-field-autofill-background and -color, which fall back to a
   light yellow and black: a pale box on the dark theme. Here they are the
   field's own background and the body text, per theme (16.77:1 in light,
   16.18:1 in dark). Declared again on every element that switches the theme,
   so each var() reads the tokens of its own theme. */
:root,
[data-theme],
[theme~='dark'] {
  --vaadin-input-field-autofill-background: var(--input-background);
  --vaadin-input-field-autofill-color: var(--color-text-primary);
}

/* ---- Code panel ----
   A well of code: the sunken surface with the primary text (14.90:1 in light,
   17.78:1 in dark), in the design system's mono font. */

.code-panel {
  font-family: var(--font-family-mono);
  font-size: var(--lumo-font-size-s);
  line-height: 1.6;
  background: var(--color-surface-sunken);
  border: 1px solid var(--singularidade-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  color: var(--color-text-primary);
  margin: 0;
  max-height: 360px;
  overflow-y: auto;
}

/* ---- Detail labels ---- */

.detail-label {
  font-size: var(--lumo-font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--lumo-secondary-text-color);
  margin: 0;
  padding: 0;
}

/* ---- Hint badges ---- */

.hint-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--lumo-font-size-xs);
  font-weight: var(--font-weight-medium);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--lumo-contrast-5pct);
  color: var(--lumo-secondary-text-color);
  border: 1px solid var(--lumo-contrast-10pct);
}

/* Selected, like a chip: primary on primary-subtle (5.01:1 | 4.81:1). */
.hint-badge--active {
  background: var(--color-interactive-primary-subtle);
  color: var(--color-interactive-primary);
  border-color: var(--lumo-primary-color-50pct);
}

/* ---- Clickable grid ---- */

.clickable-grid vaadin-grid::part(body-cell) {
  cursor: pointer;
}

/* ---- Notification ---- */
/* Note: box-shadow and border-radius are intentionally NOT set on vaadin-notification-card
   because the card (:host) is wider than the visible overlay. Lumo already styles
   [part='overlay'] inside the shadow DOM with the correct shadow and radius. */

/* The dark-mode body-appended overlay fix used to live here. Moved to the
   parent theme `singularidade-base` (in @singularidade/vaadin-bindings) —
   it's a generic Vaadin Lumo workaround (overlays appended to document.body
   escape shadow-DOM theme inheritance) and applies the same brand-token
   values regardless of which child theme inherits from it. Single source of
   truth at the bridge level. */

/* ---- Focus (accessibility) ----
   One focus indicator everywhere, drawn by Lumo from --vaadin-focus-ring-color
   and --vaadin-focus-ring-width, which the parent theme points at
   color-border-focus and 2px (at least 4.89:1 in light and 6.23:1 in dark on
   base, raised and sunken; Lumo's own 50% primary gave 2.23:1). Buttons,
   checkboxes, tabs and menu items show it on keyboard focus; fields show it on
   any focus, as the design system's text field does. The rules this replaces
   drew a second outline over Lumo's ring. */
:root {
  --lumo-input-field-pointer-focus-visible: 1;
}

/* ---- Read-only choices ---- */

/* A read-only text field already shows a dashed border. A read-only checkbox or radio
   button kept the look of an editable one on the dark theme, so in a dialog opened for
   viewing people clicked it and nothing happened. Dimmed, with the cursor that says no. */
vaadin-checkbox[readonly],
vaadin-checkbox-group[readonly] vaadin-checkbox,
vaadin-radio-group[readonly] vaadin-radio-button {
  opacity: 0.55;
  cursor: not-allowed;
}

vaadin-checkbox[readonly]::part(checkbox),
vaadin-checkbox-group[readonly] vaadin-checkbox::part(checkbox),
vaadin-radio-group[readonly] vaadin-radio-button::part(radio) {
  outline: 1px dashed var(--lumo-contrast-50pct);
  outline-offset: 1px;
}

/* ---- Grid row hover ---- */

/* A pseudo-element cannot be followed by a combinator, nor chained with another one:
   the previous selector never matched anything and Vaadin 25's CSS minifier rejects it.
   Hovering the cell is what a user perceives as hovering the row. */
vaadin-grid::part(body-cell):hover {
  background: var(--singularidade-hover);
}

vaadin-grid::part(body-cell) {
  transition: background-color var(--duration-fast) var(--easing-ease-out);
}

/* ---- Custom scrollbar ---- */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--lumo-contrast-20pct);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--lumo-contrast-30pct);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--lumo-contrast-20pct) transparent;
}

/* ---- Mobile responsive ---- */

@media (max-width: 768px) {
  .material-card {
    min-width: unset;
    max-width: unset;
    flex: 1 1 100%;
  }

  vaadin-grid {
    font-size: var(--lumo-font-size-s);
  }
}

/* ---- Login ---- */

.login-view {
  background: var(--lumo-base-color);
}

vaadin-login-form-wrapper {
  border-radius: var(--radius-lg);
}

/* ---- título da barra superior ---- */
/* O nome do cliente vem de cadastro e pode ser longo. Uma linha só, com
   reticências; o nome inteiro fica na dica do elemento. `min-width: 0` é o que
   permite ao item encolher dentro do flex — sem ele o texto empurra a barra. */
.singularidade-navbar__title {
  min-width: 0;
  max-width: min(38ch, 40vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--lumo-line-height-xs);
}

@media (max-width: 600px) {
  .singularidade-navbar__title {
    max-width: 45vw;
    font-size: var(--lumo-font-size-m);
  }
}

/* ---- Reduced motion ----
   Whoever asks the system for less motion gets none: transitions and
   animations end at once (0.01ms rather than none, so that the transitionend
   and animationend events Vaadin's overlays wait for still arrive). Covers
   this library, the apps' own styles and the hosts of Vaadin's components. */
@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;
  }
}
