/* Design system: tokens, ambient light, glass materials and shared controls.
   Loaded before every surface file, so surface rules refine what lives here. */

:root {
  color-scheme: light;

  --bg: #eceef2;
  --surface: rgba(255, 255, 255, 0.68);
  --surface-solid: #ffffff;
  --surface-soft: rgba(255, 255, 255, 0.44);
  --surface-tint: rgba(30, 38, 60, 0.055);
  --ink: #0e0f12;
  --ink-soft: #2a2c33;
  --muted: #5c606b;
  --muted-light: #6b6f7a;
  --placeholder: #86868f;
  --line: rgba(30, 38, 60, 0.1);
  --line-strong: rgba(30, 38, 60, 0.17);
  --line-hover: rgba(30, 38, 60, 0.3);

  --brand: #004bb3;
  --brand-dark: #003f96;
  --brand-soft: rgba(0, 110, 255, 0.11);
  --brand-ink: #003f96;
  --brand-ring: rgba(0, 110, 255, 0.24);
  --focus: #0a6cff;
  --on-ink: #ffffff;

  --green: #1d7a3a;
  --green-soft: rgba(52, 199, 89, 0.15);
  --green-ink: #135e2b;
  --green-line: rgba(52, 199, 89, 0.32);
  --red: #c4202b;
  --red-soft: rgba(255, 59, 48, 0.11);
  --red-ink: #a1141e;
  --red-line: rgba(255, 59, 48, 0.28);
  --amber: #8f5000;
  --amber-soft: rgba(255, 179, 0, 0.17);
  --amber-line: rgba(230, 150, 0, 0.34);
  --violet: #5b36c4;
  --violet-soft: rgba(120, 90, 240, 0.12);
  --pink: #b0275f;
  --pink-soft: rgba(255, 45, 125, 0.1);
  --switch-on: #34c759;

  --glass-bar: rgba(248, 249, 252, 0.8);
  --glass-card: rgba(255, 255, 255, 0.56);
  --glass-control: rgba(255, 255, 255, 0.42);
  --glass-control-hover: rgba(255, 255, 255, 0.8);
  --glass-sheet: rgba(250, 251, 253, 0.8);
  --blur-bar: blur(28px) saturate(180%);
  --blur-card: blur(40px) saturate(170%);
  --blur-control: blur(14px) saturate(170%);
  --lens: radial-gradient(120% 70% at 18% -10%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 58%);
  --lens-soft: radial-gradient(140% 90% at 12% -20%, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 60%);
  --edge: inset 0 1px 0 rgba(255, 255, 255, 0.95), inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    inset 0 -1px 0 rgba(20, 30, 60, 0.05);
  --edge-soft: inset 0 1px 0 rgba(255, 255, 255, 0.85), inset 0 0 0 1px rgba(255, 255, 255, 0.45);

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-sm: 0 1px 1px rgba(16, 24, 40, 0.03), 0 12px 32px -20px rgba(16, 24, 48, 0.22);
  --shadow-md: 0 1px 2px rgba(16, 24, 40, 0.04), 0 22px 50px -22px rgba(16, 24, 48, 0.28);
  --shadow-lg: 0 2px 6px rgba(16, 24, 40, 0.06), 0 30px 80px -24px rgba(16, 24, 48, 0.32);

  --ink-button: #0e0f12;
  --ink-button-hover: #26282e;
  --ink-edge: 0 10px 24px -12px rgba(10, 14, 30, 0.5);

  --radius-xs: 10px;
  --radius-sm: 13px;
  --radius: 18px;
  --radius-lg: 28px;
  --radius-xl: 36px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  --text-xs: 12.5px;
  --text-sm: 13.5px;
  --text-base: 15px;
  --text-md: 16px;
  --text-lg: 19px;
  --text-xl: 24px;
  --text-2xl: 34px;

  --control-h: 48px;
  --btn-h: 46px;
  --btn-h-sm: 38px;

  --dur-fast: 120ms;
  --dur: 180ms;
  --dur-slow: 260ms;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --reader-bg: #e6e8ee;
  --paper: #ffffff;
  --bar-solid: rgba(255, 255, 255, 0.97);

  --amb-base: #eceef2;
  --amb-1: #cfdcf3;
  --amb-2: #e3daf4;
  --amb-3: #d3e9e4;
  --amb-4: #f5ddd3;
}

