/* =============================================================================
   layout.css — Mobile-first layout primitives
   -----------------------------------------------------------------------------
   Containers, the sticky app header/nav, page stacks, a responsive grid system
   and the centered auth layout. Mobile-first: base rules target small screens
   (<=600px, single column); a single media query at min-width:601px switches to
   the multi-column desktop layout.

   Uses ONLY tokens from tokens.css. Loaded after base.css.
   ============================================================================= */

/* -----------------------------------------------------------------------------
   App container — centers content and caps width
   --------------------------------------------------------------------------- */
.app-container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

/* -----------------------------------------------------------------------------
   App header / top nav bar
   - Sticky to the top, surface background, hairline bottom border.
   - Flex row: brand on the left, nav/actions on the right.
   - On mobile it wraps gracefully and stays compact.
   --------------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.app-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  min-height: var(--header-height);
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-block: var(--space-2);
  padding-inline: var(--space-4);
}

/* Brand / logo lockup */
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  white-space: nowrap;
}

.app-brand:hover {
  color: var(--color-text);
  text-decoration: none;
}

.app-brand__mark {
  font-size: 1.4em;
  line-height: 1;
}

/* Right-hand navigation / actions cluster */
.app-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.app-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding-inline: var(--space-3);
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
}

.app-nav__link:hover,
.app-nav__link.is-active {
  color: var(--color-primary);
  background-color: var(--color-primary-soft);
  text-decoration: none;
}

/* -----------------------------------------------------------------------------
   Page — main content wrapper, vertical stack with comfortable gaps
   --------------------------------------------------------------------------- */
.page {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
  padding-block: var(--space-5) var(--space-8);
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.page-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
}

/* -----------------------------------------------------------------------------
   Responsive grid system
   - Single column by default (mobile).
   - Multi-column at >=601px.
   - .grid-2 / .grid-3 control desktop column counts.
   - .grid-auto fills with responsive auto-fit cards.
   --------------------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.grid-2,
.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

/* Auto-fit grid for card collections (e.g., cars list) */
.grid-auto {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

/* -----------------------------------------------------------------------------
   Auth layout — centered card for login / register
   --------------------------------------------------------------------------- */
.auth-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-4);
  background-color: var(--color-bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

/* ---------------------------------------------------------------------------
   Auth split layout — SEO hero alongside the auth card (login / register)
   --------------------------------------------------------------------------- */
.auth-layout--split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: var(--space-8);
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
}

.auth-layout--split .auth-card {
  max-width: 460px;
  justify-self: stretch;
}

.auth-hero {
  max-width: 560px;
}

.auth-hero__brand {
  margin-bottom: var(--space-4);
}

.auth-hero__title {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  line-height: 1.2;
  margin: 0 0 var(--space-3);
  color: var(--color-text);
}

.auth-hero__lead {
  font-size: var(--text-lg);
  line-height: 1.6;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-6);
}

.auth-hero__subtitle {
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-4);
}

.auth-hero__features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.auth-hero__features h3 {
  font-size: var(--text-base);
  margin: 0 0 var(--space-1);
  color: var(--color-text);
}

.auth-hero__features p {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text-muted);
  margin: 0;
}

/* On narrow screens: single column, form first, hero below. */
@media (max-width: 860px) {
  .auth-layout--split {
    grid-template-columns: 1fr;
    gap: var(--space-6);
    justify-items: center;
  }
  .auth-layout--split .auth-card {
    order: -1;
    max-width: 420px;
  }
  .auth-hero {
    text-align: center;
  }
  .auth-hero__features {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .auth-hero__features {
    grid-template-columns: 1fr;
  }
}

.auth-card__header {
  text-align: center;
  margin-bottom: var(--space-5);
}

.auth-card__title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
}

.auth-card__subtitle {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.auth-card__footer {
  margin-top: var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* =============================================================================
   Desktop layout — single breakpoint per design (>=601px multi-column)
   ============================================================================= */
@media (min-width: 601px) {
  .app-container,
  .app-header__inner,
  .page {
    padding-inline: var(--space-5);
  }

  .page {
    padding-block: var(--space-6) var(--space-8);
  }

  /* Two- and three-column grids activate on desktop */
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Auto-fit cards: as many ~280px columns as fit */
  .grid-auto {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }

  /* Dashboard layout: main column + narrower side column */
  .dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-5);
    align-items: start;
  }
}
