/* === Reset === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-size: clamp(14px, 0.875rem + 0.2vw, 18px);
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

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

/* === Color Tokens (OKLCH) === */
:root {
  --color-primary: oklch(0.55 0.2 260);
  --color-secondary: oklch(0.6 0.15 290);
  --color-accent: oklch(0.7 0.15 175);

  --color-surface-0: oklch(0.99 0.005 260 / 0.6);
  --color-surface-1: oklch(0.96 0.005 260 / 0.7);
  --color-surface-2: oklch(0.93 0.005 260 / 0.8);
  --color-surface-3: oklch(0.90 0.005 260 / 0.9);

  --color-text: oklch(0.15 0.01 260);
  --color-text-muted: oklch(0.45 0.02 260);
  --color-border: oklch(0.85 0.01 260 / 0.3);

  --color-error: oklch(0.55 0.2 25);
  --color-warning: oklch(0.7 0.15 85);
  --color-success: oklch(0.6 0.18 145);
  --color-info: oklch(0.6 0.15 240);

  /* Spacing — 4px base grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Motion */
  --transition-fast: 150ms ease-out;

  /* Breakpoints (reference only — CSS cannot use custom props in media queries)
     --bp-sm: 640px;
     --bp-md: 768px;
     --bp-lg: 1024px;
     --bp-xl: 1440px;
     --bp-2xl: 2560px;
     --bp-4k: 3840px;
  */
}

/* === Dark Mode === */
.dark {
  --color-surface-0: oklch(0.15 0.01 260 / 0.6);
  --color-surface-1: oklch(0.18 0.01 260 / 0.7);
  --color-surface-2: oklch(0.22 0.01 260 / 0.8);
  --color-surface-3: oklch(0.26 0.01 260 / 0.9);

  --color-text: oklch(0.93 0.005 260);
  --color-text-muted: oklch(0.65 0.02 260);
  --color-border: oklch(0.3 0.01 260 / 0.4);
}

@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --color-surface-0: oklch(0.15 0.01 260 / 0.6);
    --color-surface-1: oklch(0.18 0.01 260 / 0.7);
    --color-surface-2: oklch(0.22 0.01 260 / 0.8);
    --color-surface-3: oklch(0.26 0.01 260 / 0.9);

    --color-text: oklch(0.93 0.005 260);
    --color-text-muted: oklch(0.65 0.02 260);
    --color-border: oklch(0.3 0.01 260 / 0.4);
  }
}

/* === Typography === */
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  background-color: var(--color-surface-0);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Major Third scale (1.250) */
h1 { font-size: 3.052rem; }
h2 { font-size: 2.441rem; }
h3 { font-size: 1.953rem; }
h4 { font-size: 1.563rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }

h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  font-weight: 600;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* === Focus === */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* === Search Bar === */
.search-bar {
  position: relative;
  width: 100%;
  max-width: 400px;
}

.search-bar__input {
  padding-right: 32px;
}

.search-bar__spinner {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

@keyframes spin {
  to { transform: translateY(-50%) rotate(360deg); }
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 60;
  max-height: 320px;
  overflow-y: auto;
  padding: var(--space-2);
}

.search-results__empty {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-muted);
  text-align: center;
}

.search-results__list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.search-results__link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  text-decoration: none;
  color: var(--color-text);
  transition: background var(--transition-fast);
}

.search-results__link:hover {
  background: var(--color-surface-3);
}

.search-results__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-results__date {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Search badge variants */
.badge-doc { color: var(--color-primary); }
.badge-sheet { color: var(--color-success); }
.badge-slides { color: var(--color-warning); }

/* === Breadcrumb === */
.breadcrumb {
  padding: var(--space-2) 0;
}

.breadcrumb__list {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.875rem;
}

.breadcrumb__item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.breadcrumb__item a {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.breadcrumb__item a:hover {
  color: var(--color-primary);
}

.breadcrumb__current span[aria-current] {
  color: var(--color-text);
  font-weight: 500;
}

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

/* === 404 Not Found === */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8) var(--space-5);
  max-width: 480px;
  margin: var(--space-8) auto;
}

.not-found__code {
  font-size: 5rem;
  font-weight: 700;
  color: var(--color-text-muted);
  line-height: 1;
  margin-bottom: var(--space-3);
}

.not-found__title {
  font-size: 1.563rem;
  margin-bottom: var(--space-3);
}

.not-found__message {
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.not-found__actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
}

/* === Document Not Found === */
.document-not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-7) var(--space-5);
  max-width: 480px;
  margin: var(--space-7) auto;
}

.document-not-found__icon {
  font-size: 3rem;
  width: 80px;
  height: 80px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
  color: var(--color-text-muted);
}

.document-not-found__message {
  color: var(--color-text-muted);
  margin: var(--space-3) 0 var(--space-5);
}

.document-not-found__message code {
  background: var(--color-surface-1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.875rem;
}

.document-not-found__actions {
  display: flex;
  gap: var(--space-3);
}

/* === Theme Toggle === */
.theme-toggle {
  padding: 6px 10px;
  min-width: unset;
}

.theme-toggle__icon {
  font-size: 1.1rem;
}

/* === Topbar Layout Updates === */
.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 var(--space-4);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* === Error Boundary === */
.error-boundary {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-7) var(--space-5);
  max-width: 560px;
  margin: var(--space-7) auto;
}

.error-details {
  margin: var(--space-3) 0 var(--space-5);
}

.error-message {
  color: var(--color-error);
  font-size: 0.875rem;
}
