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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

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

h1 {
  font-size: var(--font-size-xxl);
  font-weight: 700;
}

h2 {
  font-size: var(--font-size-xl);
  font-weight: 700;
}

h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

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

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* App shell: fixed left sidebar + independently-scrolling main area */
.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  height: 100vh;
  z-index: var(--z-sidebar);
  transition: width 0.18s ease;
}

.sidebar.collapsed {
  width: 64px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4) var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-2);
}

.sidebar.collapsed .sidebar-header {
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  justify-content: center;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 700;
  font-size: var(--font-size-md);
  min-width: 0;
}

.sidebar-brand .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  display: block;
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.sidebar-collapse-btn svg {
  width: 14px;
  height: 14px;
}

.sidebar.collapsed .sidebar-collapse-btn {
  display: none;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav-bottom {
  flex: 0 0 auto;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
  margin-top: 0;
  overflow: visible;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-md);
  border-left: 3px solid transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: 600;
  white-space: nowrap;
  min-width: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

a.nav-item:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.nav-item.active {
  background: var(--color-primary-light);
  border-left-color: var(--color-primary);
  color: var(--color-primary-dark);
}

.nav-item.disabled {
  color: var(--color-text-faint);
  cursor: default;
  justify-content: space-between;
}

.nav-item.disabled .nav-item-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.nav-item .soon-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--color-surface-alt);
  color: var(--color-text-faint);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

/* Collapsed sidebar: icons only */
.sidebar.collapsed .sidebar-brand span:not(.brand-mark),
.sidebar.collapsed .nav-label,
.sidebar.collapsed .soon-tag,
.sidebar.collapsed .sidebar-profile .profile-text {
  display: none;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
}

.sidebar.collapsed .nav-item.disabled {
  justify-content: center;
}

/* User profile tab, pinned to the bottom of the sidebar */
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.sidebar.collapsed .sidebar-profile {
  padding: var(--space-4) 0;
  justify-content: center;
}

.sidebar-profile:hover {
  background: var(--color-surface-alt);
}

.sidebar-profile .profile-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--color-primary-light);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: var(--font-size-xs);
}

.sidebar-profile .profile-text {
  min-width: 0;
}

.sidebar-profile .profile-name {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-profile .profile-role {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

.main-area {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.app-footer:empty {
  display: none;
}

.app-footer {
  flex-shrink: 0;
  min-height: 36px;
  padding: var(--space-2) var(--space-6);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

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

/* Mobile top bar (hamburger + brand) + off-canvas sidebar drawer.
   Hidden on desktop; see the max-width:640px block below for the switch. */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  background: var(--color-bg-sidebar);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  padding: 0;
}

.mobile-topbar-title {
  font-weight: 700;
  font-size: var(--font-size-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 34, 0.4);
  z-index: var(--z-drawer-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-mobile-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0;
}

@media (max-width: 640px) {
  .mobile-topbar,
  .sidebar-backdrop {
    display: flex;
  }

  .app-shell {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .main-area {
    height: auto;
    overflow-y: visible;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(82vw, 280px);
    transform: translateX(-100%);
    z-index: var(--z-drawer);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* A desktop "collapsed to icons" preference (from localStorage) must not
     carry over into the mobile drawer, which always shows full labels. */
  .sidebar.collapsed {
    width: min(82vw, 280px);
  }

  .sidebar.collapsed .sidebar-header {
    padding: var(--space-6) var(--space-4) var(--space-4) var(--space-5);
    justify-content: space-between;
  }

  .sidebar.collapsed .sidebar-brand span:not(.brand-mark),
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .soon-tag {
    display: inline;
  }

  .sidebar.collapsed .sidebar-profile .profile-text {
    display: block;
  }

  .sidebar.collapsed .nav-item,
  .sidebar.collapsed .nav-item.disabled {
    justify-content: flex-start;
  }

  .sidebar.collapsed .sidebar-profile {
    padding: var(--space-4) var(--space-5);
    justify-content: flex-start;
  }

  .sidebar-collapse-btn {
    display: none;
  }

  .sidebar-mobile-close {
    display: flex;
  }

  .sidebar-nav-bottom {
    overflow: visible;
  }

  .nav-item {
    padding: 12px var(--space-3);
  }
}

::selection {
  background: var(--color-primary-light);
}

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