/* ─────────────────────────────────────────────────────────────── */
/* Nestra — layout.css: Body Flex, Nav Fixed, Main Responsive       */
/* ─────────────────────────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────── */
/* Sidebar Width Tokens                                             */
/* ─────────────────────────────────────────────────────────────── */

:root {
  --sidebar-width: 240px;
  --sidebar-width-collapsed: 64px;
}

/* Collapsed state — desktop only, driven by js/sidebar.js         */
@media (min-width: 768px) {
  body.sidebar-collapsed {
    --sidebar-width: var(--sidebar-width-collapsed);
  }

  body.sidebar-collapsed .navbar-brand {
    display: none;
  }

  body.sidebar-collapsed .nav-label {
    display: none;
  }

  body.sidebar-collapsed .user-info {
    display: none;
  }

  body.sidebar-collapsed .user-chip {
    justify-content: center;
    padding: var(--space-sm) 0;
  }

  body.sidebar-collapsed nav a {
    justify-content: center;
    padding: var(--space-md) var(--space-sm);
  }
}

/* ─────────────────────────────────────────────────────────────── */
/* Body Layout — Flex Container */
/* ─────────────────────────────────────────────────────────────── */

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

/* ─────────────────────────────────────────────────────────────── */
/* Main Content — Mobile First */
/* ─────────────────────────────────────────────────────────────── */

main {
  flex: 1;
  overflow-y: auto;
  margin-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

/* ─────────────────────────────────────────────────────────────── */
/* Navigation — Mobile First (Fixed Bottom) */
/* ─────────────────────────────────────────────────────────────── */

nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  background-color: var(--bg-light);
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: row;
  align-items: flex-start;      /* links align to top 60px; safe-area below is padding */
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  z-index: 100;
  box-shadow: var(--shadow-md);
}

/* .navbar-logo display:block must come BEFORE brand-logo hide rules so the
   hide rules (same specificity, later in file) win the cascade */
.navbar-logo {
  display: block;
  height: auto;
}

/* Theme-aware brand logo */
.brand-logo--dark {
  display: none;
}

html.dark .brand-logo--light {
  display: none;
}

html.dark .brand-logo--dark {
  display: block;
}

html.light .brand-logo--light {
  display: block;
}

html.light .brand-logo--dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  html:not(.light) .brand-logo--light {
    display: none;
  }

  html:not(.light) .brand-logo--dark {
    display: block;
  }
}

/* Brand — hidden on mobile bottom bar (no vertical room) */
.navbar-container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  align-items: center;
}

.navbar-brand {
  display: none;
}

/* Nav Links Container — Mobile Flex Row (scrollable) */
nav ul {
  display: flex;
  flex-direction: row;
  list-style: none;
  width: 100%;
  height: 100%;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* IE/Edge */
  -webkit-overflow-scrolling: touch;
}

nav ul::-webkit-scrollbar {
  display: none;                /* Chrome/Safari */
}

nav li {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  justify-content: center;
  min-width: 52px;              /* compact when label hidden */
}

nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 60px;
  width: auto;
  min-width: 52px;
  padding: 0 10px;
  position: relative;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: color 0.18s ease;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: width 0.18s ease, height 0.18s ease;
}

/* Labels hidden by default — only active item shows label */
.nav-label {
  font-size: 10px;
  letter-spacing: 0.04em;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.18s ease, max-height 0.18s ease;
}

nav a:hover {
  color: var(--color-primary);
  text-decoration: none;
}

nav a.active {
  color: var(--color-primary);
}

/* Refined pill indicator — small centered capsule at top edge */
nav a.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 3px;
  background: var(--color-primary);
  border-radius: 0 0 4px 4px;
}

/* Active: show label + enlarge icon */
nav a.active .nav-label {
  opacity: 1;
  max-height: 14px;
}

nav a.active .nav-icon {
  width: 22px;
  height: 22px;
}

/* ─────────────────────────────────────────────────────────────── */
/* Desktop Breakpoint — 768px+ */
/* ─────────────────────────────────────────────────────────────── */

