/*
 * The pieces every page is built from.
 *
 * Only surfaces blur. A button or an input is translucent white with no
 * backdrop-filter of its own: blurring behind forty small controls costs a
 * laptop's GPU a great deal and looks no different from blurring once behind
 * the panel they sit on.
 */

/* --- Surfaces ------------------------------------------------------------ */

.glass {
  position: relative;
  background-color: var(--glass);
  background-image: var(--sheen);
  border: 1px solid var(--glass-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--highlight), 0 0 0 1px var(--hairline), var(--shadow);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(170%);
  backdrop-filter: blur(var(--glass-blur)) saturate(170%);
}

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

/* Without backdrop-filter the translucency is all cost and no glass: text
   loses contrast against the backdrop and nothing is frosted. Near-solid
   white instead. */
/* The rim: a one-pixel ring of light around the surface, brighter where the
   light falls. Drawn as a masked gradient, because a border cannot be a
   gradient and keep its rounded corners. Not on sheets, which scroll, and
   whose ring would scroll away with their contents. */
.glass::before {
  content: "";
  position: absolute;
  inset: -1px;
  padding: 1px;
  border-radius: inherit;
  background: var(--glass-rim);
  pointer-events: none;
  -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 exclude,
    linear-gradient(#000 0 0);
}

.sheet__panel.glass::before {
  content: none;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass,
  .glass--strong {
    background-color: var(--glass-solid);
  }
}

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

.divider {
  height: 1px;
  border: 0;
  margin: 0;
  background: var(--hairline);
}

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

.btn {
  --btn-bg: var(--glass-strong);
  --btn-ink: var(--ink);
  --btn-edge: var(--hairline-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--btn-edge);
  border-radius: var(--radius-pill);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: var(--text-sm);
  font-weight: 650;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--highlight), var(--shadow-sm);
  transition:
    transform var(--duration-fast) var(--ease),
    background-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease),
    opacity var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover {
  box-shadow: var(--highlight), var(--shadow);
}

.btn:active {
  transform: scale(0.98);
}

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

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn--primary {
  --btn-bg: var(--accent);
  --btn-ink: var(--on-accent);
  --btn-edge: transparent;
  box-shadow: var(--solid-sheen), 0 6px 18px var(--accent-glow);
}

.btn--primary:hover {
  --btn-bg: var(--accent-hover);
  box-shadow: var(--solid-sheen), 0 8px 24px var(--accent-glow-strong);
}

.btn--success {
  --btn-bg: var(--success);
  --btn-ink: var(--on-solid);
  --btn-edge: transparent;
  box-shadow: var(--solid-sheen), 0 6px 18px var(--success-glow);
}

.btn--danger {
  --btn-bg: var(--danger-soft);
  --btn-ink: var(--danger-ink);
  --btn-edge: var(--danger-edge);
}

.btn--danger-solid {
  --btn-bg: var(--danger);
  --btn-ink: var(--on-solid);
  --btn-edge: transparent;
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-edge: transparent;
  box-shadow: none;
}

.btn--ghost:hover {
  --btn-bg: var(--wash-hover);
  box-shadow: none;
}

.btn--sm {
  min-height: 34px;
  padding: 0 14px;
  font-size: var(--text-xs);
}

.btn--lg {
  min-height: 50px;
  padding: 0 26px;
  font-size: var(--text-base);
}

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

.btn--icon {
  width: 42px;
  padding: 0;
}

.btn--icon.btn--sm {
  width: 34px;
}

/* --- Form fields --------------------------------------------------------- */

.label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--ink-2);
}

.hint {
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--ink-3);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  border: 1px solid var(--hairline-strong);
  border-radius: 12px;
  background: var(--glass-strong);
  color: var(--ink);
  box-shadow: var(--inset);
  transition:
    border-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--ink-3);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

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

.textarea {
  min-height: 112px;
  line-height: 1.5;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 42px;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
}

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

/* A <button role="switch" aria-checked>. A real button, so it takes focus and
   answers to Space and Enter without a line of script to make it. */
