/* PortKnot design tokens + shared primitives. */

:root {
  color-scheme: light;

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --ink: #0f172a;
  --text: #334155;
  --muted: #475569;
  --subtle: #64748b;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-300: #a5b4fc;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-900: #312e81;

  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success: #047857;
  --success-bright: #10b981;

  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning: #b45309;

  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger: #b91c1c;

  --sidebar: #0b1120;
  --sidebar-raised: #111a2e;
  --sidebar-border: rgba(148, 163, 184, 0.14);
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #7c8ba1;

  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 20px -12px rgba(15, 23, 42, 0.12);
  --shadow-md: 0 2px 4px rgba(15, 23, 42, 0.04), 0 18px 40px -24px rgba(15, 23, 42, 0.22);
  --shadow-lg: 0 30px 70px -30px rgba(15, 23, 42, 0.3);
  --focus-ring: 0 0 0 4px rgba(79, 70, 229, 0.16);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

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

h1,
h2,
h3,
h4 {
  color: var(--ink);
  letter-spacing: -0.025em;
  font-weight: 600;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

svg {
  display: block;
  flex: none;
}

::selection {
  background: var(--brand-200);
  color: var(--brand-900);
}

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

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 600;
  transition: top 160ms ease;
}

.skip-link:focus {
  top: 16px;
}

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex: none;
}

.brand-name {
  font-size: 17px;
}

.brand-name span {
  color: var(--brand-600);
}

.brand--on-dark {
  color: #fff;
}

.brand--on-dark .brand-name span {
  color: var(--brand-300);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease,
    box-shadow 160ms ease, transform 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

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

.btn-primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
  box-shadow: 0 8px 20px -10px rgba(79, 70, 229, 0.55);
}

.btn-primary:hover {
  background: var(--brand-700);
  border-color: var(--brand-700);
}

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

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}

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

.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.12);
  color: var(--ink);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
  border-radius: var(--radius-xs);
}

.btn-lg {
  min-height: 48px;
  padding: 12px 20px;
  font-size: 15px;
}

.btn .btn-arrow {
  transition: transform 160ms ease;
}

.btn:hover .btn-arrow {
  transform: translateX(2px);
}

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

.field + .field {
  margin-top: 16px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.label-optional {
  color: var(--faint);
  font-weight: 500;
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.02);
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

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

.input:hover {
  border-color: var(--border-strong);
}

.input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--focus-ring);
}

.input[aria-invalid='true'] {
  border-color: #fca5a5;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
}

.field-hint {
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.5;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.password-control {
  position: relative;
}

.password-control .input {
  padding-right: 64px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  min-height: 34px;
  padding: 6px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 600;
}

.password-toggle:hover {
  background: var(--bg);
  color: var(--ink);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-actions {
  margin-top: 4px;
}

/* Alerts */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.alert svg {
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

.alert--error {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.alert--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.alert--warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}

.alert--info {
  background: var(--brand-50);
  border-color: var(--brand-100);
  color: var(--brand-700);
}

.alert + .form-stack,
.form-stack + .alert {
  margin-top: 16px;
}

/* Pills / badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--subtle);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.pill--brand {
  border-color: var(--brand-100);
  background: var(--brand-50);
  color: var(--brand-700);
}

.pill--success {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success);
}

.pill--neutral {
  background: var(--bg);
}

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

.dot--success {
  background: var(--success-bright);
}

.dot--warning {
  background: #f59e0b;
}

.dot--brand {
  background: var(--brand-600);
}

/* Small utilities */
.eyebrow {
  color: var(--brand-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.text-link {
  color: var(--brand-600);
  font-weight: 600;
  text-decoration: none;
}

.text-link:hover {
  color: var(--brand-700);
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.mono {
  font-family: var(--font-mono);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  border-color: var(--danger-border);
  color: var(--danger);
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