/* Moods: each context has its own light. */
html[data-mood="sky"] {
  --amb-base: #eceef2;
  --amb-1: #cfdcf3;
  --amb-2: #e3daf4;
  --amb-3: #d3e9e4;
  --amb-4: #f5ddd3;
}

html[data-mood="calm"] {
  --amb-base: #eef0f3;
  --amb-1: #d3e0f3;
  --amb-2: #d6ebe5;
  --amb-3: #e6dcf5;
  --amb-4: #f7dbe0;
}

html[data-mood="dusk"] {
  --amb-base: #eeedf3;
  --amb-1: #dcd5f5;
  --amb-2: #cddcf3;
  --amb-3: #f5d9e2;
  --amb-4: #d4e8ee;
}

html[data-mood="tide"] {
  --amb-base: #ecf0f1;
  --amb-1: #cfe7e3;
  --amb-2: #d0def3;
  --amb-3: #dcecdf;
  --amb-4: #e4dcf5;
}

/* Where the glass cannot blur, or the person asks for less transparency or
   more contrast, every material becomes solid and the light stays still. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root {
    --glass-bar: var(--surface-solid);
    --glass-card: var(--surface-solid);
    --glass-sheet: var(--surface-solid);
    --surface: var(--surface-solid);
  }
}

@media (prefers-reduced-transparency: reduce) {
  :root {
    --glass-bar: var(--surface-solid);
    --glass-card: var(--surface-solid);
    --glass-sheet: var(--surface-solid);
    --glass-control: var(--surface-solid);
    --glass-control-hover: var(--surface-solid);
    --surface: var(--surface-solid);
    --blur-bar: none;
    --blur-card: none;
    --blur-control: none;
  }
}

@media (prefers-contrast: more) {
  :root {
    --glass-bar: var(--surface-solid);
    --glass-card: var(--surface-solid);
    --glass-sheet: var(--surface-solid);
    --glass-control: var(--surface-solid);
    --glass-control-hover: var(--surface-solid);
    --surface: var(--surface-solid);
    --blur-bar: none;
    --blur-card: none;
    --blur-control: none;
    --lens: none;
    --lens-soft: none;
    --muted: var(--ink-soft);
    --muted-light: var(--ink-soft);
    --line: var(--line-hover);
    --line-strong: var(--ink-soft);
    --edge: inset 0 0 0 1px var(--ink-soft);
    --edge-soft: inset 0 0 0 1px var(--ink-soft);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--amb-base);
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  letter-spacing: -0.006em;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background: transparent;
  overflow-x: hidden;
}

/* Ambient light: soft colour fields that drift on the compositor. */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: var(--amb-base);
  pointer-events: none;
  contain: strict;
  transition: background-color 900ms ease;
}

.ambient i {
  position: absolute;
  width: 78vmax;
  height: 78vmax;
  border-radius: 50%;
  opacity: 0.9;
  will-change: transform;
  animation: amb-a 46s ease-in-out infinite alternate;
}

.ambient i:nth-child(1) {
  top: -34vmax;
  left: -26vmax;
  background: radial-gradient(closest-side, var(--amb-1), transparent);
}

.ambient i:nth-child(2) {
  top: -22vmax;
  right: -36vmax;
  background: radial-gradient(closest-side, var(--amb-2), transparent);
  animation-name: amb-b;
  animation-duration: 54s;
}

.ambient i:nth-child(3) {
  bottom: -40vmax;
  left: -10vmax;
  background: radial-gradient(closest-side, var(--amb-3), transparent);
  animation-name: amb-c;
  animation-duration: 60s;
}

.ambient i:nth-child(4) {
  right: -30vmax;
  bottom: -34vmax;
  background: radial-gradient(closest-side, var(--amb-4), transparent);
  animation-name: amb-b;
  animation-duration: 70s;
  animation-direction: alternate-reverse;
}

.ambient b {
  position: absolute;
  top: -20vmax;
  left: 20%;
  width: 60vmax;
  height: 40vmax;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.55), transparent);
  will-change: transform;
  animation: amb-sun 38s ease-in-out infinite alternate;
}

.ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.07;
}

@keyframes amb-a {
  to {
    transform: translate3d(14vmax, 10vmax, 0) scale(1.12);
  }
}

@keyframes amb-b {
  to {
    transform: translate3d(-16vmax, 12vmax, 0) scale(0.9);
  }
}

@keyframes amb-c {
  to {
    transform: translate3d(10vmax, -14vmax, 0) scale(1.15);
  }
}

@keyframes amb-sun {
  to {
    transform: translate3d(-24vmax, 8vmax, 0);
  }
}

