/* Adapted from @stp/ui 0.1.0 foundation.css + components.css ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Â see docs/stp-ui-provenance.md */

:root {
  --letter-spacing-wide: 0.04em;
  --font-weight-regular: 400;
  --line-height-relaxed: 1.625;

  --color-background: var(--bg);
  --color-surface: var(--surface);
  --color-surface-hover: var(--surface-hover, var(--surface-muted));
  --color-surface-muted: var(--surface-muted);
  --color-input-bg: var(--input);
  --color-input-border: var(--border-strong);
  --color-border: var(--border);
  --color-border-strong: var(--border-strong);
  --color-text-primary: var(--text);
  --color-text-secondary: var(--text-secondary);
  --color-text-muted: var(--text-muted);
  --color-text-disabled: color-mix(in srgb, var(--text-muted) 72%, transparent);
  --color-primary: var(--primary);
  --color-primary-hover: var(--primary-hover);
  --color-primary-foreground: #ffffff;
  --color-danger: var(--error);
  --color-danger-hover: var(--error-hover);
  --color-danger-foreground: #ffffff;
  --color-success: var(--success);
  --color-focus-ring: color-mix(in srgb, var(--primary) 28%, transparent);
  --color-overlay: rgb(16 24 40 / 0.42);
  --color-ink: var(--text);
  --color-primary-pressed: var(--primary-hover);
}

html[data-theme="dark"] {
  --color-overlay: rgb(0 0 0 / 0.55);
  --color-focus-ring: color-mix(in srgb, var(--focus) 32%, transparent);
}

:root {
  --scrollbar-size: 14px;
  --scrollbar-track: color-mix(in srgb, var(--color-ink) 12%, transparent);
  --scrollbar-thumb: color-mix(in srgb, var(--color-primary) 58%, var(--color-border-strong));
  --scrollbar-thumb-hover: color-mix(in srgb, var(--color-primary-hover) 72%, var(--color-text-secondary));
}

@supports not selector(::-webkit-scrollbar) {
  html,
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }
}

@supports selector(::-webkit-scrollbar) {
  html,
  * {
    scrollbar-width: auto;
    scrollbar-color: auto;
  }

  *::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
    background: transparent;
  }

  *::-webkit-scrollbar-track {
    background-color: var(--scrollbar-track);
    border-radius: 999px;
    margin: 4px;
  }

  *::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
  }

  *::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
  }
}


/* Buttons Ã¢â‚¬â€ STP border reveal via @property + @keyframes (transitions alone often skip frames).
   Flat overrides for scanner / photo-capture / #intake below. */
@property --stp-wipe {
  syntax: "<percentage>";
  inherits: false;
  initial-value: -8%;
}

@property --stp-gloss-x {
  syntax: "<percentage>";
  inherits: false;
  initial-value: -8%;
}

@property --stp-gloss-a {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

@keyframes stp-btn-reveal {
  from {
    --stp-wipe: -8%;
    --stp-gloss-x: -8%;
    --stp-gloss-a: 0;
  }
  to {
    --stp-wipe: 108%;
    --stp-gloss-x: 108%;
    --stp-gloss-a: 0.55;
  }
}

@keyframes stp-gloss-pass {
  0% {
    opacity: 0;
    transform: translateX(-30%) skewX(-12deg);
  }
  18% {
    opacity: 0.55;
  }
  100% {
    opacity: 0;
    transform: translateX(320%) skewX(-12deg);
  }
}

.btn {
  --stp-fill: var(--color-surface);
  --stp-idle: var(--color-border-strong);
  --stp-reveal: var(--color-primary);
  --stp-reveal-2: var(--color-primary);
  --stp-wipe: -8%;
  --stp-gloss-x: -8%;
  --stp-gloss-a: 0;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: var(--btn-h);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background-color: transparent;
  background-image:
    linear-gradient(
      165deg,
      transparent calc(var(--stp-gloss-x) - 22%),
      color-mix(
          in srgb,
          color-mix(in srgb, var(--stp-reveal) 62%, white) calc(var(--stp-gloss-a) * 100%),
          transparent
        )
        var(--stp-gloss-x),
      transparent calc(var(--stp-gloss-x) + 22%)
    ),
    linear-gradient(var(--stp-fill), var(--stp-fill)),
    linear-gradient(
      165deg,
      var(--stp-reveal) calc(var(--stp-wipe) - 100%),
      var(--stp-reveal-2) var(--stp-wipe),
      transparent var(--stp-wipe)
    ),
    linear-gradient(var(--stp-idle), var(--stp-idle));
  background-clip: padding-box, padding-box, border-box, border-box;
  background-origin: padding-box, padding-box, border-box, border-box;
  background-repeat: no-repeat;
  transition:
    box-shadow var(--transition-fast),
    transform var(--transition-fast),
    color var(--transition-fast),
    opacity var(--transition-fast);
}

/* Visible gloss sweep that never depends on @property interpolation */
.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 42%;
  pointer-events: none;
  z-index: 1;
  border-radius: inherit;
  background: linear-gradient(
    105deg,
    transparent 0%,
    color-mix(in srgb, white 55%, transparent) 48%,
    transparent 100%
  );
  opacity: 0;
  transform: translateX(-40%) skewX(-12deg);
}

