/* ========= SHELL LAYOUT ========= */

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

body {
  display: flex;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  line-height: 1.6;
}

/* ========= SIDEBAR ========= */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease;
  position: relative;
  z-index: 50;
}

/* Sidebar Logo - fixed at top */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 24px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: linear-gradient(135deg, #00d4ff, #7c3aed);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.sidebar-logo-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar-logo-text {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
}

/* Sidebar Navigation - scrollable */
.sidebar-nav {
  flex: 1;
  padding: 4px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--sidebar-hover-bg);
  border-radius: 4px;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-title {
  display: block;
  padding: 12px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--sidebar-text);
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s, color 0.15s;
}

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

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.nav-item.active .nav-icon {
  color: var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
}

.nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.nav-badge {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
  white-space: nowrap;
}

/* Sidebar Footer - fixed at bottom */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-collapse-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

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

.sidebar-collapse-btn svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
}

.sidebar-collapse-btn .collapse-label {
  white-space: nowrap;
  overflow: hidden;
}

/* Sidebar Collapsed State */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .collapse-label {
  display: none;
}

.sidebar.collapsed .sidebar-logo {
  justify-content: center;
  padding: 20px 8px 24px;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px 0;
}

.sidebar.collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

/* ========= MAIN WRAPPER ========= */

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ========= TOP BAR ========= */

.topbar {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Hamburger (hidden on desktop) */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.hamburger-btn:hover {
  background: var(--surface-2);
}

.hamburger-btn svg {
  width: 22px;
  height: 22px;
}

/* Search Box */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 38px;
  max-width: 400px;
  width: 100%;
  transition: border-color 0.15s;
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-icon {
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.search-icon svg {
  width: 16px;
  height: 16px;
}

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: var(--font-sans);
}

.search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.search-kbd {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-sans);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  line-height: 1;
}

/* Topbar Icon Buttons */
.topbar-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  position: relative;
}

.topbar-icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-light);
}

.topbar-icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Theme Toggle */
.theme-toggle-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.theme-toggle-btn:hover {
  background: var(--surface-3);
  color: var(--orange);
  border-color: var(--border-light);
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* Profile Avatar */
.profile-avatar {
  margin-left: 4px;
}

.avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d4ff, #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Notification badge dot */
.notification-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--red);
  border-radius: 50%;
  border: 2px solid var(--header-bg);
}

/* ========= CONTENT AREA ========= */

.content-area {
  flex: 1;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ========= FOOTER ========= */

.site-footer {
  padding: 8px 24px;
  border-top: 1px solid var(--border);
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--accent);
}

.footer-sep {
  opacity: 0.4;
}

/* ========= SIDEBAR OVERLAY (mobile) ========= */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

/* ========= SEARCH DROPDOWN (mobile + desktop) ========= */

.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
}

.search-dropdown.visible {
  display: block;
}

.search-dropdown-item {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.search-dropdown-item:last-child {
  border-bottom: none;
}

.search-dropdown-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ========= RESPONSIVE ========= */

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    z-index: 100;
    transition: transform 0.3s ease;
  }

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

  .hamburger-btn {
    display: flex;
  }

  .sidebar-footer {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 12px;
    height: 52px;
    min-height: 52px;
    gap: 8px;
  }

  .search-box {
    max-width: none;
    height: 34px;
    padding: 0 10px;
  }

  .search-input {
    font-size: 14px;
  }

  .search-kbd {
    display: none;
  }

  .site-footer {
    padding: 8px 16px;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    text-align: center;
  }

  .content-area {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ========= GLOBAL MOBILE APP HELPERS ========= */

@media (max-width: 768px) {
  /* Make app headers wrap on mobile */
  [class$="-header"] {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Make buttons smaller */
  .btn {
    padding: 6px 10px;
    font-size: 12px;
  }
}