html[data-idle] .ambient i,
html[data-idle] .ambient b,
html[data-still] .ambient i,
html[data-still] .ambient b {
  animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
  .ambient i,
  .ambient b {
    animation: none;
  }
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .ambient i,
  .ambient b {
    animation: none;
    opacity: 0.55;
  }
}

/* Glass materials. Bars and sheets blur; cards are frosted without blur so
   long lists stay cheap to scroll. */
.glass,
.glass-bar,
.glass-control {
  position: relative;
  -webkit-backdrop-filter: var(--blur-card);
  backdrop-filter: var(--blur-card);
  background: var(--lens), var(--glass-card);
  box-shadow: var(--edge), var(--shadow-md);
}

.glass-bar {
  -webkit-backdrop-filter: var(--blur-bar);
  backdrop-filter: var(--blur-bar);
  background: var(--lens-soft), var(--glass-bar);
  box-shadow: var(--edge-soft), var(--shadow-sm);
}

.glass-control {
  -webkit-backdrop-filter: var(--blur-control);
  backdrop-filter: var(--blur-control);
  background: var(--lens-soft), var(--glass-control);
  box-shadow: var(--edge-soft), var(--shadow-xs);
}

[hidden] {
  display: none !important;
}

a {
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
}

:where(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2 {
  text-wrap: balance;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

p {
  text-wrap: pretty;
}

h1 {
  font-size: var(--text-2xl);
  line-height: 1.1;
  letter-spacing: -0.035em;
  font-weight: 500;
}

h2 {
  font-size: var(--text-lg);
  line-height: 1.25;
  letter-spacing: -0.022em;
  font-weight: 550;
}

h3 {
  font-size: var(--text-md);
  line-height: 1.35;
  letter-spacing: -0.01em;
  font-weight: 560;
}

::selection {
  background: var(--brand-ring);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

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

.small {
  font-size: var(--text-xs);
  line-height: 1.45;
}

.tnum {
  font-variant-numeric: tabular-nums;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-width: 0;
}

.col {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

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

.spacer {
  flex: 1;
}

/* Brand mark: a file whose lower half has set solid, the seal rising. */
.mark {
  display: block;
  flex: none;
  overflow: visible;
}

.mark-stop-a {
  stop-color: #e4e9f5;
}

.mark-stop-b {
  stop-color: #a9b6d4;
}

.mark-sheet {
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 0.8;
}

.mark-seal {
  fill: var(--ink);
}

.mark-fold {
  fill: rgba(255, 255, 255, 0.92);
}

.mark-seam {
  fill: rgba(255, 255, 255, 0.95);
}

.brand-mark {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: none;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

.brand-word {
  color: var(--ink);
  font-size: var(--text-md);
  font-weight: 560;
  letter-spacing: -0.02em;
}

/* Buttons: capsules. One ink button per screen, everything else glass. */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--btn-h);
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 550;
  letter-spacing: -0.01em;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  transition:
    background-color var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease,
    color var(--dur-fast) ease,
    opacity var(--dur-fast) ease,
    transform var(--dur) var(--ease-spring);
}

.btn svg {
  flex: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
  transition-duration: 70ms;
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn:disabled:active,
.btn[aria-busy="true"]:active {
  transform: none;
}

.btn[aria-busy="true"] {
  cursor: progress;
  opacity: 0.85;
}

.btn-primary,
.btn-dark {
  background: var(--ink-button);
  color: var(--on-ink);
  box-shadow: var(--ink-edge);
}

.btn-secondary {
  -webkit-backdrop-filter: var(--blur-control);
  backdrop-filter: var(--blur-control);
  background: var(--glass-control);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.btn-ghost {
  color: var(--ink-soft);
}

.btn-danger {
  background: linear-gradient(180deg, #f2443a 0%, #d0202a 100%);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 2px rgba(150, 10, 20, 0.22),
    0 8px 20px -8px rgba(200, 20, 30, 0.45);
}

.btn-sm {
  height: var(--btn-h-sm);
  gap: 6px;
  padding: 0 13px;
  font-size: var(--text-xs);
}

.btn-lg {
  height: 52px;
  padding: 0 24px;
  font-size: var(--text-md);
}

.btn-icon {
  width: var(--btn-h);
  padding: 0;
}

.btn-block {
  width: 100%;
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled),
  .btn-dark:hover:not(:disabled) {
    background: var(--ink-button-hover);
  }

  .btn-secondary:hover:not(:disabled) {
    background: var(--lens-soft), var(--glass-control-hover);
  }

  .btn-ghost:hover:not(:disabled) {
    background: var(--surface-tint);
    color: var(--ink);
  }

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

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.label {
  color: var(--ink-soft);
  font-size: var(--text-xs);
  font-weight: 560;
  letter-spacing: 0;
  line-height: 1.4;
}

.input,
.textarea,
.select {
  width: 100%;
  height: var(--control-h);
  min-height: var(--control-h);
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--glass-control);
  color: var(--ink);
  font-size: var(--text-base);
  line-height: 1.4;
  outline: none;
  box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 1px 2px rgba(16, 24, 40, 0.05);
  transition:
    background-color var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease;
}

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

.select {
  padding-right: 36px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238c8479' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}

.select option {
  background: var(--surface-solid);
  color: var(--ink);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.55;
}

@media (hover: hover) and (pointer: fine) {
  .input:hover:not(:disabled):not(:focus),
  .textarea:hover:not(:disabled):not(:focus),
  .select:hover:not(:disabled):not(:focus) {
    box-shadow: inset 0 0 0 1px var(--line-hover), inset 0 1px 2px rgba(16, 24, 40, 0.05);
  }
}

.input:focus,
.textarea:focus,
.select:focus {
  background-color: var(--glass-control-hover);
  box-shadow: inset 0 0 0 1.5px var(--brand), 0 0 0 4px var(--brand-ring);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  background-color: var(--surface-tint);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

.input:disabled::placeholder,
.textarea:disabled::placeholder {
  color: var(--muted-light);
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"],
.select[aria-invalid="true"],
.input.invalid,
.textarea.invalid,
.select.invalid {
  box-shadow: inset 0 0 0 1.5px var(--red);
}

.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus,
.input.invalid:focus,
.textarea.invalid:focus,
.select.invalid:focus {
  box-shadow: inset 0 0 0 1.5px var(--red), 0 0 0 4px var(--red-soft);
}

@media (forced-colors: active) {
  .input,
  .textarea,
  .select {
    border: 1px solid;
  }

  .input:focus,
  .textarea:focus,
  .select:focus {
    outline: 2px solid;
    outline-offset: 1px;
  }
}

.file-input {
  height: auto;
  padding: 7px 10px;
  color: var(--muted);
  font-size: var(--text-xs);
  cursor: pointer;
}

.file-input::file-selector-button {
  height: 30px;
  margin-right: 10px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--line);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 560;
  cursor: pointer;
}

.file-input::file-selector-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hint {
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.error-text {
  color: var(--red-ink);
  font-size: var(--text-xs);
  line-height: 1.45;
}

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

.hidden-input {
  display: none !important;
}

.copy-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.copy-field .input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* Surfaces */
.card {
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--lens-soft), var(--surface);
  box-shadow: var(--edge), var(--shadow-sm);
}

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

.panel-title {
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 560;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.card-header h2,
.card-header h3 {
  font-size: var(--text-md);
  font-weight: 560;
  letter-spacing: -0.014em;
  line-height: 1.35;
}

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

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: 24px;
}

.page-header > div {
  min-width: 0;
}

.page-header h1 {
  font-size: 40px;
  overflow-wrap: anywhere;
}

.page-header p {
  max-width: 68ch;
  margin-top: 8px;
  color: var(--muted);
  font-size: var(--text-md);
  line-height: 1.45;
  letter-spacing: -0.012em;
  overflow-wrap: anywhere;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: 24px;
}

.tile,
.stat-card {
  --tile-a: #27324e;
  --tile-b: #4d87a1;
  --tile-c: #aadfe6;
  position: relative;
  min-width: 0;
  min-height: 132px;
  padding: 18px 20px 20px;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(95% 85% at 88% 112%, var(--tile-c), transparent 62%),
    radial-gradient(85% 95% at -4% 104%, var(--tile-b), transparent 66%),
    var(--tile-a);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), inset 0 0 30px rgba(255, 255, 255, 0.12), var(--shadow-sm);
  color: #fff;
}

.tile:nth-child(4n + 2),
.stat-card:nth-child(4n + 2) {
  --tile-a: #4b2d56;
  --tile-b: #cd72a4;
  --tile-c: #f6c5dd;
}

.tile:nth-child(4n + 3),
.stat-card:nth-child(4n + 3) {
  --tile-a: #2e305e;
  --tile-b: #6c71cc;
  --tile-c: #bbc8f8;
}

.tile:nth-child(4n + 4),
.stat-card:nth-child(4n + 4) {
  --tile-a: #6b3827;
  --tile-b: #dd895f;
  --tile-c: #fbd5a4;
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.stat-label {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.86);
  font-size: var(--text-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.34);
  color: #fff;
}

.stat-value {
  margin-top: 18px;
  font-size: 44px;
  font-weight: 300;
  letter-spacing: -0.045em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-sub {
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.78);
  font-size: var(--text-xs);
  line-height: 1.4;
}

/* Empty state: one line and the one action. */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 48px var(--space-6);
  text-align: center;
}

.empty-icon {
  display: flex;
  width: 52px;
  height: 52px;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-2);
  border-radius: 16px;
  background: var(--lens), var(--glass-control);
  box-shadow: var(--edge), var(--shadow-sm);
  color: var(--ink-soft);
}

.empty h3 {
  font-size: var(--text-md);
  font-weight: 560;
  letter-spacing: -0.012em;
}

.empty p {
  max-width: 40ch;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* Loading */
.loading-block {
  display: flex;
  min-height: 180px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-7);
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

.loading-block .spinner {
  width: 22px;
  height: 22px;
}

.page-loader {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--muted);
  font-size: var(--text-sm);
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-tint) 25%, var(--surface-soft) 37%, var(--surface-tint) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid var(--line-strong);
  border-top-color: var(--ink);
  border-radius: 999px;
  animation: spin 0.65s linear infinite;
}

.spinner-light {
  border-color: color-mix(in srgb, var(--on-ink) 30%, transparent);
  border-top-color: var(--on-ink);
}

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

/* Error panel */
.error-panel {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--lens-soft), var(--red-soft), var(--surface);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--red-line);
}

.error-panel-icon {
  display: flex;
  width: 34px;
  height: 34px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red);
}

