/* ==========================================================================
   PT Meja Kreasi Sejahtera — UI component layer

   The vanilla equivalent of the shadcn primitives: button, card, field,
   badge, table, dialog, tabs, toast, skeleton, switch, tooltip, plus the
   app shell and the split-flap board.

   Everything here is namespaced .ui-* so it can never collide with the 334
   class names the existing pages and JS already rely on. Those keep their
   names; only their declarations were retokenized.

   Requires tokens.css.
   ========================================================================== */

/* ==========================================================================
   Liquid glass material

   Surfaces sample and blur what sits behind them, and carry a specular rim
   along the light-facing edge. Two rules keep it honest:

   1. Only floating chrome gets it — top bar, navigation, cards, dialogs,
      toasts. Never list rows or table cells, where a blur per row costs a
      frame budget nothing else can pay back.
   2. The tint stays dense enough that text on glass keeps the contrast
      ratios the tokens were chosen for. Transparency is a look, not an
      excuse for grey-on-grey.
   ========================================================================== */

.ui-glass {
  position: relative;
  isolation: isolate;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-rim);
}

.ui-glass--strong {
  background: var(--glass-bg-strong);
}

/* The rim is a gradient border: bright where the light lands, gone by the
   opposite corner. Painted as a masked ring so it never tints the fill. */
.ui-glass::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(150deg, var(--glass-sheen), transparent 45%);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0.55;
  pointer-events: none;
}

/* Without backdrop-filter the material would read as a washed-out panel, so
   fall back to the opaque surface instead. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ui-glass {
    background: var(--surface);
  }

  .ui-glass--strong {
    background: var(--surface);
  }
}

/* ==========================================================================
   Shell
   ========================================================================== */

.ui-ambient {
  position: fixed;
  inset: 0;
  z-index: var(--z-ambient);
  pointer-events: none;
  background: var(--ambient), var(--bg);
}

/* Any page carrying the bar reserves room for it once, here, so no page has
   to remember to do it and none of them can double up. */
body:has(> .ui-topbar) {
  padding-top: var(--topbar-h);
}

.ui-shell {
  min-height: 100dvh;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
}

.ui-page {
  width: 100%;
  max-width: var(--shell-max);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter);
}

/* --- Top bar ----------------------------------------------------------- */

.ui-topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-inline: var(--gutter);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--glass-rim);
}

.ui-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  color: var(--ink);
  text-decoration: none;
}

.ui-brand__mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: var(--text-sm);
  font-weight: 800;
  overflow: hidden;
}

.ui-brand__mark--logo {
  background: #ffffff;
  padding: 2px;
}

.ui-brand__mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ui-topbar__title {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ui-topbar__spacer {
  flex: 1 1 auto;
}

/* Below 1024px the bottom bar carries navigation, so the back control in the
   top bar is a second route to the same place. It goes, and the bar is left
   with what identifies the page: the mark, the name, the theme switch. */
@media (max-width: 1023px) {
  .ui-topbar #backBtn,
  .ui-topbar #backToDashboard,
  .ui-topbar a.back {
    display: none;
  }
}

/* Narrower still, the wordmark drops — but only where the bar also carries a
   page name. On the attendance page there is no back control and no page
   name, so the bar has room and the company name stays readable. */
@media (max-width: 640px) {
  .ui-topbar:has(.ui-topbar__title) .ui-brand {
    font-size: 0;
    gap: 0;
  }

  .ui-topbar:has(.ui-topbar__title) .ui-brand__mark {
    font-size: var(--text-sm);
  }
}

/* The bar never wraps; the page name truncates instead. */
.ui-topbar {
  flex-wrap: nowrap;
}

.ui-topbar__title {
  min-width: 0;
}

/* --- Navigation --------------------------------------------------------
   Bottom bar on phones; from 1024px the same five items sit in the top bar
   (.ui-topnav). */

.ui-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-nav);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border-top: 1px solid var(--glass-border);
  box-shadow: var(--glass-rim);
}

.ui-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap-min);
  padding: var(--space-1);
  color: var(--ink-muted);
  font-size: var(--text-2xs);
  font-weight: 500;
  text-decoration: none;
  border: 0;
  background: none;
  cursor: pointer;
  position: relative;
  transition: color var(--dur-fast) var(--ease-out);
}

.ui-nav__item:hover {
  color: var(--ink);
}

/* "Lainnya" is a <button>: keep the dashboard's button lift and glow off it. */
.ui-nav__item,
.ui-nav__item:hover,
.ui-nav__item:active {
  border-radius: 0;
  box-shadow: none;
  filter: none;
  transform: none;
}