@media (min-width: 768px) {
  /* Body — Desktop Flex Row */
  body {
    flex-direction: row;
  }

  /* Navigation — Fixed Left Sidebar */
  nav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    right: auto;
    width: var(--sidebar-width);
    transition: width 0.2s ease;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    border-top: none;
    border-right: 1px solid var(--border-light);
    flex-direction: column;
    padding: var(--space-lg) var(--space-md);
    align-items: flex-start;
    justify-content: flex-start;
    box-shadow: none;
  }

  /* Container — Desktop Flex Column (brand on top, links below) */
  .navbar-container {
    flex-direction: column;
    align-items: stretch;
  }

  .navbar-brand {
    display: block;
    padding: 0 var(--space-md) var(--space-lg);
  }

  .navbar-logo {
    width: 100%;
    max-width: 150px;
  }

  /* Nav Links Container — Desktop Flex Column */
  nav ul {
    flex-direction: column;
    width: 100%;
    height: auto;
    gap: 0;
    overflow-x: unset;
    overflow-y: unset;
  }

  nav li {
    width: 100%;
    justify-content: flex-start;
  }

  nav a {
    flex-direction: row;    /* sidebar: icon + label in a row */
    gap: var(--space-sm);
    width: 100%;
    height: auto;
    padding: var(--space-md);
    font-size: var(--font-size-base);
    border-bottom: none;
    border-left: none;
    border-radius: var(--radius-md);
    transition: background 0.2s, color 0.2s;
  }

  /* Desktop sidebar — always show labels, reset mobile hidden state */
  .nav-label {
    font-size: var(--font-size-base);
    opacity: 1;
    max-height: none;
    overflow: visible;
    letter-spacing: normal;
    white-space: normal;
  }

  /* Remove mobile pill indicator on desktop */
  nav a.active::before {
    display: none;
  }

  nav a.active .nav-icon {
    width: 20px;
    height: 20px;
  }

  nav a:hover {
    color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
    text-decoration: none;
  }

  nav a.active {
    color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 12%, transparent);
    border-top: none;
    border-left: none;
    border-bottom: none;
  }

  /* Main Content — Desktop Layout */
  main {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-bottom: 0;
    transition: margin-left 0.2s ease;
  }
}

/* ─────────────────────────────────────────────────────────────── */
/* No-Chrome — Public Views (login/register) Hide Nav */
/* ─────────────────────────────────────────────────────────────── */

body.no-chrome nav {
  display: none;
}

body.no-chrome main {
  margin: 0;
}

/* ─────────────────────────────────────────────────────────────── */
/* Grid Utility — 2-Column Layout */
/* ─────────────────────────────────────────────────────────────── */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* ─────────────────────────────────────────────────────────────── */
/* Sections & Content Containers */
/* ─────────────────────────────────────────────────────────────── */

section {
  padding: var(--space-xl) var(--space-md);
}

.section-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md);
}

/* ─────────────────────────────────────────────────────────────── */
/* Card Layout */
/* ─────────────────────────────────────────────────────────────── */

.card {
  background-color: var(--bg-light-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: box-shadow 0.2s, transform 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* ─────────────────────────────────────────────────────────────── */
/* Scrollbar Styling */
/* ─────────────────────────────────────────────────────────────── */

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

/* Chrome, Safari, Edge */
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--radius-md);
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ─────────────────────────────────────────────────────────────── */
/* Sidebar Toggle Button — Desktop Only                             */
/* ─────────────────────────────────────────────────────────────── */

.sidebar-toggle {
  display: none; /* hidden on mobile */
}

@media (min-width: 768px) {
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    transition: color 0.2s, background 0.2s;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: var(--space-sm);
  }

  .sidebar-toggle:hover {
    color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  }

  .sidebar-toggle .nav-icon {
    pointer-events: none;
  }
}

/* Reduced motion — disable sidebar transitions */
@media (prefers-reduced-motion: reduce) {
  nav,
  main {
    transition: none;
  }
}
