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

:root {
  color-scheme: light;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-soft: #fafbfd;
  --surface-tint: #f2f5fb;
  --ink: #0f172a;
  --ink-soft: #344054;
  --muted: #5b6677;
  --muted-light: #667085;
  --placeholder: #98a2b3;
  --line: #e7eaf0;
  --line-strong: #d8dde7;
  --line-hover: #c9d0dc;

  --brand: #2f6bff;
  --brand-dark: #1f55d6;
  --brand-soft: #eef4ff;
  --brand-ink: #1743b3;
  --brand-ring: rgba(47, 107, 255, 0.14);

  --green: #079455;
  --green-soft: #ecfdf3;
  --green-ink: #05603a;
  --red: #d92d20;
  --red-soft: #fef3f2;
  --red-ink: #b42318;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --violet: #6941c6;
  --violet-soft: #f4f3ff;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 10px 24px -6px rgba(16, 24, 40, 0.1), 0 2px 6px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 24px 60px -12px rgba(16, 24, 40, 0.22), 0 6px 16px -8px rgba(16, 24, 40, 0.12);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --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: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 26px;

  --control-h: 40px;
  --btn-h: 38px;
  --btn-h-sm: 32px;

  --dur-fast: 120ms;
  --dur: 160ms;
  --dur-slow: 220ms;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

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

body {
  overflow-x: hidden;
}

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

button,
input,
textarea,
select {
  font: inherit;
  color: 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(--brand);
  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.2;
  letter-spacing: -0.022em;
  font-weight: 650;
}

h2 {
  font-size: var(--text-lg);
  line-height: 1.3;
  letter-spacing: -0.014em;
  font-weight: 600;
}

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

::selection {
  background: #dbe6ff;
}

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

.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;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--btn-h);
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  user-select: none;
  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) var(--ease-out);
}

.btn svg {
  flex: none;
}

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

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

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

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

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

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

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-soft);
  box-shadow: var(--shadow-xs);
}

.btn-dark {
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

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

.btn-danger {
  background: var(--red-ink);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

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

.btn-lg {
  height: 44px;
  padding: 0 20px;
  font-size: var(--text-base);
  border-radius: var(--radius);
}

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

.btn-block {
  width: 100%;
}

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

  .btn-secondary:hover:not(:disabled) {
    border-color: var(--line-hover);
    background: var(--surface-soft);
    color: var(--ink);
  }

  .btn-dark:hover:not(:disabled) {
    background: #1d2939;
  }

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

  .btn-danger:hover:not(:disabled) {
    background: #912018;
  }
}

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

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

.input,
.textarea,
.select {
  width: 100%;
  height: var(--control-h);
  min-height: var(--control-h);
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-base);
  line-height: 1.4;
  outline: none;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

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

.select {
  padding-right: 34px;
  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='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

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

.textarea {
  height: auto;
  min-height: 88px;
  padding: 9px 11px;
  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) {
    border-color: var(--line-hover);
  }
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px 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 {
  border-color: 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: 0 0 0 3px rgba(217, 45, 32, 0.14);
}

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

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

.file-input::file-selector-button {
  height: 28px;
  margin-right: 10px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 550;
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .file-input::file-selector-button:hover {
    border-color: var(--line-hover);
    background: var(--surface-tint);
  }
}

.file-input::file-selector-button:focus-visible {
  outline: 2px solid var(--brand);
  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: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

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

.panel-title {
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  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: 14px 20px;
  border-bottom: 1px solid var(--line);
}

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

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

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

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

.page-header h1 {
  overflow-wrap: anywhere;
}

.page-header p {
  max-width: 68ch;
  margin-top: 5px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.5;
  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(170px, 1fr));
  gap: var(--space-3);
  margin-bottom: 22px;
}

.stat-card {
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

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

.stat-label {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  color: var(--muted-light);
}

.stat-value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-sub {
  margin-top: 4px;
  color: var(--muted-light);
  font-size: var(--text-xs);
  line-height: 1.4;
}

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

.empty-icon {
  display: flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-1);
  border-radius: var(--radius);
  background: var(--surface-tint);
  color: var(--muted);
}

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

.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: 20px;
  height: 20px;
}

.page-loader {
  display: flex;
  min-height: 45vh;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: var(--text-sm);
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #eef1f6 25%, #f6f8fb 37%, #eef1f6 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 rgba(47, 107, 255, 0.2);
  border-top-color: var(--brand);
  border-radius: 999px;
  animation: spin 0.7s linear infinite;
}

.spinner-light {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}

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

/* Error panel */
.error-panel {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 14px 16px;
  border: 1px solid #fecdca;
  border-radius: var(--radius);
  background: var(--red-soft);
}

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

.error-panel-title {
  color: #912018;
  font-size: var(--text-sm);
  font-weight: 600;
  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 */
.toast-stack {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  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: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  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-out);
}

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

.toast.error {
  border-color: #fecdca;
  background: var(--red-soft);
  color: var(--red-ink);
}

.toast.success {
  border-color: #abefc6;
  background: var(--green-soft);
  color: var(--green-ink);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
}

.badge-slate {
  background: #f2f4f7;
  color: #475467;
}

.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: #fdf2fa;
  color: #c11574;
}