/* --- Top navigation (desktop) -----------------------------------------
   nav.js puts it in the top bar, after the page name. */

.ui-topnav {
  display: none;
}

@media (min-width: 1024px) {
  .ui-topnav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-left: var(--space-2);
    padding-left: var(--space-4);
    border-left: 1px solid var(--line);
  }
}

.ui-topnav__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  box-shadow: none;
  filter: none;
  transform: none;
  color: var(--ink-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.ui-topnav__item .ui-icon {
  width: 18px;
  height: 18px;
}

/* Explicit on every state: the dashboard lifts and lights every button. */
.ui-topnav__item:hover {
  background: var(--wash-2);
  box-shadow: none;
  filter: none;
  transform: none;
  color: var(--ink);
}

.ui-topnav__item:active {
  box-shadow: none;
  transform: scale(0.97);
}

.ui-topnav__item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.ui-topnav__item[aria-current="page"] {
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand-text);
  font-weight: 600;
}

/* --- Nav sheet: the pages not on the bar, as a grid of tiles ---------- */

.ui-navsheet__list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.ui-navsheet__item {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: var(--space-2);
  min-height: 96px;
  padding: var(--space-3) var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--wash-1);
  color: var(--ink);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: var(--leading-snug);
  text-align: center;
  text-decoration: none;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

.ui-navsheet__item:hover {
  border-color: color-mix(in srgb, var(--brand) 55%, transparent);
}

.ui-navsheet__item[aria-current="page"] {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
}

.ui-navsheet__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand-text);
}

.ui-navsheet__icon .ui-icon {
  width: 20px;
  height: 20px;
}

@media (max-width: 340px) {
  .ui-navsheet__list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.ui-nav__item[aria-current="page"] {
  color: var(--brand-text);
}

/* The active marker is a shape, not only a color — the nav still reads
   correctly for anyone who cannot separate the two hues. */
.ui-nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  border-radius: 0 0 var(--radius-full) var(--radius-full);
  background: var(--brand);
  box-shadow: var(--glow-brand);
}

/* Mobile only. Desktop keeps the dashboard's own layout, which already puts
   its navigation on screen; a left rail there would mean re-offsetting every
   container on every page. */
@media (min-width: 1024px) {
  .ui-nav {
    display: none;
  }
}

/* Room for the bar, plus the home indicator on phones that have one. */
@media (max-width: 1023px) {
  body:has(> .ui-nav) {
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  }
}

/* ==========================================================================
   Icon
   ========================================================================== */

.ui-icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  vertical-align: -0.25em;
}

.ui-icon--sm {
  width: 1em;
  height: 1em;
}

.ui-icon--lg {
  width: 1.75em;
  height: 1.75em;
}

/* ==========================================================================
   Button
   ========================================================================== */

.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  min-width: var(--tap-min);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  letter-spacing: var(--tracking-wide);
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-instant) var(--ease-out);
}

/* Press feedback that does not move neighbours. */
.ui-btn:active {
  transform: scale(0.97);
}

.ui-btn[disabled],
.ui-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.ui-btn--primary {
  background: var(--action);
  color: var(--action-ink);
}

.ui-btn--primary:hover:not([disabled]) {
  background: var(--action-bright);
  box-shadow: var(--glow-brand);
}

.ui-btn--secondary {
  background: var(--glass-bg);
  border-color: var(--glass-border);
  color: var(--ink);
  box-shadow: var(--glass-rim);
}

.ui-btn--secondary:hover:not([disabled]) {
  background: var(--hover-bg-strong);
  border-color: var(--line-strong);
}

.ui-btn--outline {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}

.ui-btn--outline:hover:not([disabled]) {
  background: var(--brand-dim);
}

.ui-btn--ghost {
  background: transparent;
  color: var(--ink-muted);
}

.ui-btn--ghost:hover:not([disabled]) {
  background: var(--hover-bg);
  color: var(--ink);
}

.ui-btn--danger {
  background: var(--danger-dim);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

.ui-btn--danger:hover:not([disabled]) {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 22%, transparent);
}

/* Reserved for the confirming action inside a destructive dialog, where the
   button is the point of no return and should look like it. */
.ui-btn--danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-ink);
}

.ui-btn--danger-solid:hover:not([disabled]) {
  filter: brightness(1.06);
}