.btn:hover,
.btn:focus-visible {
  animation: stp-btn-reveal 520ms linear forwards;
}

.btn:hover::before,
.btn:focus-visible::before {
  animation: stp-gloss-pass 460ms ease-out forwards;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  --stp-fill: var(--color-primary);
  --stp-idle: var(--color-primary-hover);
  --stp-reveal: color-mix(in srgb, var(--color-primary-foreground) 72%, var(--color-primary));
  --stp-reveal-2: color-mix(in srgb, var(--color-primary-foreground) 45%, var(--color-primary));
  color: var(--color-primary-foreground);
}

.btn-primary:hover,
.btn-primary:active:not(:disabled) {
  --stp-fill: var(--color-primary);
}

.btn-secondary {
  --stp-fill: var(--color-surface);
  --stp-idle: var(--color-border-strong);
  --stp-reveal: var(--color-primary);
  --stp-reveal-2: var(--color-primary-hover);
  color: var(--color-text-primary);
}

.btn-secondary:hover,
.btn-secondary:active:not(:disabled) {
  --stp-fill: var(--color-surface);
}

.btn-quiet,
.btn-ghost {
  --stp-fill: color-mix(in srgb, var(--color-background) 62%, var(--color-surface));
  --stp-idle: var(--color-border-strong);
  --stp-reveal: var(--color-primary);
  --stp-reveal-2: var(--color-primary);
  color: var(--color-text-secondary);
}

.btn-quiet:hover,
.btn-quiet:active:not(:disabled),
.btn-ghost:hover,
.btn-ghost:active:not(:disabled) {
  --stp-fill: color-mix(in srgb, var(--color-background) 62%, var(--color-surface));
}

.btn-danger {
  --stp-fill: var(--color-danger);
  --stp-idle: var(--color-danger-hover);
  --stp-reveal: color-mix(in srgb, white 55%, var(--color-danger));
  --stp-reveal-2: var(--color-danger-hover);
  color: var(--color-danger-foreground);
}

.btn-danger:hover,
.btn-danger:active:not(:disabled) {
  --stp-fill: var(--color-danger);
}

.preview-admin .btn {
  --stp-fill: color-mix(in srgb, var(--color-primary-foreground) 14%, transparent);
  --stp-idle: color-mix(in srgb, var(--color-primary-foreground) 38%, transparent);
  --stp-reveal: color-mix(in srgb, var(--color-primary-foreground) 72%, transparent);
  --stp-reveal-2: color-mix(in srgb, var(--color-primary-foreground) 52%, transparent);
  color: var(--color-primary-foreground);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

html:not([data-theme="dark"]) .btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--surface);
}