.error-panel-title {
  color: var(--red-ink);
  font-size: var(--text-sm);
  font-weight: 560;
  line-height: 1.4;
}

.error-panel-text {
  margin-top: 2px;
  color: var(--red-ink);
  font-size: var(--text-xs);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.error-panel .btn {
  flex: none;
}

/* Toasts: glass capsules. */
.toast-stack {
  position: fixed;
  right: var(--space-5);
  bottom: max(var(--space-5), env(safe-area-inset-bottom));
  z-index: 120;
  display: flex;
  max-width: calc(100vw - 40px);
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  padding: 13px 18px;
  border: 0;
  border-radius: 22px;
  -webkit-backdrop-filter: var(--blur-bar);
  backdrop-filter: var(--blur-bar);
  background: var(--lens), var(--glass-sheet);
  color: var(--ink);
  box-shadow: var(--edge), var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 550;
  line-height: 1.45;
  overflow-wrap: anywhere;
  opacity: 1;
  transform: none;
  transition:
    opacity var(--dur-slow) var(--ease-out),
    transform var(--dur-slow) var(--ease-spring);
}

@starting-style {
  .toast {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
}

.toast.error {
  color: var(--red-ink);
  box-shadow: var(--edge), var(--shadow-lg), inset 0 0 0 1px var(--red-line);
}

.toast.success {
  color: var(--green-ink);
  box-shadow: var(--edge), var(--shadow-lg), inset 0 0 0 1px var(--green-line);
}

/* Badges: a dot of colour and a word. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 560;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
}

.badge-slate {
  background: var(--surface-tint);
  color: var(--ink-soft);
}

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

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

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

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

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

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

/* File badge: every stored file is a sealed block of glass. */
.file-badge {
  position: relative;
  display: inline-flex;
  width: 38px;
  height: 44px;
  flex: none;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  padding-bottom: 6px;
  border-radius: 10px 15px 10px 10px;
  background: var(--lens), var(--glass-control);
  box-shadow: var(--edge), var(--shadow-xs);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 560;
  letter-spacing: 0.02em;
  line-height: 1;
}

.file-badge::before {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 46%;
  background: var(--fb, var(--surface-tint));
}

.file-badge::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-bottom-left-radius: 5px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: -1px 1px 2px rgba(16, 24, 40, 0.12);
}

.file-badge > * {
  position: relative;
}

.file-badge.red {
  --fb: linear-gradient(180deg, #ff6a5f, #e0322a);
  color: #fff;
}

.file-badge.blue {
  --fb: linear-gradient(180deg, #4aa3ff, #0a68e6);
  color: #fff;
}

.file-badge.violet {
  --fb: linear-gradient(180deg, #a58cff, #6a4ee0);
  color: #fff;
}

.file-badge.green {
  --fb: linear-gradient(180deg, #4dd07a, #1e9a48);
  color: #fff;
}

.file-badge.amber {
  --fb: linear-gradient(180deg, #ffc23d, #e08600);
  color: #fff;
}

.file-badge.slate {
  --fb: linear-gradient(180deg, #a3a9b6, #636a78);
  color: #fff;
}

/* Avatar */
.avatar {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(160deg, var(--amb-2), var(--amb-1));
  color: #2b241d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  font-size: var(--text-xs);
  font-weight: 560;
  line-height: 1;
  letter-spacing: 0.01em;
}

.avatar-lg {
  width: 42px;
  height: 42px;
  font-size: 15px;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.table-wrap:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.table th {
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 560;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--ink-soft);
}

.table td .strong,
.table td strong {
  color: var(--ink);
  font-weight: 560;
}

.table th.num,
.table td.num,
.table th.numeric,
.table td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table tbody tr {
  transition: background-color var(--dur-fast) ease;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

@media (hover: hover) and (pointer: fine) {
  .table tbody tr:hover {
    background: var(--surface-tint);
  }
}

/* Notices */
.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-4);
  padding: 12px 16px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--lens-soft), var(--surface);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--line);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.notice svg {
  flex: none;
}

.notice-error {
  background: var(--lens-soft), var(--red-soft), var(--surface);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--red-line);
  color: var(--red-ink);
}

.notice-success {
  background: var(--lens-soft), var(--green-soft), var(--surface);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--green-line);
  color: var(--green-ink);
}

.notice-info {
  background: var(--lens-soft), var(--brand-soft), var(--surface);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--brand-ring);
  color: var(--brand-ink);
}

.form-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--red-soft);
  color: var(--red-ink);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.form-note {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--green-soft);
  color: var(--green-ink);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.inline-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: var(--text-xs);
}