.ui-btn--sm {
  min-height: var(--control-h-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.ui-btn--lg {
  min-height: var(--control-h-lg);
  padding: 0 var(--space-6);
  font-size: var(--text-base);
}

.ui-btn--block {
  width: 100%;
}

.ui-btn--icon {
  padding: 0;
  width: var(--control-h);
  aspect-ratio: 1;
}

.ui-btn--icon.ui-btn--sm {
  width: var(--control-h-sm);
}

/* Busy state: the label stays, the spinner replaces the leading icon, and
   the button is inert while the request is in flight. */
.ui-btn[data-busy="true"] {
  pointer-events: none;
  opacity: 0.7;
}

.ui-btn[data-busy="true"] .ui-icon:first-child {
  animation: ui-spin 0.8s linear infinite;
}

@keyframes ui-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Card
   ========================================================================== */

/* Cards are frosted, not clear: translucent fill and a specular rim, but no
   live backdrop blur. A card sits on a near-uniform ambient, so the blur was
   sampling one colour and returning it — 23 blur passes a frame for an effect
   you cannot see. The blur stays where content actually slides behind glass:
   the top bar, the navigation, dialogs and toasts. */
.ui-card {
  position: relative;
  isolation: isolate;
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-rim);
}

.ui-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(150deg, var(--glass-sheen), transparent 45%);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0.55;
  pointer-events: none;
}

.ui-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}

.ui-card__title {
  font-size: var(--text-md);
  font-weight: 700;
}

.ui-card__body {
  padding: var(--space-5);
}

.ui-card__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--line);
}

.ui-card--flush .ui-card__body {
  padding: 0;
}

/* ==========================================================================
   Fields
   ========================================================================== */

.ui-field {
  display: grid;
  gap: var(--space-2);
}

.ui-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-muted);
}

.ui-label__required {
  color: var(--danger);
}

.ui-input,
.ui-select,
.ui-textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  /* 16px on phones — anything smaller makes iOS zoom the viewport on focus. */
  font-size: var(--text-base);
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

@media (max-width: 600px) {
  .ui-input,
  .ui-select,
  .ui-textarea {
    font-size: 16px;
  }
}

.ui-input::placeholder,
.ui-textarea::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

.ui-input:hover,
.ui-select:hover,
.ui-textarea:hover {
  border-color: var(--line-strong);
}

.ui-textarea {
  min-height: 96px;
  resize: vertical;
  line-height: var(--leading-body);
}

.ui-select {
  appearance: none;
  padding-right: var(--space-10);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 20px center, right 14px center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.ui-hint {
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.ui-error {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--danger);
}

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

/* --- Radio and checkbox ------------------------------------------------ */

.ui-choice {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-inset);
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}

.ui-choice:hover {
  border-color: var(--line-strong);
}

.ui-choice:has(:checked) {
  border-color: var(--brand-text);
  background: var(--brand-dim);
}

.ui-choice input {
  accent-color: var(--brand-text);
  width: 18px;
  height: 18px;
  flex: none;
}

/* --- Switch ------------------------------------------------------------ */

.ui-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.ui-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ui-switch__track {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background-color var(--dur) var(--ease-out);
}

.ui-switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--ink);
  transition: transform var(--dur) var(--ease-spring);
}

.ui-switch input:checked + .ui-switch__track {
  background: var(--brand);
  border-color: var(--brand-text);
}

.ui-switch input:checked + .ui-switch__track::after {
  transform: translateX(18px);
  background: var(--brand-ink);
}

.ui-switch input:focus-visible + .ui-switch__track {
  box-shadow: var(--focus-ring);
}

/* ==========================================================================
   Badge and status pill
   ========================================================================== */

.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  white-space: nowrap;
}

.ui-badge--brand {
  background: var(--brand-dim);
  border-color: var(--line-strong);
  color: var(--brand-text);
}

.ui-badge--ok {
  background: var(--ok-dim);
  border-color: color-mix(in srgb, var(--ok) 40%, transparent);
  color: var(--ok);
}

.ui-badge--late {
  background: var(--late-dim);
  border-color: color-mix(in srgb, var(--late) 40%, transparent);
  color: var(--late);
}

.ui-badge--early {
  background: var(--early-dim);
  border-color: color-mix(in srgb, var(--early) 40%, transparent);
  color: var(--early);
}

.ui-badge--izin {
  background: var(--izin-dim);
  border-color: color-mix(in srgb, var(--izin) 40%, transparent);
  color: var(--izin);
}

/* ==========================================================================
   Table
   ========================================================================== */

.ui-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ui-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.ui-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

.ui-table td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.ui-table tbody tr:hover {
  background: var(--hover-bg);
}

