/* ============================================================
   layout.css — the app shell
   Computer: the menu (aside) on the left, the page on the right.
   Phone (900px and below): the menu slides in from the left
   when the ☰ button is pressed.
   ============================================================ */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

/* ---------------- The menu (aside) ---------------- */

.app-aside {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  z-index: 40;
}

.app-aside__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) var(--space-2);
}

.app-aside .app-aside__close {
  display: none;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
}

.app-brand:hover {
  color: var(--color-text);
}

.app-brand__mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--gradient-primary);
  color: var(--color-on-primary);
  font-weight: 800;
  font-size: var(--text-lg);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.app-brand__name {
  font-weight: 800;
  font-size: var(--text-lg);
  letter-spacing: -0.02em;
}

/* the club the user belongs to */
.app-club {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.app-club__logo {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.app-club__logo--empty {
  display: grid;
  place-items: center;
  background: var(--color-surface-3);
  color: var(--color-primary);
  font-weight: 700;
  text-transform: uppercase;
}

.app-club__name {
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* the links */
.app-sidebar {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.app-sidebar__title {
  padding: var(--space-2) var(--space-3);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-faint);
}

.app-sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 42px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.app-sidebar__link .icon {
  flex: none;
  opacity: 0.85;
}

.app-sidebar__link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.app-sidebar__link.is-active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 600;
}

.app-sidebar__link.is-active .icon {
  opacity: 1;
}

/* the user at the bottom of the menu */
.app-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-top: 1px solid var(--color-border);
  margin: 0 calc(var(--space-3) * -1) calc(var(--space-4) * -1);
  padding: var(--space-4);
}

.app-user form {
  margin-left: auto;
}

.app-user__avatar,
.app-navbar__avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text);
  font-weight: 700;
  font-size: var(--text-sm);
}

.app-user__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.app-user__name {
  font-size: var(--text-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user__role {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* a square button with only an icon */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ---------------- The page side ---------------- */

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--navbar-h);
  padding: 0 var(--space-6);
  background: rgba(11, 13, 18, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}

.app-navbar .app-navbar__menu {
  display: none;
}

.app-navbar__brand {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-navbar__brand:hover {
  color: var(--color-text);
}

.app-navbar__spacer {
  flex: 1;
}

.app-navbar__role {
  padding: 3px var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.app-content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-6);
}

.app-backdrop {
  display: none;
}

/* ---------------- Page header ---------------- */

.page-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-title {
  margin: 0;
}

.page-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------------- Simple grids ---------------- */

.grid {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.grid > .card {
  margin-bottom: 0;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ============================================================
   Tablet and phone — 900px and below: the menu becomes a drawer
   ============================================================ */

@media (max-width: 900px) {

  .app-shell {
    display: block;
  }

  .app-aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100%;
    transform: translateX(-105%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow-lg);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }

  .app-aside .app-aside__close {
    display: inline-grid;
  }

  .app-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .nav-open .app-aside {
    transform: none;
  }

  .nav-open .app-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .nav-open {
    overflow: hidden;
  }

  .app-navbar {
    padding: 0 var(--space-3);
    padding-left: max(var(--space-3), env(safe-area-inset-left));
    padding-right: max(var(--space-3), env(safe-area-inset-right));
    height: 56px;
  }

  .app-navbar .app-navbar__menu {
    display: inline-grid;
    color: var(--color-text);
  }

  .app-navbar__brand {
    font-size: var(--text-base);
    color: var(--color-text);
  }

  .app-content {
    padding: var(--space-5) var(--space-4) var(--space-7);
  }

  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
  }

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

@media (max-width: 560px) {

  h1 { font-size: 1.5rem; }

  .app-navbar__role {
    display: none;
  }

  .page-header {
    margin-bottom: var(--space-5);
  }

  /* the buttons of a page go under the title, full width */
  .page-actions {
    margin-left: 0;
    width: 100%;
  }

  .page-actions > .btn,
  .page-actions > form,
  .page-actions > form .btn {
    flex: 1;
  }
}

/* ---------------- Login and error pages ---------------- */

.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-5) var(--space-4);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth-card__title {
  margin-bottom: var(--space-5);
  text-align: center;
}

/* ---------------- Printing ---------------- */

@media print {
  .app-aside,
  .app-navbar,
  .app-backdrop {
    display: none !important;
  }

  .app-shell {
    display: block;
  }
}