.btn:disabled,
.btn[aria-busy="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn:disabled:hover,
.btn:disabled:focus-visible,
.btn[aria-busy="true"]:hover {
  animation: none;
}

.btn:disabled::before,
.btn[aria-busy="true"]::before {
  animation: none;
  opacity: 0;
}

/* Text fields */
.login-screen .field-label,
.shell .field-label,
.quick-sheet .field-label {
  font-size: 0.8125rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
}

.login-screen .field input,
.login-screen .field textarea,
.shell .field input,
.shell .field textarea,
.shell input[type="text"],
.shell input[type="search"],
.shell input[type="tel"],
.shell input[type="email"],
.shell input[type="url"],
.shell input[type="password"],
.shell textarea,
.quick-sheet .field input {
  border-color: var(--color-input-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.login-screen .field input:hover:not(:disabled):not(:focus),
.shell .field input:hover:not(:disabled):not(:focus),
.shell .field textarea:hover:not(:disabled):not(:focus) {
  border-color: var(--color-border-strong);
}

.login-screen .field input:focus,
.login-screen .field textarea:focus,
.shell .field input:focus,
.shell .field textarea:focus,
.shell select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

html:not([data-theme="dark"]) .login-screen .field input:focus,
html:not([data-theme="dark"]) .shell .field input:focus,
html:not([data-theme="dark"]) .shell .field textarea:focus {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--surface);
}

.login-screen .field input::placeholder,
.shell .field input::placeholder,
.shell .field textarea::placeholder {
  color: var(--color-text-muted);
}

.shell .field input[aria-invalid="true"],
.shell .field textarea[aria-invalid="true"] {
  border-color: var(--color-danger);
}

.shell .field input[aria-invalid="true"]:focus,
.shell .field textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-danger) 28%, transparent);
}

/* Dialog surfaces (delete confirm, quick add) */
.quick-sheet {
  z-index: var(--z-modal);
  align-items: flex-end;
  padding: var(--space-md);
}

.quick-sheet::before {
  background: var(--color-overlay);
}

.quick-card {
  width: 100%;
  max-width: 32rem;
  max-height: min(90dvh, 720px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-lg);
  gap: var(--space-md);
}

.quick-card h2 {
  margin: 0;
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}

.quick-card > p:not(.note) {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

@media (min-width: 721px) {
  .quick-sheet {
    align-items: center;
    padding: var(--space-xl);
  }

  .quick-card {
    border-radius: var(--radius-xl);
    padding-bottom: var(--space-lg);
  }
}

@media (max-width: 640px) {
  .quick-sheet {
    padding: 0;
  }

  .quick-card {
    max-width: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
    padding-left: calc(var(--space-lg) + env(safe-area-inset-left, 0px));
    padding-right: calc(var(--space-lg) + env(safe-area-inset-right, 0px));
  }
}

/* Keep capture / scan UI on flat controls (partner branches). */
.scanner .btn,
.photo-capture .btn,
#intake .btn {
  /* flat */
  --stp-wipe: initial;
  --stp-gloss-x: initial;
  --stp-gloss-a: initial;
  background-image: none;
  background-clip: border-box;
  background-origin: padding-box;
  background-color: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-weight: 600;
  font-size: inherit;
  transition:
    var(--motion-press),
    opacity var(--duration-fast) var(--ease-standard),
    background-color var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard);
}

.scanner .btn:hover,
.photo-capture .btn:hover,
#intake .btn:hover {
  --stp-wipe: initial;
  --stp-gloss-x: initial;
  --stp-gloss-a: initial;
}

.scanner .btn::before,
.photo-capture .btn::before,
#intake .btn::before {
  content: none;
  animation: none;
  display: none;
}

.scanner .btn:hover,
.photo-capture .btn:hover,
#intake .btn:hover,
.scanner .btn:focus-visible,
.photo-capture .btn:focus-visible,
#intake .btn:focus-visible {
  animation: none;
}


#intake .btn-primary,
.scanner .btn-primary,
.photo-capture .btn-primary {
  background-color: var(--primary);
  color: #fff;
}

#intake .btn-secondary,
.scanner .btn-secondary,
.photo-capture .btn-secondary {
  background: var(--surface);
  border-color: var(--border);
}

@media (hover: hover) {
  .choice:hover:not(:disabled):not(.is-primary) {
    box-shadow: var(--shadow-sm);
  }

  .product-summary:hover,
  .record-card:hover {
    box-shadow: var(--shadow-sm);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn:hover,
  .btn:focus-visible,
  .btn:hover::before,
  .btn:focus-visible::before {
    animation: none !important;
  }
  .btn,
  .login-screen .field input,
  .shell .field input,
  .quick-card,
  .choice,
  .product-summary,
  .record-card {
    transition: none;
  }

  .btn:active:not(:disabled),
  .scanner .btn:active:not(:disabled),
  .photo-capture .btn:active:not(:disabled),
  #intake .btn:active:not(:disabled) {
    transform: none;
  }
}