/* CatalogLens dashboard stylesheet.
   Consumes tokens.css variables only. Zero hardcoded colors.
   Desktop Spacious density. Sidebar-main grid layout per AD-5.
   Responsive collapse at 900px. */

/* ============================================================
   Reset
   ============================================================ */

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: rgb(var(--c-bg));
  color: rgb(var(--c-fg));
  font-family: var(--font-serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
}

p {
  margin: 0;
  line-height: 1.55;
}

a {
  color: rgb(var(--c-accent));
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ============================================================
   Shell: sidebar + main grid
   ============================================================ */

.shell {
  display: grid;
  grid-template-columns: 224px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  width: 224px;
  background: rgb(var(--c-surface));
  border-right: var(--border-w) solid rgb(var(--c-border));
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

/* Body section: wordmark + nav */
.sidebar__body {
  flex: 1 1 auto;
  padding: 28px 20px var(--d-gap-section);
  display: flex;
  flex-direction: column;
  gap: var(--d-gap-section);
}

/* Wordmark block */
.wordmark {
  display: block;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  color: rgb(var(--c-fg));
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.wordmark-sub {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgb(var(--c-faint));
  letter-spacing: 0.03em;
  margin-top: 4px;
}

/* Sidebar navigation */
.sidenav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidenav__link {
  display: block;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 400;
  color: rgb(var(--c-muted));
  text-decoration: none;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  transition: color 0.1s ease, background 0.1s ease;
  line-height: 1.3;
}

.sidenav__link:hover {
  color: rgb(var(--c-fg));
  background: rgb(var(--c-surface-2));
  text-decoration: none;
}

/* Active link: near-ink accent left rule + bold weight */
.sidenav__link.is-active {
  color: rgb(var(--c-fg));
  font-weight: 600;
  background: rgb(var(--c-surface-2));
  box-shadow: inset 2px 0 0 rgb(var(--c-accent));
}

/* Sidebar meta footer: scrape date + item count, mono small */
.sidebar__meta {
  flex-shrink: 0;
  padding: 14px 20px;
  border-top: var(--border-w) solid rgb(var(--c-border));
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar__meta-line {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgb(var(--c-faint));
  line-height: 1.5;
}

/* ============================================================
   Main region
   ============================================================ */

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  min-width: 0;
}

/* ============================================================
   Top bar
   ============================================================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 var(--d-content);
  background: rgb(var(--c-bg));
  border-bottom: var(--border-w) solid rgb(var(--c-border));
}

.topbar__title {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgb(var(--c-muted));
}

/* ============================================================
   Content area
   ============================================================ */

.content {
  flex: 1 1 auto;
  padding: var(--d-content);
  display: flex;
  flex-direction: column;
  gap: var(--d-gap-section);
  max-width: 1200px;
}

/* ============================================================
   Section
   ============================================================ */

.section {
  display: flex;
  flex-direction: column;
  gap: var(--d-gap-tiles);
}

/* Extra breathing room for placeholder sections below overview */
.section--spaced {
  padding-top: var(--d-gap-section);
  border-top: var(--border-w) solid rgb(var(--c-border));
}

.section__heading {
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgb(var(--c-faint));
  margin: 0;
}

/* ============================================================
   Stat tiles (Card/Stat spec from DESIGN_PORTABLE)
   muted small-caps label, big mono number, optional sub-label
   ============================================================ */

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--d-gap-tiles);
}

.tile {
  background: rgb(var(--c-surface));
  border: var(--border-w) solid rgb(var(--c-border));
  border-radius: var(--radius);
  padding: var(--d-card-y) var(--d-content);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* Muted small-caps label */
.tile__label {
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgb(var(--c-muted));
  line-height: 1.3;
}

/* Big mono number, ink-weight */
.tile__value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 600;
  color: rgb(var(--c-fg));
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  /* Reserve vertical space while loading, preventing layout jump */
  min-height: 1.15em;
}

/* Skeleton state while data is in flight.
   Reserves the same bounding box, hides text with transparent color. */
.tile__value[data-loading] {
  background: rgb(var(--c-surface-2));
  border-radius: var(--radius-sm);
  color: transparent;
  min-width: 120px;
  display: inline-block;
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}

/* Optional status tint on in-stock tile: subtle ok color on the number */
.tile__value--ok {
  color: rgb(var(--c-ok));
}

/* Remove tint while loading so skeleton is neutral */
.tile__value--ok[data-loading] {
  color: transparent;
}

/* Optional sub-label below the number */
.tile__sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgb(var(--c-faint));
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

/* ============================================================
   Skeleton pulse animation (functional only, rule 3)
   ============================================================ */

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .tile__value[data-loading] {
    animation: none;
  }
}

/* ============================================================
   EmptyState pattern (placeholder sections)
   ============================================================ */

.empty-state {
  padding: var(--d-card-y) var(--d-content);
  background: rgb(var(--c-surface));
  border: var(--border-w) solid rgb(var(--c-border));
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 80px;
  justify-content: center;
}

.empty-state__text {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 500;
  color: rgb(var(--c-muted));
}

.empty-state__sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgb(var(--c-faint));
}

/* ============================================================
   Site footer: AD-9 honesty line
   ============================================================ */

.site-footer {
  padding: var(--d-gap-tiles) var(--d-content);
  border-top: var(--border-w) solid rgb(var(--c-border));
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.site-footer__line {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgb(var(--c-faint));
  line-height: 1.5;
}

.site-footer__line--sub {
  color: rgb(var(--c-faint));
  opacity: 0.7;
}

/* ============================================================
   Responsive: collapse sidebar to top strip under 900px
   ============================================================ */

@media (max-width: 899px) {

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  /* Sidebar becomes a top strip */
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: var(--border-w) solid rgb(var(--c-border));
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .sidebar__body {
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    gap: var(--d-content);
    flex: 1 1 auto;
  }

  .wordmark-sub {
    display: none;
  }

  .sidenav {
    flex-direction: row;
    gap: 4px;
    flex-shrink: 0;
  }

  .sidenav__link {
    font-size: 13px;
    padding: 5px 10px;
    white-space: nowrap;
  }

  .sidenav__link.is-active {
    box-shadow: none;
    border-bottom: 2px solid rgb(var(--c-accent));
    border-radius: 0;
    background: transparent;
  }

  .sidebar__meta {
    display: none;
  }

  /* Content: reduce desktop padding */
  .content {
    padding: 20px 16px;
  }

  /* Tiles: 2 columns on narrow screens */
  .tiles {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Tile number slightly smaller */
  .tile__value {
    font-size: 26px;
  }

  /* Topbar: reduce padding */
  .topbar {
    padding: 0 16px;
  }

}

/* Very narrow (390px): single column tiles */
@media (max-width: 479px) {

  .tiles {
    grid-template-columns: 1fr 1fr;
  }

  .tile {
    padding: 14px 16px;
  }

  .tile__value {
    font-size: 24px;
  }

}
