.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: clip;
  background: var(--color-surface);
}

/* Desktop Slim Icon Rail Sidebar (>= 1024px) */
.sidebar {
  display: none;
}

.main-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-4));
  background: var(--color-surface);
}

/* Sticky Pure-White Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-3);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #FFFFFF;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.topbar-brand-badge svg {
  width: 18px;
  height: 18px;
}

.topbar-titles {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-subtitle {
  font-size: 11px;
  line-height: 1.2;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Topbar Pill Global Search (visible >= 768px) */
.topbar-search {
  display: none;
}

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

.topbar-settings-btn {
  display: none;
}

.topbar-profile-btn {
  display: none;
}

.topbar-create-label-full {
  display: none;
}

.topbar-create-label-short {
  display: inline;
}

/* Main Content */
.main-content {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

/* Section Header */
.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-heading {
  min-width: 0;
}

.section-heading h1 {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.section-heading p {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.dashboard-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
}

.detail-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
}

/* Responsive table vs card list */
.desktop-table-wrap {
  display: none;
}

.mobile-card-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Mobile / Tablet Bottom Navigation (< 1024px) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  height: var(--bottom-nav-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-hairline);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: var(--space-1) var(--space-1);
  gap: var(--space-1);
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  min-width: 0;
  padding: var(--space-1);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 500;
  position: relative;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.bottom-nav-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.bottom-nav-btn span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-nav-btn[aria-current="page"] {
  background: var(--color-surface-hover);
  color: var(--color-text);
  font-weight: 600;
}

/* >= 640px */
@media (min-width: 640px) {
  .topbar {
    padding: 0 var(--space-4);
  }

  .topbar-settings-btn {
    display: inline-flex;
  }

  .topbar-create-label-full {
    display: inline;
  }

  .topbar-create-label-short {
    display: none;
  }

  .main-content {
    padding: var(--space-4);
    gap: var(--space-6);
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .form-span-2 {
    grid-column: 1 / -1;
  }
}

/* >= 768px */
@media (min-width: 768px) {
  .topbar {
    height: 68px;
    padding: 0 var(--space-6);
  }

  .topbar-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .topbar-search {
    display: flex;
    align-items: center;
    position: relative;
    width: 240px;
    margin-left: var(--space-3);
  }

  .topbar-search-input {
    width: 100%;
    height: 38px;
    padding: 0 38px 0 var(--space-4);
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-hairline);
    background: var(--color-surface);
    font-size: 13px;
    color: var(--color-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, width 0.25s var(--ease-out-expo);
  }

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

  .topbar-search-input:hover {
    border-color: var(--color-border-strong);
  }

  .topbar-search-input:focus {
    outline: none;
    border-color: var(--color-text);
    box-shadow: 0 0 0 3px rgba(17, 19, 21, 0.08);
  }

  .topbar-search-btn {
    position: absolute;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 0;
    background: transparent;
    color: var(--color-text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.15s ease, background-color 0.15s ease;
  }

  .topbar-search-btn:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
  }

  .topbar-search-btn svg {
    width: 15px;
    height: 15px;
  }

  .topbar-profile-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 2px 6px 2px 2px;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    background: transparent;
    transition: background-color 0.18s ease, border-color 0.18s ease;
  }

  .topbar-profile-btn:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-hairline);
  }

  .topbar-profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 100%);
    color: #3730A3;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .topbar-profile-chevron {
    width: 14px;
    height: 14px;
    color: var(--color-text-muted);
  }

  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .main-content {
    padding: var(--space-6);
  }

  .section-heading h1 {
    font-size: 22px;
  }
}

/* >= 1024px Desktop Slim Icon Rail */
@media (min-width: 1024px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-hairline);
    position: sticky;
    top: 0;
    height: 100vh;
    padding: var(--space-4) 0;
    gap: var(--space-6);
    z-index: 25;
  }

  .sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-logo-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 0;
    background: var(--color-primary);
    color: #FFFFFF;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
  }

  .sidebar-logo-btn:hover {
    transform: translateY(-1px) scale(1.03);
    box-shadow: var(--shadow-md);
  }

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

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    flex: 1 1 auto;
    width: 100%;
  }

  .sidebar-nav-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--color-text-muted);
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.18s var(--ease-spring);
  }

  .sidebar-nav-btn:hover {
    background: var(--color-surface-subtle);
    color: var(--color-text);
    transform: scale(1.05);
  }

  .sidebar-nav-btn[aria-current="page"] {
    background: var(--color-surface-hover);
    color: var(--color-text);
  }

  .sidebar-nav-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .sidebar-nav-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-danger);
    border: 1.5px solid #FFFFFF;
  }

  /* Floating Tooltip on Hover/Focus */
  .sidebar-nav-btn::after,
  .sidebar-util-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--color-primary);
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    box-shadow: var(--shadow-md);
    transition: opacity 0.16s ease, transform 0.18s var(--ease-out-expo);
    z-index: 50;
  }

  .sidebar-nav-btn:hover::after,
  .sidebar-nav-btn:focus-visible::after,
  .sidebar-util-btn:hover::after,
  .sidebar-util-btn:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }

  .sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding-top: var(--space-2);
  }

  .sidebar-util-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--color-text-muted);
    transition: background-color 0.2s ease, color 0.2s ease;
  }

  .sidebar-util-btn:hover {
    background: var(--color-surface-subtle);
    color: var(--color-text);
  }

  .sidebar-util-btn[aria-current="page"] {
    background: var(--color-surface-hover);
    color: var(--color-text);
  }

  .sidebar-util-btn svg {
    width: 19px;
    height: 19px;
  }

  .topbar-brand-badge,
  .topbar-subtitle {
    display: none;
  }

  .topbar-search {
    width: 280px;
  }

  .main-area {
    padding-bottom: var(--space-8);
  }

  .main-content {
    padding: var(--space-6) var(--space-8);
    gap: var(--space-8);
  }

  .bottom-nav {
    display: none;
  }

  .desktop-table-wrap {
    display: block;
  }

  .mobile-card-list {
    display: none;
  }

  .dashboard-split {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: var(--space-8);
    align-items: start;
  }

  .detail-split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-4);
  }
}