/* File badge */
.file-badge {
  display: inline-flex;
  width: 34px;
  height: 34px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1;
}

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

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

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

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

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

.file-badge.slate {
  background: #f2f4f7;
  color: #475467;
}

/* Avatar */
.avatar {
  display: inline-flex;
  width: 28px;
  height: 28px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: var(--text-xs);
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0.01em;
}

.avatar-lg {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

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

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

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

.table th {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 550;
  letter-spacing: 0.01em;
  text-align: left;
  white-space: nowrap;
}

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

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

.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) var(--ease-out);
}

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

@media (hover: hover) and (pointer: fine) {
  .table tbody tr:hover {
    background: #fbfcfe;
  }
}

/* Notices */
.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-4);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.notice svg {
  flex: none;
}

.notice-error {
  border-color: #fecdca;
  background: var(--red-soft);
  color: var(--red-ink);
}

.notice-success {
  border-color: #abefc6;
  background: var(--green-soft);
  color: var(--green-ink);
}

.notice-info {
  border-color: #d1e0ff;
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.form-error {
  padding: 8px 10px;
  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: 8px 10px;
  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: 6px;
  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: 9px 11px;
  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: 9px 11px;
  border: 1px solid #d1e0ff;
  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: 14px;
  border: 1px solid #abefc6;
  border-radius: var(--radius-lg);
  background: var(--green-soft);
}

.success-icon {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #fff;
  color: var(--green);
  box-shadow: var(--shadow-xs);
}

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

.success-hero p {
  margin-top: 3px;
  color: #067647;
  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 button */
.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;
}

/* Modal */
.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(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  overscroll-behavior: contain;
  opacity: 1;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  opacity: 1;
  transform: none;
  transform-origin: center;
  transition:
    opacity var(--dur-slow) var(--ease-out),
    transform var(--dur-slow) var(--ease-out);
}

.modal:focus-visible {
  outline: 2px solid var(--brand);
  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: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.modal-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px;
  overflow-wrap: anywhere;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur) var(--ease-out);
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.94);
}

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

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

.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: 34px;
}

.search-box svg {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--muted-light);
  pointer-events: none;
  transform: translateY(-50%);
  transition: color var(--dur-fast) var(--ease-out);
}

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

/* Link display */
.link-url {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.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: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.tag-input:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.tag {
  display: inline-flex;
  height: 26px;
  align-items: center;
  gap: 4px;
  padding: 0 4px 0 8px;
  border-radius: var(--radius-xs);
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: var(--text-xs);
  line-height: 1;
  max-width: 100%;
}

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

.tag button {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: currentColor;
  line-height: 1;
  opacity: 0.65;
  transition:
    opacity var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}

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

@media (hover: hover) and (pointer: fine) {
  .tag button:hover {
    background: rgba(23, 67, 179, 0.08);
    opacity: 1;
  }
}

/* Toggle rows */
.toggle-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 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-sm);
  font-weight: 550;
  line-height: 1.4;
}

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

/* Switch */
.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #d4d9e3;
  transition: background-color var(--dur) var(--ease-out);
}

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

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2), 0 0 0 0.5px rgba(16, 24, 40, 0.06);
  transition: transform var(--dur) var(--ease-out);
}

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

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

.switch.on {
  background: var(--brand);
}

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

@media (hover: hover) and (pointer: fine) {
  .switch:hover:not(.on):not(:disabled) {
    background: #c7ceda;
  }

  .switch.on:hover:not(:disabled) {
    background: var(--brand-dark);
  }
}

/* Tabs and chips */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--surface-tint);
}

.tab {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

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

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

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

.filter-chip {
  display: inline-flex;
  height: 32px;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

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

.filter-chip.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

@media (hover: hover) and (pointer: fine) {
  .filter-chip:hover:not(.active) {
    border-color: var(--line-hover);
    background: var(--surface-soft);
    color: var(--ink);
  }
}

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

.activity-list.bordered {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.activity-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 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: 11px;
  padding: 12px 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) var(--ease-out);
}

.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: 28px;
  height: 28px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-tint);
  color: var(--muted);
}

.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: 600;
}

.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: 2px 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted-light);
  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;
    gap: var(--space-3);
  }

  .page-actions {
    width: 100%;
  }

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

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

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

  .btn {
    height: 40px;
  }

  .btn-sm {
    height: 40px;
  }

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

  .tab {
    height: 40px;
    padding: 0 14px;
  }

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

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

  .modal-backdrop {
    padding: 12px;
  }

  .modal {
    max-height: 92dvh;
  }

  .toast-stack {
    right: 12px;
    bottom: 12px;
    left: 12px;
    max-width: none;
    align-items: stretch;
  }

  .toast {
    min-width: 0;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-backdrop,
  .toast {
    transition: none;
  }

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

  .switch::after {
    transition: none;
  }

  .skeleton {
    animation: none;
    background: #eef1f6;
  }

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