.ui-table__num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ==========================================================================
   Avatar

   A person's registered face (profile-photos.js), or their initials on a
   colour of their own. --avatar-hue and --avatar-size are set inline per
   avatar, from the sizes in profile-photos.js.
   ========================================================================== */

.ui-avatar {
  --avatar-size: 28px;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--avatar-size);
  height: var(--avatar-size);
  overflow: hidden;
  border-radius: 50%;
  background: hsl(var(--avatar-hue, 40) 42% 40%);
  box-shadow: 0 0 0 1px var(--line);
  color: #fff;
  font-size: calc(var(--avatar-size) * 0.4);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  vertical-align: middle;
  user-select: none;
}

.ui-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================================================
   Dialog
   ========================================================================== */

.ui-dialog {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--gutter);
}

.ui-dialog[hidden] {
  display: none;
}

.ui-dialog__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  border: 0;
  cursor: pointer;
  /* It is a <button>, and the dashboard styles every button as a lifting,
     glowing pill; on a scrim that read as a giant blurred oval. */
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  filter: none;
  transform: none;
  transition: none;
}

.ui-dialog__scrim:hover,
.ui-dialog__scrim:active {
  box-shadow: none;
  filter: none;
  transform: none;
}

.ui-dialog__panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - var(--space-16));
  overflow-y: auto;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3), var(--glass-rim);
  animation: ui-dialog-in var(--dur) var(--ease-spring);
}

@keyframes ui-dialog-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.ui-dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-5) var(--space-3);
}

.ui-dialog__title {
  font-size: var(--text-md);
  font-weight: 700;
}

.ui-dialog__body {
  padding: 0 var(--space-5) var(--space-5);
}

.ui-dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--line);
}

/* On phones a dialog behaves as a bottom sheet — reachable with one thumb. */
@media (max-width: 600px) {
  .ui-dialog {
    place-items: end center;
    padding: 0;
  }

  .ui-dialog__panel {
    max-width: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation-name: ui-sheet-in;
  }

  @keyframes ui-sheet-in {
    from {
      transform: translateY(100%);
    }
  }
}

/* ==========================================================================
   Tabs
   ========================================================================== */

.ui-tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  scrollbar-width: none;
}

.ui-tabs::-webkit-scrollbar {
  display: none;
}

.ui-tab {
  flex: 1 0 auto;
  min-height: var(--control-h-sm);
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.ui-tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

/* ==========================================================================
   Toast
   ========================================================================== */

.ui-toaster {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  transform: translateX(-50%);
  display: grid;
  gap: var(--space-2);
  width: min(420px, calc(100vw - 2 * var(--gutter)));
  pointer-events: none;
}

@media (min-width: 1024px) {
  .ui-toaster {
    left: auto;
    right: var(--gutter);
    bottom: var(--gutter);
    transform: none;
  }
}

.ui-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2), var(--glass-rim);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: ui-toast-in var(--dur) var(--ease-spring);
}

.ui-toast[data-tone="ok"] {
  border-color: color-mix(in srgb, var(--ok) 50%, transparent);
}

.ui-toast[data-tone="error"] {
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
}

.ui-toast__icon {
  color: var(--brand-text);
}

.ui-toast[data-tone="ok"] .ui-toast__icon {
  color: var(--ok);
}

.ui-toast[data-tone="error"] .ui-toast__icon {
  color: var(--danger);
}

.ui-toast.is-leaving {
  animation: ui-toast-out var(--dur-fast) var(--ease-in) forwards;
}

@keyframes ui-toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes ui-toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ==========================================================================
   Skeleton
   ========================================================================== */

.ui-skeleton {
  border-radius: var(--radius-xs);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 37%,
    var(--surface-2) 63%
  );
  background-size: 400% 100%;
  animation: ui-shimmer 1.4s ease-in-out infinite;
}

@keyframes ui-shimmer {
  from {
    background-position: 100% 50%;
  }
  to {
    background-position: 0 50%;
  }
}

/* ==========================================================================
   Tooltip
   ========================================================================== */

.ui-tip {
  position: relative;
}

.ui-tip__bubble {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-overlay);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-2);
  font-size: var(--text-xs);
  color: var(--ink);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out);
}

/* Focus as well as hover — a tooltip that only answers to a pointer is
   invisible to keyboard users. */
.ui-tip:hover .ui-tip__bubble,
.ui-tip:focus-within .ui-tip__bubble {
  opacity: 1;
}