.switch {
  --switch-w: 46px;
  --switch-h: 28px;
  position: relative;
  display: inline-flex;
  flex: none;
  width: var(--switch-w);
  height: var(--switch-h);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--switch-off);
  box-shadow: var(--inset);
  transition: background-color var(--duration) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(var(--switch-h) - 6px);
  height: calc(var(--switch-h) - 6px);
  border-radius: 50%;
  background: #fff; /* not themed: a knob is white on either track */
  box-shadow: var(--knob-shadow);
  transition: transform var(--duration) var(--ease-spring);
}

.switch[aria-checked="true"] {
  background: var(--success);
}

.switch[aria-checked="true"]::after {
  transform: translateX(calc(var(--switch-w) - var(--switch-h)));
}

.switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Segmented control and chips ----------------------------------------- */

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--wash-strong);
  box-shadow: var(--inset);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 650;
  transition:
    background-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease),
    color var(--duration) var(--ease);
}

.segmented button[aria-pressed="true"] {
  background: var(--raised);
  color: var(--ink);
  box-shadow: var(--raised-shadow);
}

.segmented .count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
}

/* On a phone the options slide sideways rather than wrapping into a second
   row that reads as a second control. */
@media (max-width: 600px) {
  .segmented {
    display: flex;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .segmented::-webkit-scrollbar {
    display: none;
  }

  .segmented button {
    flex: none;
    padding: 7px 12px;
  }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  background: var(--glass-strong);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  transition:
    background-color var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}

.chip[aria-pressed="true"],
.chip[aria-checked="true"] {
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
}

/* --- Badges and avatars -------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--wash-strong);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.badge--accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.badge--success {
  background: var(--success-soft);
  color: var(--success-ink);
}

.badge--danger {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.badge--warning {
  background: var(--warning-soft);
  color: var(--warning-ink);
}

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-from), var(--accent));
  color: var(--on-solid);
  font-size: var(--text-sm);
  font-weight: 700;
  box-shadow: var(--highlight), 0 2px 8px var(--accent-glow);
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Feedback ------------------------------------------------------------ */

.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.8;
  animation: spin 0.7s linear infinite;
}

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

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--wash-strong);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--shimmer), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s var(--ease) infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-7) var(--space-5);
  text-align: center;
  color: var(--ink-3);
}

.empty > .icon {
  width: 40px;
  height: 40px;
  margin-bottom: var(--space-2);
  stroke-width: 1.4;
}

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

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.notice--warning {
  background: var(--warning-soft);
}

.notice--danger {
  background: var(--danger-soft);
}

.notice .icon {
  margin-top: 1px;
}

/* --- Toasts -------------------------------------------------------------- */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  display: grid;
  gap: var(--space-2);
  width: min(560px, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 10px 10px 18px;
  border-radius: 16px;
  background: var(--toast);
  color: var(--toast-ink);
  border: 1px solid var(--toast-edge);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  animation: toast-in var(--duration-slow) var(--ease-spring);
}

.toast__text {
  flex: 1;
  min-width: 0;
}

.toast .btn {
  --btn-bg: var(--toast-control);
  --btn-ink: var(--toast-ink);
  --btn-edge: var(--toast-edge);
  box-shadow: none;
}

.toast--danger {
  background: var(--toast-danger);
}

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

/* --- Dialogs ------------------------------------------------------------- */

/* A native <dialog>: the browser traps focus, closes on Escape and puts the
   rest of the page out of reach, which no hand-rolled overlay gets right. */
dialog.sheet {
  width: 100%;
  max-width: min(560px, calc(100% - 32px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}

dialog.sheet::backdrop {
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

dialog.sheet[open] {
  animation: sheet-in var(--duration-slow) var(--ease-spring);
}

.sheet__panel {
  max-height: min(86vh, 780px);
  padding: var(--space-5);
  overflow: auto;
  border-radius: var(--radius-xl);
}

.sheet__title {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.3;
}

.sheet__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

@media (max-width: 640px) {
  dialog.sheet {
    max-width: 100%;
    margin: auto 0 0;
  }

  .sheet__panel {
    max-height: 90vh;
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
    border-radius: 24px 24px 0 0;
  }

  dialog.sheet[open] {
    animation-name: sheet-up;
  }

  .sheet__actions .btn {
    flex: 1;
  }
}

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