.inline-status .spinner {
  width: 14px;
  height: 14px;
  border-width: 1.5px;
}

.upload-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: var(--text-xs);
}

.upload-progress .spinner {
  width: 14px;
  height: 14px;
  border-width: 1.5px;
}

.preview-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.success-hero {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--lens), var(--green-soft), var(--surface);
  box-shadow: var(--edge), inset 0 0 0 1px var(--green-line);
}

.success-icon {
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(180deg, #4fd67a, #22a64e);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 6px 16px -6px rgba(30, 150, 70, 0.55);
}

.success-hero h3 {
  color: var(--green-ink);
  font-size: var(--text-sm);
}

.success-hero p {
  margin-top: 3px;
  color: var(--green-ink);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.share-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
  font-size: var(--text-xs);
}

/* Shared primitives */
.icon {
  display: block;
  flex: none;
}

.clipboard-helper {
  position: fixed;
  opacity: 0;
  pointer-events: none;
}

.copy-btn {
  min-width: 96px;
}

.copy-btn.copy-btn-icon {
  min-width: 0;
}

.copy-btn .copy-label {
  display: inline-block;
  min-width: 46px;
  text-align: left;
}

/* Fingerprint light: a SHA-256 drawn as an iris, one ray per byte. */
.iris {
  display: block;
  flex: none;
  overflow: visible;
}

.iris-rays line {
  stroke: currentColor;
  stroke-linecap: round;
}

.iris-glow {
  opacity: 0.95;
}

.iris-ring {
  fill: none;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 1.2;
}

.iris-core {
  fill: rgba(255, 255, 255, 0.92);
}

.iris {
  color: #fff;
  filter: drop-shadow(0 6px 14px rgba(16, 24, 40, 0.18));
}

.iris.is-forming .iris-rays {
  animation: iris-rays 900ms var(--ease-out) both;
  transform-box: view-box;
  transform-origin: 50% 50%;
}

.iris.is-forming .iris-glow {
  animation: iris-glow 1100ms var(--ease-out) both;
  transform-box: view-box;
  transform-origin: 50% 50%;
}

@keyframes iris-rays {
  from {
    opacity: 0;
    transform: rotate(-60deg) scale(0.55);
  }
}

@keyframes iris-glow {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .iris.is-forming .iris-rays,
  .iris.is-forming .iris-glow {
    animation: none;
  }
}

/* Sheets: centred on wide screens, a bottom sheet with a grabber on phones. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: rgba(8, 12, 24, 0.24);
  overscroll-behavior: contain;
  opacity: 1;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: var(--radius-xl);
  -webkit-backdrop-filter: var(--blur-card);
  backdrop-filter: var(--blur-card);
  background: var(--lens), var(--glass-sheet);
  box-shadow: var(--edge), var(--shadow-lg);
  opacity: 1;
  transform: none;
  transform-origin: center;
  transition:
    opacity var(--dur-slow) var(--ease-out),
    transform 380ms var(--ease-drawer);
}

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

.modal-lg {
  max-width: 720px;
}

@starting-style {
  .modal-backdrop {
    opacity: 0;
  }

  .modal {
    opacity: 0;
    transform: scale(0.96);
  }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 22px 22px 12px 24px;
}

.modal-header h2 {
  font-size: var(--text-lg);
  font-weight: 560;
  letter-spacing: -0.02em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.modal-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.modal-header .icon-btn {
  border-radius: 999px;
  background: var(--surface-tint);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 24px 20px;
  overflow-wrap: anywhere;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 14px 24px 22px;
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--glass-control);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  color: var(--ink-soft);
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    transform var(--dur) var(--ease-spring);
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.9);
  transition-duration: 70ms;
}

.icon-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.icon-btn:disabled:active {
  transform: none;
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover:not(:disabled) {
    background: var(--surface-tint);
    color: var(--ink);
  }
}

/* Filters and search */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.search-box {
  position: relative;
  flex: 1 1 220px;
  min-width: 0;
  max-width: 340px;
}

.search-box .input {
  padding-left: 38px;
  border-radius: 999px;
}

.search-box svg {
  position: absolute;
  top: 50%;
  left: 14px;
  width: 16px;
  height: 16px;
  color: var(--muted-light);
  pointer-events: none;
  transform: translateY(-50%);
}

.search-box:focus-within svg {
  color: var(--ink);
}

/* Link display */
.link-url {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  padding: 5px 6px 5px 12px;
  border-radius: 999px;
  background: var(--surface-tint);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0;
}

.link-url > span,
.link-url > a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tags */
.tag-input {
  display: flex;
  min-height: var(--control-h);
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--glass-control);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: box-shadow var(--dur-fast) ease;
}

