/* ==========================================================================
   layout.css — Panel and grid structure
   ========================================================================== */

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

html {
  font-size: 16px; /* base for rem calculation; type scale uses 20px base via --text-base: 1.25rem equivalent offset */
}

body {
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-regular);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--surface-page);
  min-height: 100vh;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* --------------------------------------------------------------------------
   Navigation bar
   -------------------------------------------------------------------------- */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background-color: var(--surface-nav);
  border-bottom: 1px solid var(--border-default);
  box-shadow: var(--shadow-nav);
}

.nav__logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-brand);
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
}

.nav__logo img {
  display: block;
  width: 9.3125rem;
  height: auto;
}

.nav__logo span {
  padding-left: var(--space-3);
  border-left: 1px solid var(--border-default);
}

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

.nav__gallery-link {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-bold);
  color: var(--text-secondary);
  text-decoration: none;
}

.nav__gallery-link:hover,
.nav__gallery-link:focus-visible {
  color: var(--text-brand);
}

.nav__gallery-link:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */

.app-shell {
  display: flex;
  height: 100vh;
  padding-top: 3.5rem; /* nav height */
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Sidebar — portfolio list
   -------------------------------------------------------------------------- */

.sidebar {
  width: 22rem;
  min-width: 22rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--surface-sidebar);
  border-right: 1px solid var(--border-default);
  overflow: hidden;
}

.sidebar__header {
  flex-shrink: 0;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-default);
}

.sidebar__controls {
  flex-shrink: 0;
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border-default);
}

.sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-4);
}

.sidebar__footer {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-default);
  background-color: var(--surface-sidebar);
}

/* --------------------------------------------------------------------------
   Main content area
   -------------------------------------------------------------------------- */

.main-content {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------------------
   KPI bar
   -------------------------------------------------------------------------- */

.kpi-bar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-default);
}

/* --------------------------------------------------------------------------
   Detail panels
   -------------------------------------------------------------------------- */

.detail-panel {
  padding: var(--space-6) var(--space-8);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.detail-panel__section {
  margin-bottom: var(--space-8);
}

.detail-panel__section-heading {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--border-default);
}

/* --------------------------------------------------------------------------
   Welcome / empty state
   -------------------------------------------------------------------------- */

.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: var(--space-12);
  color: var(--text-secondary);
}

.welcome-state__icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.welcome-state__title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

.welcome-state__body {
  font-size: var(--text-base);
  color: var(--text-secondary);
  max-width: 24rem;
}

/* --------------------------------------------------------------------------
   Loading & error states
   -------------------------------------------------------------------------- */

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.error-state {
  padding: var(--space-4);
  margin: var(--space-4);
  border-radius: var(--radius-md);
  background-color: #FEE2E2;
  color: #991B1B;
  font-size: var(--text-sm);
}

[data-theme="dark"] .error-state {
  background-color: #450A0A;
  color: #FCA5A5;
}

/* --------------------------------------------------------------------------
   Responsive — narrow viewport fallback
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .nav {
    padding: 0 var(--space-4);
  }

  .nav__logo {
    gap: var(--space-2);
  }

  .nav__logo img {
    width: 7.5rem;
  }

  .nav__logo span {
    padding-left: var(--space-2);
  }

  .nav__gallery-link {
    display: none;
  }

  .app-shell {
    flex-direction: column;
    overflow: auto;
  }

  .sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    max-height: 50vh;
  }

  .main-content {
    height: auto;
  }

  .detail-panel {
    padding: var(--space-4) var(--space-5);
  }
}
