/* ============================================================================
   App Shell — sidebar + topbar + 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";
  min-height: 100vh;
  transition: grid-template-columns var(--dur-base) var(--ease-out);
}
.app-shell[data-sidebar="collapsed"] {
  grid-template-columns: 0 1fr;
}
.app-shell[data-sidebar="collapsed"] .app-sidebar {
  transform: translateX(-100%);
  pointer-events: none;
  border-right-color: transparent;
}

.app-sidebar {
  grid-area: sidebar;
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: var(--z-sticky);
  transition: transform var(--dur-base) var(--ease-out),
              border-color var(--dur-base) var(--ease-out);
}

.sidebar-reveal-zone {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 18px;
  z-index: calc(var(--z-sticky) + 3);
  cursor: e-resize;
}
.sidebar-reveal-zone::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 50%;
  width: 4px;
  height: 72px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--brand-500) 42%, transparent);
  transform: translateY(-50%);
  opacity: 0.55;
}

.app-topbar {
  grid-area: topbar;
  background: var(--surface-1);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
}
.app-topbar,
.app-topbar .breadcrumb,
.app-topbar .breadcrumb-current {
  color: var(--text-primary);
}

.app-main {
  grid-area: main;
  min-width: 0;
  padding: var(--space-6);
  max-width: 100%;
}

/* ─── Sidebar internals ───────────────────────────────────────────────── */
.sb-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.sb-brand-logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-1) 86%, var(--brand-500));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.sb-brand-william {
  border-radius: 9999px;
  border: 1px solid color-mix(in srgb, #fbbf24 55%, var(--border-subtle));
}
.sb-brand-william img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.sb-brand-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 0.9375rem;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
}
.sb-close-btn {
  width: 2rem;
  height: 2rem;
  margin-left: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text-primary);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sb-close-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-default);
}

.sb-nav {
  flex: 1;
  padding: var(--space-3);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.sb-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: var(--space-3) var(--space-3) var(--space-1);
  white-space: nowrap;
  overflow: hidden;
}
.sb-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--dur-fast) var(--ease-out);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}
.sb-link:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.sb-link[aria-current="page"] {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 600;
}
[data-theme="dark"] .sb-link[aria-current="page"] {
  background: rgb(99 102 241 / 0.15);
  color: var(--brand-300);
}
.sb-link-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9375rem;
}
.sb-link-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sb-link-badge {
  background: var(--danger-500);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0 0.375rem;
  border-radius: var(--radius-full);
  min-width: 1.125rem;
  height: 1.125rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

/* Collapsed state */
.app-shell[data-sidebar="collapsed"] .sb-brand-name,
.app-shell[data-sidebar="collapsed"] .sb-section-label,
.app-shell[data-sidebar="collapsed"] .sb-link-label,
.app-shell[data-sidebar="collapsed"] .sb-link-badge,
.app-shell[data-sidebar="collapsed"] .sb-user-meta {
  display: none;
}
.app-shell[data-sidebar="collapsed"] .sb-link,
.app-shell[data-sidebar="collapsed"] .sb-brand,
.app-shell[data-sidebar="collapsed"] .sb-user {
  justify-content: center;
}

/* User card */
.sb-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-fast);
}
.sb-user:hover { background: var(--surface-2); }
.sb-user-meta { flex: 1; min-width: 0; }
.sb-user-name { font-size: 0.8125rem; font-weight: 600; color: var(--text-primary); }
.sb-user-sub { font-size: 0.6875rem; color: var(--text-tertiary); display: flex; align-items: center; gap: 0.25rem; }

/* ─── Topbar ────────────────────────────────────────────────────────── */
.tb-search {
  flex: 1;
  max-width: 480px;
  position: relative;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  margin-left: auto;
}
.tb-search-input {
  width: 100%;
  padding: 0.375rem 0.75rem 0.375rem 2.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-align: left;
  pointer-events: none;
  transition: border-color var(--dur-fast);
}
.tb-search-input:focus {
  background: var(--surface-1);
  border-color: var(--border-default);
  outline: none;
}
.tb-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  font-size: 0.75rem;
}
.tb-search-kbd {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

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

.tb-icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur-fast);
  cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  font-size: 0.9375rem;
}
.tb-icon-btn:hover {
  background: var(--surface-3);
  color: var(--brand-600);
  border-color: var(--brand-300);
}

.tb-collapse-btn {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.tb-collapse-btn:hover {
  background: var(--brand-50);
  color: var(--brand-600);
  border-color: var(--brand-300);
}
/* Theme toggle: prominent pill that reads at a glance in both modes */
.tb-theme-toggle {
  background: linear-gradient(135deg, var(--brand-500), var(--accent-500));
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.tb-theme-toggle:hover {
  background: linear-gradient(135deg, var(--brand-500), var(--accent-500));
  color: #fff;
  border-color: transparent;
  transform: rotate(-18deg);
  box-shadow: var(--shadow-md);
}
.tb-theme-toggle i { color: currentColor; transition: transform var(--dur-fast); }
[data-theme="dark"] .tb-theme-toggle {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #1f2937;
  border-color: transparent;
}
[data-theme="dark"] .tb-theme-toggle:hover {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #1f2937;
}

/* ─── Breadcrumb ────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.breadcrumb-sep { color: var(--text-tertiary); }
.breadcrumb-current { color: var(--text-primary); font-weight: 500; }

/* ─── Page header ───────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  line-height: 1.2;
}
.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: var(--space-1);
}
.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ─── Mobile ────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
      "topbar"
      "main";
    padding-bottom: 56px; /* mobile nav space */
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease-out);
    width: 280px;
    height: 100vh;
    box-shadow: var(--shadow-2xl);
  }
  .sidebar-reveal-zone { display: none !important; }
  .app-shell[data-mobile-nav="open"] .app-sidebar {
    transform: translateX(0);
    pointer-events: auto;
    border-right-color: var(--border-subtle);
  }
  .app-shell[data-mobile-nav="open"]::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.5);
    z-index: calc(var(--z-sticky) - 1);
    animation: fade-in var(--dur-base) var(--ease-out);
  }
  .app-main {
    padding: var(--space-4);
  }
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface-1);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: var(--z-sticky);
    padding: 0 var(--space-2);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--text-tertiary);
    font-size: 0.625rem;
    font-weight: 500;
    padding: var(--space-2);
    flex: 1;
    border-radius: var(--radius-md);
  }
  .mobile-nav-link i { font-size: 1.125rem; }
  .mobile-nav-link[aria-current="page"] { color: var(--brand-600); }
  .tb-collapse-btn { display: none !important; }
  .sb-close-btn { display: inline-flex; }
}

@media (min-width: 1024px) {
  .mobile-nav { display: none; }
  .tb-hamburger { display: none !important; }
}
