/* ============================================================
   NexHome Smart Home Platform — Layout Framework
   Design tokens referenced from design-system.css via var()
   ============================================================ */

/* ----- 1. App Shell ----- */

.app-shell {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  width: 100%;
}

/* ----- 2. Sidebar ----- */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 260px;
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  transition: transform 0.3s ease, width 0.3s ease;
}

.sidebar-header {
  height: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 20px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-user .user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-user .user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-user .user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  flex: 1;
}

.sidebar-nav-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 44px;
  padding: 0 20px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  position: relative;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sidebar-nav-item:hover {
  background: rgba(56, 189, 248, 0.08);
  color: var(--text-primary);
}

.sidebar-nav-item.active {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-cyan);
  border-left: 3px solid var(--accent-cyan);
  padding-left: 17px;
}

.sidebar-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.sidebar-nav-item .nav-badge {
  margin-left: auto;
  background: var(--color-cyan, var(--bg-accent));
  color: var(--text-on-accent, #fff);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  line-height: 1.4;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 20px;
}

/* ----- 3. Top Bar ----- */

.topbar {
  position: sticky;
  top: 0;
  height: 64px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(21, 34, 50, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
}

.topbar-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
}

.topbar-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.topbar-breadcrumb {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ----- 4. Main Content ----- */

.main-content {
  margin-left: 260px;
  min-height: 100vh;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ----- 5. Page Content ----- */

.page-content {
  padding: 24px;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

/* Responsive max-width for better readability */
@media (min-width: 1920px) {
  .page-content {
    max-width: 1800px;
    margin: 0 auto;
  }
}

@media (min-width: 2560px) {
  .page-content {
    max-width: 2200px;
    margin: 0 auto;
  }
}

/* ----- 6. Grid System ----- */

.grid {
  display: grid;
  gap: 20px;
}

.grid-1 {
  grid-template-columns: 1fr;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid-auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.col-span-2 {
  grid-column: span 2;
}

.col-span-3 {
  grid-column: span 3;
}

.col-span-full {
  grid-column: 1 / -1;
}

/* ----- 7. Section ----- */

.section {
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i {
  color: var(--accent-cyan);
}

.section-action {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ----- 9. Menu Toggle Button ----- */

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 301;
  padding: 0;
  color: var(--text-primary);
  transition: background 0.2s ease;
}

.menu-toggle:hover {
  background: var(--bg-highlight);
}

.menu-toggle .hamburger {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 18px;
}

.menu-toggle .hamburger span {
  display: block;
  height: 2px;
  width: 100%;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.2s ease;
}

/* ----- Sidebar Overlay ----- */

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 299;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

/* ----- 10. Scrollable Horizontal Container ----- */

.scroll-x {
  display: flex;
  flex-direction: row;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.scroll-x > * {
  scroll-snap-align: start;
  flex-shrink: 0;
}

.scroll-x::-webkit-scrollbar {
  height: 6px;
}

.scroll-x::-webkit-scrollbar-track {
  background: transparent;
}

.scroll-x::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

/* ============================================================
   8. Responsive Breakpoints
   ============================================================ */

/* ----- Laptop: 1024px - 1200px ----- */

@media (max-width: 1200px) {
  .sidebar {
    width: 220px;
  }

  .main-content {
    margin-left: 220px;
  }

  .page-content {
    padding: 20px;
  }

  .grid {
    gap: 16px;
  }
}

/* ----- Tablet: 768px - 1024px ----- */

@media (max-width: 1024px) {
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    position: fixed;
    z-index: 300;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: flex;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .col-span-3 {
    grid-column: span 2;
  }
}

/* ----- Mobile: < 768px ----- */

@media (max-width: 767px) {
  .topbar {
    padding: 0 16px;
    height: 56px;
  }

  .topbar-title {
    font-size: 1.05rem;
  }

  .page-content {
    padding: 16px;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .col-span-2,
  .col-span-3 {
    grid-column: span 1;
  }

  .grid-auto-fit,
  .grid-auto-fill {
    grid-template-columns: 1fr;
  }

  .grid {
    gap: 14px;
  }

  .menu-toggle {
    display: flex;
  }

  .scroll-x::-webkit-scrollbar {
    display: none;
  }

  .scroll-x {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .topbar-right {
    gap: 10px;
  }
}

/* ----- Small: < 480px ----- */

@media (max-width: 479px) {
  .page-content {
    padding: 12px;
  }

  .grid {
    gap: 12px;
  }

  .topbar {
    padding: 0 12px;
  }

  .sidebar-nav {
    padding: 8px;
  }

  .sidebar-nav-item {
    padding: 0 14px;
    height: 40px;
    font-size: 0.825rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .topbar-title {
    font-size: 0.95rem;
  }

  .topbar-breadcrumb {
    display: none;
  }

  .scroll-x {
    gap: 12px;
  }
}
