/* ============================================================================
   M Line Books — Reset & App Shell Layout
   Mobile-first: bottom nav + single column. Desktop: sidebar + wide content.
   ============================================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; overscroll-behavior-y: contain; }

h1, h2, h3, h4, p, ul, ol { margin: 0; }

img { max-width: 100%; display: block; }

button { font-family: inherit; }

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

input, select, textarea {
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ----------------------------------------------------------------------------
   App shell
   ---------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* js/router.js toggles the native `hidden` attribute on #app vs #auth-root to
   switch between the persistent app shell and the standalone login screen.
   The ID selector above (#app { display: flex }) otherwise outranks the
   browser's default `[hidden] { display: none }` UA rule, which would leave
   #app visibly rendered even while "hidden" — these explicit overrides fix
   that so hidden actually hides. */
#app[hidden],
#auth-root[hidden] {
  display: none;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: var(--text-base);
  white-space: nowrap;
}

.app-header__spacer { flex: 1; }

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: var(--space-4);
  padding-bottom: calc(var(--nav-height-mobile) + var(--space-6));
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* ----------------------------------------------------------------------------
   Sidebar (desktop) — hidden on mobile
   ---------------------------------------------------------------------------- */
.app-sidebar {
  display: none;
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-3);
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-link {
  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-size: var(--text-sm);
  font-weight: 600;
}

.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-link:hover { background: var(--color-surface-2); color: var(--color-text); }

.sidebar-link.is-active {
  background: var(--company-color-soft);
  color: var(--company-color);
}

.sidebar-section-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  padding: var(--space-4) var(--space-3) var(--space-1);
}

/* ----------------------------------------------------------------------------
   Bottom nav (mobile) — hidden on desktop
   ---------------------------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  height: var(--nav-height-mobile);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-text-faint);
  font-size: var(--text-xs);
  font-weight: 600;
  min-height: 44px;
}

.bottom-nav__item svg { width: 21px; height: 21px; }

.bottom-nav__item.is-active { color: var(--company-color); }

/* ----------------------------------------------------------------------------
   Responsive breakpoints
   ---------------------------------------------------------------------------- */
@media (min-width: 900px) {
  .app-sidebar { display: block; }
  .bottom-nav { display: none; }
  .app-main { padding: var(--space-8); padding-bottom: var(--space-8); max-width: 1280px; }
}

@media (max-width: 899.98px) {
  .desktop-only { display: none !important; }
}

@media (min-width: 900px) {
  .mobile-only { display: none !important; }
}

/* ----------------------------------------------------------------------------
   Utility layout classes
   ---------------------------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-wrap { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grid-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}
@media (min-width: 640px) {
  .grid-cards { grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
}

.split-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
@media (min-width: 900px) {
  .split-layout { flex-direction: row; align-items: flex-start; }
  .split-layout__image { width: 44%; position: sticky; top: calc(var(--header-height) + var(--space-4)); }
  .split-layout__form { flex: 1; min-width: 0; }
}