/* ==========================================================================
   Split-flap board — the signature element

   Attendance is arrival and departure, and the Solari board is that world's
   instrument. Mechanical under Meja Kreasi, holographic under Synaptic;
   the difference is carried entirely by --flap-* tokens.
   ========================================================================== */

.ui-flap {
  display: inline-flex;
  gap: var(--space-1);
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
}

.ui-flap__cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0.72em;
  padding: 0.08em 0.1em;
  perspective: 500px;
  border-radius: var(--radius-xs);
  background: linear-gradient(180deg, var(--flap-face) 0 50%, var(--flap-face-2) 50% 100%);
  box-shadow: var(--flap-shadow);
  font-size: var(--text-flap);
  font-weight: 700;
  line-height: 1;
  color: var(--flap-ink);
}

/* The seam is what makes it read as a flap rather than a tile. */
.ui-flap__cell::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--flap-seam);
  pointer-events: none;
}

/* Synaptic adds a scanline instead of a mechanical highlight. */
.ui-flap__cell::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, transparent 0 45%, var(--flap-scan) 50%, transparent 55% 100%);
  pointer-events: none;
}

.ui-flap__face {
  display: block;
  transform-origin: center;
  backface-visibility: hidden;
}

.ui-flap__cell.is-flipping .ui-flap__face {
  animation: ui-flap var(--dur-flap) var(--ease-out);
}

@keyframes ui-flap {
  0% {
    transform: rotateX(0deg);
  }
  49% {
    transform: rotateX(-90deg);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

.ui-flap--sm .ui-flap__cell {
  font-size: var(--text-xl);
}

.ui-flap__sep {
  align-self: center;
  display: grid;
  align-content: center;
  gap: 0.16em;
  padding-inline: 0.12em;
  font-size: var(--text-flap);
  /* The glyph itself is hidden — the dots below read cleaner at board size. */
  color: transparent;
  width: 0.2em;
}

.ui-flap__sep::before,
.ui-flap__sep::after {
  content: "";
  width: 0.11em;
  height: 0.11em;
  border-radius: 50%;
  background: var(--brand);
}

.ui-flap--sm .ui-flap__sep {
  font-size: var(--text-xl);
}

/* ==========================================================================
   Lottie slot

   The player is lazy-loaded and skipped entirely under reduced motion, so
   every slot ships a static fallback that is styled the same either way.
   ========================================================================== */

.ui-lottie {
  display: grid;
  place-items: center;
  width: var(--lottie-size, 120px);
  height: var(--lottie-size, 120px);
}

.ui-lottie > svg {
  width: 100%;
  height: 100%;
}

.ui-lottie__fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--brand-text);
}

.ui-lottie[data-loaded="true"] .ui-lottie__fallback {
  display: none;
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.ui-stack {
  display: grid;
  gap: var(--space-4);
}

.ui-stack--sm {
  gap: var(--space-2);
}

.ui-stack--lg {
  gap: var(--space-6);
}

.ui-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.ui-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
}

.ui-muted {
  color: var(--ink-muted);
}

.ui-eyebrow {
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--ink-muted);
}

.ui-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Long content — URLs, pasted notes, Firestore ids — reflows instead of
   pushing the page sideways. */
.ui-wrap-any {
  overflow-wrap: anywhere;
  min-width: 0;
}

.ui-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.ui-empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--ink-muted);
}

.ui-empty__title {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--ink);
}

/* Theme control — two swatches, the active one ringed.

   It reads as a choice rather than a mystery button, and it stays legible at
   the size a phone can spare. */
.ui-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  background: var(--glass-bg);
  box-shadow: var(--glass-rim);
}

.ui-theme-swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 3px;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
  /* Light chip under the mark: both logos are drawn for a light ground and
     lose their negative space on the dark theme. The brand colour stays as
     the ring, which is what marks the active one. */
  background: #ffffff;
  cursor: pointer;
  transition:
    transform var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-fast) var(--ease-out);
}

/* Without a logo file the dot still identifies the theme by colour. */
.ui-theme-swatch:not(:has(img)) {
  background: var(--swatch);
}

.ui-theme-swatch__logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* The tap area reaches the 44px minimum without the dot having to be that
   big — the bar would not survive two 44px circles. Placed on the parent so
   the swatch itself can clip its logo. */
.ui-theme-toggle .ui-theme-swatch {
  margin: 8px;
}

.ui-theme-toggle {
  margin: -8px 0;
}

.ui-theme-swatch:hover {
  transform: scale(1.12);
}

.ui-theme-swatch[aria-pressed="true"] {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--swatch),
    0 0 14px var(--swatch);
}

.ui-theme-swatch:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