.tag-input:focus-within {
  box-shadow: inset 0 0 0 1.5px var(--brand), 0 0 0 4px var(--brand-ring);
}

.tag {
  display: inline-flex;
  height: 30px;
  align-items: center;
  gap: 4px;
  padding: 0 4px 0 11px;
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: var(--edge-soft), inset 0 0 0 1px var(--line);
  font-size: var(--text-xs);
  font-weight: 550;
  line-height: 1;
  max-width: 100%;
}

.tag > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag button {
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--surface-tint);
  color: currentColor;
  line-height: 1;
  opacity: 0.7;
  transition: opacity var(--dur-fast) ease;
}

.tag button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
  .tag button:hover {
    opacity: 1;
  }
}

/* Toggle rows: settings style. */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 56px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.toggle-row:last-child {
  border-bottom: 0;
}

.toggle-row > div {
  min-width: 0;
}

.toggle-row .title {
  font-size: var(--text-base);
  font-weight: 500;
  line-height: 1.35;
}

.toggle-row .desc {
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.45;
}

/* Switch: platform proportions, spring knob. */
.switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--line-strong);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background-color 200ms ease;
}

.switch::before {
  content: "";
  position: absolute;
  inset: -7px -4px;
  border-radius: 999px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.16), 0 1px 1px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
  transition: transform 280ms var(--ease-spring), width 160ms var(--ease-out);
}

