/*
 * SpaceZ shared foundation — canonical runtime source.
 *
 * Product CSS may map local variables to these tokens, but must not redefine
 * the shared foundation. The visual baseline is the current white SpaceZ home.
 */
:root {
  color-scheme: light;
  --sz-background: #fdfdfc;
  --sz-foreground: #111111;
  --sz-surface: #ffffff;
  --sz-surface-raised: #ffffff;
  --sz-surface-muted: #f9f9f9;
  --sz-muted: #64748b;
  --sz-faint: #94a3b8;
  --sz-line: #eef0f2;
  --sz-line-strong: #dfe3e8;
  --sz-accent: #2563eb;
  --sz-active: #3b82f6;
  --sz-danger: #b64b45;
  --sz-danger-soft: #fff0ef;
  --sz-success: #2e7457;
  --sz-success-soft: #edf7f1;
  --sz-warning: #9a5a14;
  --sz-warning-soft: #fff6e8;

  /* Compatibility aliases for product-local styles. */
  --sz-canvas: var(--sz-background);
  --sz-canvas-deep: #f6f7f8;
  --sz-ink: var(--sz-foreground);
  --sz-ink-2: #3f4652;
  --sz-focus: var(--sz-accent);

  --sz-radius-xs: 7px;
  --sz-radius-sm: 10px;
  --sz-radius-md: 14px;
  --sz-radius-lg: 18px;
  --sz-radius-xl: 24px;
  --sz-shadow-soft: 0 1px 3px rgba(15, 23, 42, .045), 0 8px 24px rgba(15, 23, 42, .035);
  --sz-shadow-raised: 0 16px 48px rgba(15, 23, 42, .09);
  --sz-font-ui: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --sz-font-reading: Georgia, "Songti SC", "STSong", serif;
  --sz-motion: cubic-bezier(.2, .72, .2, 1);
  --sz-focus-ring: 0 0 0 3px color-mix(in srgb, var(--sz-focus) 16%, transparent);

  /* Generic aliases consumed by the Astro portal and legacy Hub components. */
  --background: var(--sz-background);
  --foreground: var(--sz-foreground);
  --surface: var(--sz-surface);
  --surface-hover: var(--sz-surface-muted);
  --muted: var(--sz-muted);
  --border: var(--sz-line);
  --accent: var(--sz-accent);
  --active-pulse: var(--sz-active);
  --radius: 1rem;
  --radius-sm: .5rem;
  --shadow-sm: var(--sz-shadow-soft);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, .08);

  /* Secondary Hub/Thinkers identity; not a second foundation. */
  --tk-accent: #b45309;
  --tk-accent-light: #d97706;
  --tk-accent-bg: rgba(180, 83, 9, .08);
  --tk-accent-border: rgba(180, 83, 9, .3);
  --tk-stone-bg: #f5f4f0;
  --tk-stone-border: #e7e5e0;
  --tk-shadow-sm: var(--sz-shadow-soft);
  --tk-shadow-md: var(--shadow-md);
}

html { min-width: 320px; font-synthesis: none; text-rendering: optimizeLegibility; }
body, button, input, textarea, select { font-family: var(--sz-font-ui); }
::selection { color: var(--sz-foreground); background: color-mix(in srgb, var(--sz-accent) 18%, transparent); }

:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
  outline: 2px solid color-mix(in srgb, var(--sz-focus) 58%, transparent);
  outline-offset: 2px;
}

/* Shared interaction grammar. App layouts remain product-owned. */
.sz-app-identity {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--sz-foreground);
  text-decoration: none;
}
.sz-app-identity > img {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: var(--sz-radius-sm);
}
.sz-app-identity > span { min-width: 0; display: grid; gap: 2px; }
.sz-app-identity strong { font-size: 14px; line-height: 1.2; letter-spacing: -.015em; }
.sz-app-identity small { overflow: hidden; color: var(--sz-muted); font-size: 11px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }

.sz-icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--sz-line);
  border-radius: var(--sz-radius-sm);
  color: var(--sz-muted);
  background: var(--sz-surface);
}
.sz-icon-button:hover { color: var(--sz-foreground); background: var(--sz-surface-muted); }
.sz-icon-button > svg { width: 18px; height: 18px; }

.sz-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 36px 24px;
  border: 1px dashed var(--sz-line-strong);
  border-radius: var(--sz-radius-md);
  color: var(--sz-muted);
  background: var(--sz-surface-muted);
  text-align: center;
}
.sz-state strong { color: var(--sz-foreground); font-size: 14px; }
.sz-state p { max-width: 44ch; margin: 0; font-size: 13px; line-height: 1.6; }
.sz-state[data-tone="error"] { border-style: solid; border-color: color-mix(in srgb, var(--sz-danger) 24%, var(--sz-line)); background: var(--sz-danger-soft); }
.sz-state[data-tone="success"] { border-style: solid; border-color: color-mix(in srgb, var(--sz-success) 24%, var(--sz-line)); background: var(--sz-success-soft); }

.sz-status {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--sz-muted);
  background: var(--sz-surface-muted);
  font-size: 11px;
  font-weight: 700;
}
.sz-status::before { content: ""; width: 7px; height: 7px; flex: 0 0 auto; border-radius: 3px; background: currentColor; }
.sz-status[data-tone="success"] { color: var(--sz-success); background: var(--sz-success-soft); }
.sz-status[data-tone="warning"] { color: var(--sz-warning); background: var(--sz-warning-soft); }
.sz-status[data-tone="danger"] { color: var(--sz-danger); background: var(--sz-danger-soft); }

.sz-context {
  min-height: 27px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--sz-line);
  border-radius: 999px;
  color: var(--sz-muted);
  background: color-mix(in srgb, var(--sz-surface) 82%, transparent);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.sz-context > span {
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--sz-active);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sz-active) 12%, transparent);
}

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

@media (max-width: 720px) {
  :root { --sz-radius-xl: 20px; --sz-radius-lg: 16px; }
  button, a, input, select { touch-action: manipulation; }
  .sz-icon-button { width: 44px; height: 44px; }
  .sz-context { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
