/* App shell layout */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-sidebar {
  grid-area: sidebar;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
  flex-shrink: 0;
}

.sidebar-brand-mark {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-brand-text {
  overflow: hidden;
}
.sidebar-brand-text strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand-text span {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-3) var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  min-height: 36px;
  position: relative;
}
@media (pointer: coarse) { .nav-item { min-height: 44px; } }

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
}
.nav-item svg { flex-shrink: 0; width: 18px; height: 18px; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 600;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.sidebar-footer {
  padding: var(--space-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.app-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
  z-index: 50;
}

.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}
.topbar-menu-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.topbar-title { font-size: var(--text-md); font-weight: 600; }
.topbar-breadcrumb {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.topbar-breadcrumb a { color: var(--text-muted); text-decoration: none; }
.topbar-breadcrumb a:hover { color: var(--accent); }

.topbar-search {
  flex: 1;
  max-width: 320px;
  position: relative;
}
.topbar-search input {
  width: 100%;
  padding-left: 32px;
  min-height: 32px;
}
.topbar-search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.help-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}
.help-link:hover { color: var(--accent); background: var(--accent-subtle); }

.user-menu {
  position: relative;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
  min-height: 32px;
}
@media (pointer: coarse) { .user-menu-btn { min-height: 44px; } }
.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: none;
  z-index: 60;
}
.user-dropdown.open { display: block; }
.user-dropdown button, .user-dropdown a {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
}
.user-dropdown button:hover, .user-dropdown a:hover { background: var(--bg-hover); }

.app-main {
  grid-area: main;
  overflow: auto;
  padding: var(--space-4);
  -webkit-overflow-scrolling: touch;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.page-header-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* Tablet: collapsed sidebar */
@media (max-width: 1280px) and (min-width: 769px) {
  .app-shell { grid-template-columns: var(--sidebar-collapsed) 1fr; }
  .sidebar-brand-text, .nav-item span, .nav-section-label, .nav-badge { display: none; }
  .nav-item { justify-content: center; padding: var(--space-2); }
  .nav-item svg { margin: 0; }
  .sidebar-brand { justify-content: center; padding: var(--space-3); }
}

/* Mobile: off-canvas sidebar */
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: min(280px, 85vw);
    height: 100%;
    transform: translateX(-100%);
    transition: transform 250ms ease;
    box-shadow: var(--shadow-md);
  }
  .app-sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
    display: none;
  }
  .sidebar-overlay.open { display: block; }
  .topbar-menu-btn { display: flex; }
  .topbar-search { display: none; }
  .topbar-breadcrumb { display: none; }
}

/* Design system proof page */
.ds-section { margin-bottom: var(--space-8); }
.ds-section > h2 {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.ds-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-4); }
.ds-swatch {
  width: 80px;
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: var(--space-1);
  font-size: 9px;
  color: var(--text-muted);
}