.switch:active:not(:disabled)::after {
  width: 33px;
}

.switch.on:active:not(:disabled)::after {
  transform: translateX(14px);
}

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

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

.switch.on {
  background: var(--switch-on);
  box-shadow: none;
}

.switch.on::after {
  transform: translateX(20px);
}

/* Segmented control */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-tint);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tab {
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: var(--text-xs);
  font-weight: 560;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease,
    transform var(--dur) var(--ease-spring);
}

.tab:active {
  transform: scale(0.96);
}

.tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.tab.active {
  background: var(--lens), var(--surface-solid);
  color: var(--ink);
  box-shadow: var(--edge), 0 2px 8px -2px rgba(16, 24, 40, 0.2);
}

@media (hover: hover) and (pointer: fine) {
  .tab:hover:not(.active) {
    color: var(--ink);
  }
}

.filter-chip {
  display: inline-flex;
  height: 40px;
  align-items: center;
  gap: 7px;
  padding: 0 17px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    transform var(--dur) var(--ease-spring);
}

.filter-chip:active {
  transform: scale(0.96);
}

.filter-chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.filter-chip.active {
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: 0 8px 20px -12px rgba(16, 24, 48, 0.4);
}

@media (hover: hover) and (pointer: fine) {
  .filter-chip:hover:not(.active) {
    background: var(--glass-control-hover);
    color: var(--ink);
  }
}

