/**
 * layout.css
 * Structural layout: app shell, top bar, bottom nav (mobile) / sidebar
 * (desktop), and the screen container that each page renders into.
 */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Top bar ---- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--top-bar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.top-bar__before {
  content: "";
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: var(--safe-top);
  background: var(--color-bg);
  z-index: 21;
}

.top-bar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.top-bar__brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.top-bar__brand-text {
  min-width: 0;
}

.top-bar__brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
}

.top-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* ---- Main content area ---- */
.screen {
  flex: 1;
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--bottom-nav-height) + var(--space-8));
}

@media (min-width: 900px) {
  .screen {
    padding: var(--space-6) var(--space-8) var(--space-10);
  }
}

/* ---- Bottom navigation (mobile) ---- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: var(--safe-bottom);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-2) 0 var(--space-1);
  min-height: 56px;
  color: var(--color-text-muted);
  transition: color var(--duration-fast) var(--ease-standard);
}

.bottom-nav__item[aria-current="page"] {
  color: var(--color-primary-dark);
}

.bottom-nav__label {
  font-size: 11px;
  font-weight: 600;
}

/* ---- Desktop: sidebar layout ---- */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: none;
}

@media (min-width: 900px) {
  .bottom-nav { display: none; }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 232px;
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: var(--space-5) var(--space-3);
    gap: var(--space-1);
  }

  .sidebar__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: var(--text-sm);
    transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
  }

  .sidebar__item:hover {
    background: var(--color-bg);
  }

  .sidebar__item[aria-current="page"] {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
  }

  .screen {
    padding-bottom: var(--space-10);
  }
}

/* ---- Common section/stack utilities ---- */
.stack { display: flex; flex-direction: column; }
.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2) !important; }
.stack-lg > * + * { margin-top: var(--space-6) !important; }

.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.row-gap { gap: var(--space-2); }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.section-heading h2, .section-heading h3 {
  margin: 0;
}

.section-heading__action {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary-dark);
}
