/* ============================================================================
   Layout Styles — Orbit Labs Design System
   ============================================================================ */

/* ── Reset & Base Styles ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
}

/* ── Layout Shell ── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--size-sidebar);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--duration-slow) var(--easing-out),
              transform var(--duration-slow) ease;
  z-index: 200;
}

.sidebar.collapsed {
  width: 0;
  border-right: none;
  overflow: hidden;
}

.sidebar-logo {
  padding: var(--space-lg) var(--space-md) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  border-radius: var(--size-radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 32px;
  height: 32px;
  border-radius: var(--size-radius-xs);
  flex-shrink: 0;
}

.sidebar-logo > div {
  min-width: 0;
}

.logo-text {
  font-weight: 700;
  font-size: 15px;
  color: var(--color-text);
}

.logo-sub {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

/* ── Sidebar Navigation ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

.nav-section {
  padding: var(--space-sm) var(--space-md) var(--space-xs);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: 0;
  transition: background var(--duration-base), color var(--duration-base);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-size: 13.5px;
  font-family: inherit;
}

.nav-item:hover {
  background: var(--color-surface2);
  color: var(--color-text);
}

.nav-item.active {
  background: rgba(79, 142, 247, 0.12);
  color: var(--color-primary);
  border-right: 2px solid var(--color-primary);
}

.nav-icon {
  width: 18px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  border-radius: 10px;
  font-size: var(--font-size-xs);
  padding: 1px 6px;
  flex-shrink: 0;
}

/* ── Sidebar User Info ── */
.sidebar-user {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  color: #fff;
}

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

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.user-logout {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 16px;
  padding: var(--space-xs);
  border-radius: var(--size-radius-xs);
  transition: color var(--duration-base);
  cursor: pointer;
  background: none;
  border: none;
}

.user-logout:hover {
  color: var(--color-danger);
}

/* ── Main Content Area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Action Group (Dashboard) ── */
.dashboard-actions {
  margin-top: var(--space-xl);
}

.action-group {
  margin-bottom: var(--space-2xl);
}

.action-group h3 {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-border);
}

/* ── Topbar ── */
.topbar {
  height: var(--size-header);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-md);
  flex-shrink: 0;
}

.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 20px;
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--size-radius-xs);
  transition: background var(--duration-base);
}

.topbar-menu-btn:hover {
  background: var(--color-surface2);
}

.topbar-toggle-btn {
  display: flex;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.topbar-theme-btn {
  font-size: 16px;
  padding: 4px 8px;
  line-height: 1;
  cursor: pointer;
}

/* ── Page Content ── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl) var(--space-2xl);
}

.page-content::-webkit-scrollbar {
  width: 6px;
}

.page-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

/* ── Footer ── */
footer {
  padding: var(--space-md) var(--space-2xl);
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ── Sidebar Overlay (for mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 199;
  backdrop-filter: blur(2px);
  cursor: pointer;
}

.sidebar-overlay.open {
  display: block;
}

/* ── Global Scrollbar ── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* ============================================================================
   Responsive Design — Mobile First
   ============================================================================ */

/* Tablet compact sidebar (768-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: var(--size-sidebar-compact);
    transition: width var(--duration-slow) var(--easing-out);
  }

  .sidebar .logo-text,
  .sidebar .nav-text,
  .sidebar .sidebar-section-label,
  .sidebar .nav-badge,
  .sidebar-user .user-info {
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity var(--duration-base);
  }

  .sidebar .nav-item {
    justify-content: center;
    padding: var(--space-sm);
  }

  .sidebar .nav-icon {
    margin: 0;
    font-size: 18px;
  }

  .sidebar-logo {
    justify-content: center;
    padding: var(--space-md);
  }

  .sidebar:hover {
    width: var(--size-sidebar);
  }

  .sidebar:hover .logo-text,
  .sidebar:hover .nav-text,
  .sidebar:hover .sidebar-section-label,
  .sidebar:hover .nav-badge,
  .sidebar:hover .user-info {
    opacity: 1;
    width: auto;
  }

  .sidebar:hover .nav-item {
    justify-content: flex-start;
    padding: var(--space-xs) var(--space-md);
  }

  .sidebar:hover .sidebar-logo {
    justify-content: flex-start;
  }
}

/* Tablet (768px) */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
  }

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

  .sidebar-overlay.open {
    display: block;
  }

  .page-content {
    padding: var(--space-md) var(--space-lg);
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    padding: 0 var(--space-lg);
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

/* Mobile (480px) */
@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

  .stat-card {
    padding: var(--space-md);
  }

  .stat-card .num {
    font-size: 22px;
  }

  .page-content {
    padding: var(--space-sm);
  }

  table {
    font-size: var(--font-size-xs);
  }

  th,
  td {
    padding: var(--space-sm);
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .card {
    padding: var(--space-md);
  }
}

/* Large screens (1400px+) */
@media (min-width: 1400px) {
  .page-content {
    padding: var(--space-2xl) 32px;
  }
}

/* ── Light Mode Layout Overrides ── */
[data-theme="light"] .sidebar {
  background: var(--color-surface);
  border-right-color: var(--color-border);
}

[data-theme="light"] .topbar {
  background: var(--color-surface);
  border-bottom-color: var(--color-border);
}

/* ── iOS Safe Area ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .page-content {
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom));
  }

  footer {
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }
}

/* ── Mobile < 400px: single column forms, tighter stat grid ── */
@media (max-width: 400px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-xs);
  }

  .stat-card .num {
    font-size: 20px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  input[type=text],
  input[type=password],
  input[type=email],
  input[type=number],
  select,
  textarea {
    font-size: 16px;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .card {
    padding: var(--space-sm);
  }

  .page-content {
    padding: var(--space-xs);
  }
}