/* Activity and event rows */
.activity-list {
  display: flex;
  flex-direction: column;
}

.activity-list.bordered {
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--lens-soft), var(--surface);
  box-shadow: var(--edge), var(--shadow-sm);
}

.activity-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.activity-row:last-child {
  border-bottom: 0;
}

.activity-row .text {
  min-width: 0;
  flex: 1;
  font-size: var(--text-sm);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.activity-row .time {
  color: var(--muted-light);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.event-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}

.event-row:last-child {
  border-bottom: 0;
}

.event-row-link {
  color: inherit;
  text-decoration: none;
  transition: background-color var(--dur-fast) ease;
}

.event-row-link:active {
  background: var(--surface-tint);
}

@media (hover: hover) and (pointer: fine) {
  .event-row-link:hover {
    background: var(--surface-tint);
  }
}

.event-row-link:focus-visible {
  background: var(--surface-tint);
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.event-icon {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--surface-tint);
  color: var(--ink-soft);
}

.event-body {
  min-width: 0;
  flex: 1;
}

.event-title {
  color: var(--ink);
  font-size: var(--text-sm);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.4;
}

.event-kind {
  color: var(--muted);
  font-weight: 560;
}

.event-time {
  color: var(--muted-light);
}

.event-dot {
  color: var(--muted-light);
  font-size: var(--text-xs);
  line-height: 1;
}

.event-agent {
  max-width: 120px;
  flex: none;
  margin-left: var(--space-1);
  padding: 3px 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-tint);
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .event-agent {
    display: none;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .page-header h1 {
    font-size: 34px;
  }

  .stat-card {
    min-height: 118px;
    padding: 16px 16px 18px;
    border-radius: var(--radius-lg);
  }

  .stat-value {
    font-size: 38px;
  }

  .page-actions {
    width: 100%;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .input,
  .textarea,
  .select {
    min-height: 48px;
    font-size: 16px;
  }

  .input {
    height: 48px;
  }

  .file-input {
    font-size: var(--text-xs);
  }

  .btn {
    height: 44px;
  }

  .btn-sm {
    height: 40px;
  }

  .btn-lg {
    height: 54px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .tab {
    height: 38px;
    padding: 0 16px;
  }

  .filter-chip {
    height: 40px;
    padding: 0 16px;
  }

  .search-box {
    max-width: none;
    flex-basis: 100%;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: max(12px, env(safe-area-inset-top)) 0 0;
  }

  .modal {
    max-width: none;
    max-height: calc(100dvh - max(24px, env(safe-area-inset-top)));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }

  .modal::before {
    content: "";
    position: sticky;
    top: 0;
    z-index: 2;
    display: block;
    width: 38px;
    height: 5px;
    margin: 8px auto -13px;
    border-radius: 999px;
    background: var(--line-hover);
  }

  @starting-style {
    .modal {
      opacity: 1;
      transform: translateY(100%);
    }
  }

  .modal-header {
    padding: 22px 18px 10px 20px;
  }

  .modal-body {
    padding: 10px 20px 18px;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: 12px 20px max(16px, env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--glass-sheet) 70%, transparent);
  }

  .modal-footer .btn {
    flex: 1;
    height: 52px;
  }

  .toast-stack {
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    bottom: auto;
    left: 12px;
    max-width: none;
    align-items: center;
  }

  .toast {
    min-width: 0;
    max-width: 100%;
  }

  @starting-style {
    .toast {
      opacity: 0;
      transform: translateY(-16px) scale(0.96);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-backdrop,
  .toast {
    transition: opacity var(--dur) ease;
  }

  @starting-style {
    .modal,
    .toast {
      transform: none;
    }
  }

  .btn:active:not(:disabled),
  .icon-btn:active:not(:disabled),
  .tab:active,
  .filter-chip:active {
    transform: none;
  }

  .switch::after {
    transition: none;
  }

  .skeleton {
    animation: none;
    background: var(--surface-tint);
  }

  .spinner {
    animation-duration: 1.6s;
  }
}
