/* ==========================================================================
   Layout Styles (Sidebar, Header, App Frame, Main Containers)
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  height: 100%;
  width: 100%;
  max-width: 100vw;
  max-height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Custom Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

@supports not (scrollbar-color: auto) {
  *::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  *::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-full);
  }
  *::-webkit-scrollbar-track {
    background: transparent;
  }
}

/* App Shell */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-normal);
  flex-shrink: 0;
  z-index: 20;
}

.sidebar.collapsed {
  width: 68px;
}

.sidebar-header {
  height: 60px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 18px;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
  flex-shrink: 0;
}

.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .section-label,
.sidebar.collapsed .project-info,
.sidebar.collapsed .sidebar-footer-text {
  display: none;
}

.sidebar-collapse-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sidebar-collapse-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
  border-color: var(--border-default);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 6px 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  position: relative;
}

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

.nav-item.active {
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  border-color: var(--brand-primary-border);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.sidebar.collapsed .nav-badge {
  display: none;
}

/* Project Selector in Sidebar */
.project-selector-wrapper {
  padding: 6px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  margin-bottom: 8px;
}

.current-project-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  text-align: left;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.current-project-btn:hover {
  background: var(--bg-surface-elevated);
}

.project-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.project-info {
  flex: 1;
  min-width: 0;
}

.project-title {
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-type-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: #3b82f6;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  border: 2px solid var(--bg-surface);
}

/* Main Area */
.main-wrapper {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-app);
  position: relative;
}

/* Top App Header */
.app-header {
  height: 56px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 10;
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 1;
}

.header-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.header-project-select {
  max-width: 190px;
  min-width: 110px;
  height: 32px;
  padding: 0 24px 0 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238b949e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 8px;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.header-project-select:hover {
  border-color: var(--border-focus);
  background-color: var(--bg-surface-elevated);
}

.header-project-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--brand-primary-light);
}

.header-status-select {
  max-width: 145px;
  min-width: 95px;
  height: 28px;
  padding: 0 22px 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238b949e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 7px;
  transition: all var(--transition-fast);
}

.header-status-select:hover {
  filter: brightness(1.15);
}

.header-status-select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--brand-primary-light);
}

.breadcrumb-separator {
  color: var(--text-muted);
  opacity: 0.5;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.breadcrumb-active {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header-center {
  flex: 1;
  max-width: 440px;
  min-width: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.global-search-btn {
  width: 100%;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
}

.global-search-btn:hover {
  border-color: var(--border-default);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
}

.global-search-btn svg {
  flex-shrink: 0;
}

.global-search-btn span:not(.search-kbd) {
  flex: 1;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-kbd {
  margin-left: auto;
  flex-shrink: 0;
  padding: 2px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1.2;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-right .btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.header-right .btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
}

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

.mobile-menu-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
  transition: opacity var(--transition-fast);
}

/* View Container */
.view-container {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.view-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px;
}

.view-content.full-bleed {
  padding: 0;
  overflow: hidden;
}

/* ==========================================================================
   Multi-Device Responsive Breakpoints (Desktop, Laptop, Tablet, Mobile)
   ========================================================================== */

/* Laptops / Smaller Desktops (<= 1280px) */
@media (max-width: 1280px) {
  .header-project-select {
    max-width: 150px;
  }
  .global-search-btn .search-kbd {
    display: none;
  }
  .header-center {
    max-width: 320px;
  }
}

/* Small Laptops / Landscape Tablets (<= 1040px) */
@media (max-width: 1040px) {
  .header-breadcrumbs .breadcrumb-separator,
  .header-breadcrumbs .breadcrumb-active {
    display: none;
  }
  .header-center {
    max-width: 220px;
  }
  .view-content {
    padding: 16px 20px;
  }
}

/* Tablets (<= 860px) */
@media (max-width: 860px) {
  .app-header {
    padding: 0 12px;
    gap: 8px;
  }
  .header-project-select {
    max-width: 120px;
  }
  .header-status-select {
    max-width: 105px;
  }
  .header-center {
    max-width: 170px;
  }
  #header-btn-chat span {
    display: none;
  }
  #header-btn-chat {
    padding: 0 8px;
  }
}

/* Mobile Devices & Portrait Tablets (<= 768px) */
@media (max-width: 768px) {
  .mobile-menu-btn {
    display: inline-flex;
  }

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

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: none;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.75);
  }

  .sidebar.mobile-open .brand-name,
  .sidebar.mobile-open .nav-text,
  .sidebar.mobile-open .section-label,
  .sidebar.mobile-open .project-info,
  .sidebar.mobile-open .sidebar-footer-text,
  .sidebar.mobile-open .nav-badge {
    display: block !important;
  }

  .header-center {
    display: none;
  }

  .view-content {
    padding: 14px 16px;
  }
}

/* Small Screen Phones (<= 480px) */
@media (max-width: 480px) {
  .app-header {
    padding: 0 10px;
    gap: 6px;
    height: 52px;
  }
  .header-project-select {
    max-width: 105px;
    font-size: 0.78rem;
    padding-right: 18px;
  }
  .header-status-select {
    max-width: 85px;
    font-size: 0.68rem;
    padding: 0 16px 0 6px;
  }
  .header-right {
    gap: 6px;
  }
  .header-right .btn-sm {
    height: 30px;
    padding: 0 8px;
    font-size: 0.78rem;
  }
  .header-right .btn-icon {
    width: 30px;
    height: 30px;
  }
}
