/* TC-017B — application shell.
   Scope: sidebar, utility top bar, page header and responsive navigation only. */

:root {
  --shell-sidebar-width: 248px;
  --shell-sidebar-collapsed-width: 72px;
  --shell-topbar-height: 64px;
}

.app {
  grid-template-columns: var(--shell-sidebar-width) minmax(0, 1fr);
  background: var(--color-bg);
  transition: grid-template-columns var(--motion-slow) var(--motion-ease);
}

.app.shell-collapsed {
  grid-template-columns: var(--shell-sidebar-collapsed-width) minmax(0, 1fr);
}

/* Sidebar */
.app > .sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 100vh;
  height: 100dvh;
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  box-shadow: none;
}

.app > .sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 0%, rgba(37, 99, 235, 0.2), transparent 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 44%);
}

.app > .sidebar > * {
  position: relative;
  z-index: 1;
}

.sidebar .brand {
  min-height: 48px;
  margin: 0;
  padding: 4px 8px 8px;
  gap: 12px;
  align-items: center;
  overflow: hidden;
}

.sidebar .logo {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, #dbeafe, #93c5fd);
  color: #08254a;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.22);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.sidebar .brand > div:last-child {
  min-width: 0;
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity var(--motion-fast) var(--motion-ease),
    transform var(--motion-medium) var(--motion-ease);
}

.sidebar .brand h1 {
  margin: 0;
  color: var(--color-sidebar-text);
  font-size: 14px;
  line-height: 18px;
  font-weight: 650;
  white-space: nowrap;
}

.sidebar .brand p {
  margin: 2px 0 0;
  color: var(--color-sidebar-muted);
  font-size: 11px;
  line-height: 16px;
  white-space: nowrap;
}

.sidebar .nav {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 4px 0 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.sidebar .nav button {
  position: relative;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--color-sidebar-muted);
  box-shadow: none;
  text-align: left;
  font-size: 13px;
  line-height: 18px;
  font-weight: 550;
  white-space: nowrap;
  transition:
    color var(--motion-fast) var(--motion-ease),
    background-color var(--motion-fast) var(--motion-ease),
    border-color var(--motion-fast) var(--motion-ease),
    transform var(--motion-fast) var(--motion-ease);
}

.sidebar .nav button:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--color-sidebar-text);
  transform: translateX(1px);
}

.sidebar .nav button.active,
.sidebar .nav button[aria-current="page"] {
  border-color: rgba(147, 197, 253, 0.22);
  background: rgba(37, 99, 235, 0.26);
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.sidebar .nav button.active::before,
.sidebar .nav button[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 3px;
  background: #93c5fd;
}

.shell-nav-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-grid;
  place-items: center;
}

.shell-nav-icon svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell-nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar .sideblock {
  display: none !important;
}

.shell-sidebar-footer {
  margin-top: auto;
  padding-top: 10px;
  display: grid;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.shell-sidebar-user {
  min-height: 48px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  color: var(--color-sidebar-text);
}

.shell-sidebar-avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
}

.shell-sidebar-user-copy {
  min-width: 0;
  display: grid;
  gap: 1px;
  opacity: 1;
  transition: opacity var(--motion-fast) var(--motion-ease);
}

.shell-sidebar-user-name,
.shell-sidebar-user-role {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell-sidebar-user-name {
  color: var(--color-sidebar-text);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
}

.shell-sidebar-user-role {
  color: var(--color-sidebar-muted);
  font-size: 11px;
  line-height: 16px;
}

.shell-collapse-btn {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-sidebar-muted);
  font: inherit;
  cursor: pointer;
  transition:
    background-color var(--motion-fast) var(--motion-ease),
    color var(--motion-fast) var(--motion-ease),
    border-color var(--motion-fast) var(--motion-ease);
}

.shell-collapse-btn:hover {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-sidebar-text);
}

.shell-collapse-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-grid;
  place-items: center;
  transition: transform var(--motion-medium) var(--motion-ease);
}

.shell-collapse-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell-collapse-label {
  white-space: nowrap;
}

.app.shell-collapsed .sidebar .brand {
  padding-inline: 4px;
  justify-content: center;
}

.app.shell-collapsed .sidebar .brand > div:last-child,
.app.shell-collapsed .shell-nav-label,
.app.shell-collapsed .shell-sidebar-user-copy,
.app.shell-collapsed .shell-collapse-label {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.app.shell-collapsed .sidebar .nav button,
.app.shell-collapsed .shell-collapse-btn {
  justify-content: center;
  padding-inline: 0;
  gap: 0;
}

.app.shell-collapsed .sidebar .nav button.active::before,
.app.shell-collapsed .sidebar .nav button[aria-current="page"]::before {
  left: 2px;
}

.app.shell-collapsed .shell-sidebar-user {
  justify-content: center;
  padding-inline: 0;
}

.app.shell-collapsed .shell-collapse-icon {
  transform: rotate(180deg);
}

/* Main workspace */
.app > .main {
  min-width: 0;
  padding: 0 24px 24px;
  background: var(--color-bg);
}

.main > .topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  min-height: var(--shell-topbar-height);
  height: var(--shell-topbar-height);
  margin: 0;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(244, 247, 251, 0.94);
  backdrop-filter: blur(10px);
}

.shell-mobile-menu {
  display: none;
}

.shell-global-search {
  position: relative;
  min-width: 220px;
  max-width: 560px;
  flex: 1 1 560px;
}

.shell-global-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

.shell-global-search-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell-global-search input {
  width: 100%;
  min-height: 40px;
  padding: 9px 42px 9px 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.96);
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
  outline: none;
  transition:
    border-color var(--motion-fast) var(--motion-ease),
    box-shadow var(--motion-fast) var(--motion-ease),
    background-color var(--motion-fast) var(--motion-ease);
}

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

.shell-global-search input:focus {
  border-color: var(--color-primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.shell-global-search input::placeholder {
  color: #94a3b8;
}

.shell-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  width: 32px;
  height: 32px;
  padding: 0;
  display: none;
  place-items: center;
  transform: translateY(-50%);
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.shell-search-clear[data-visible="true"] {
  display: grid;
}

.shell-search-clear:hover {
  background: var(--color-neutral-bg);
  color: var(--color-text);
}

.main > .topbar .topbar-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
}

.shell-utility-btn,
.main > .topbar .topbar-actions > .icon-btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--color-text-secondary);
}

.shell-utility-btn:hover,
.main > .topbar .topbar-actions > .icon-btn:hover {
  border-color: var(--color-border);
  background: #ffffff;
  color: var(--color-primary-hover);
  box-shadow: var(--shadow-sm);
}

.shell-utility-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell-notification-btn {
  position: relative;
}

.shell-notification-count {
  position: absolute;
  top: 3px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  display: none;
  place-items: center;
  border: 2px solid var(--color-bg);
  border-radius: 999px;
  background: var(--color-danger-text);
  color: #ffffff;
  font-size: 9px;
  line-height: 13px;
  font-weight: 700;
}

.shell-notification-count[data-visible="true"] {
  display: grid;
}

.main > .topbar .user-badge {
  min-height: 40px;
  padding: 4px 4px 4px 10px;
  gap: 8px;
  border-color: var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--color-text-secondary);
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
}

.main > .topbar .user-badge > span:first-child {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main > .topbar .user-badge .role-badge {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main > .topbar .user-badge .icon-btn {
  width: 32px;
  height: 32px;
  min-height: 32px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

/* Page header */
.shell-page-header {
  min-height: 88px;
  padding: 20px 0 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.shell-page-header-copy {
  min-width: 0;
  max-width: 880px;
}

.shell-page-header h2,
.shell-page-header #pageTitle {
  margin: 0;
  color: var(--color-text);
  font-size: 24px;
  line-height: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.shell-page-header p,
.shell-page-header #pageSubtitle {
  margin: 3px 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 20px;
  overflow-wrap: break-word;
}

.shell-page-actions {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.shell-mobile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: none;
  background: rgba(7, 26, 51, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-medium) var(--motion-ease);
}

/* Help modal */
.shell-help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.shell-help-card {
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted);
}

.shell-help-card h4 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 650;
}

.shell-help-card p {
  margin: 6px 0 0;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 19px;
}

.shell-status-list {
  display: grid;
  gap: 8px;
}

.shell-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 18px;
}

.shell-status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
}

@media (max-width: 1100px) {
  :root {
    --shell-sidebar-width: 224px;
  }

  .app > .main {
    padding-inline: 18px;
  }

  .main > .topbar .user-badge > span:first-child,
  .main > .topbar .user-badge .role-badge {
    display: none;
  }

  .main > .topbar .user-badge {
    padding-left: 4px;
  }
}

@media (max-width: 900px) {
  .app,
  .app.shell-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .app > .sidebar,
  .app.shell-collapsed > .sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    z-index: 60;
    width: min(288px, calc(100vw - 48px));
    height: 100vh;
    height: 100dvh;
    padding: 16px 12px 12px;
    transform: translateX(-104%);
    transition: transform var(--motion-slow) var(--motion-ease);
    box-shadow: 18px 0 48px rgba(7, 26, 51, 0.26);
  }

  .app.shell-mobile-open > .sidebar,
  .app.shell-collapsed.shell-mobile-open > .sidebar {
    transform: translateX(0);
  }

  .app.shell-mobile-open + .shell-mobile-backdrop,
  .shell-mobile-backdrop[data-open="true"] {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .app.shell-collapsed .sidebar .brand {
    padding-inline: 8px;
    justify-content: flex-start;
  }

  .app.shell-collapsed .sidebar .brand > div:last-child,
  .app.shell-collapsed .shell-nav-label,
  .app.shell-collapsed .shell-sidebar-user-copy {
    width: auto;
    opacity: 1;
    pointer-events: auto;
  }

  .app.shell-collapsed .sidebar .nav button,
  .app.shell-collapsed .shell-sidebar-user {
    justify-content: flex-start;
    padding-inline: 12px;
    gap: 12px;
  }

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

  .app > .main {
    padding: 0 16px 20px;
  }

  .main > .topbar {
    display: flex !important;
    gap: 10px;
  }

  .shell-mobile-menu {
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    flex: 0 0 40px;
  }

  .shell-mobile-menu svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
  }

  .shell-global-search {
    min-width: 0;
    max-width: none;
    flex-basis: auto;
  }

  .shell-page-header {
    min-height: 80px;
    padding-top: 16px;
  }
}

@media (max-width: 680px) {
  .app > .main {
    padding-inline: 12px;
  }

  .main > .topbar {
    height: auto;
    min-height: var(--shell-topbar-height);
    padding-block: 10px;
    display: grid !important;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
  }

  .main > .topbar .topbar-actions {
    margin: 0;
    gap: 4px;
  }

  .main > .topbar .topbar-actions .shell-help-btn,
  .main > .topbar .topbar-actions > .icon-btn:not(:last-child) {
    display: none;
  }

  .main > .topbar .user-badge {
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .shell-page-header {
    min-height: 0;
    padding: 14px 0 12px;
    flex-direction: column;
    gap: 10px;
  }

  .shell-page-header h2,
  .shell-page-header #pageTitle {
    font-size: 21px;
    line-height: 28px;
  }

  .shell-page-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .shell-help-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .main > .topbar {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
  }

  .main > .topbar .topbar-actions .shell-notification-btn,
  .main > .topbar .topbar-actions > .icon-btn {
    display: none;
  }

  .main > .topbar .user-badge {
    width: 40px;
    min-width: 40px;
    padding: 4px;
  }

  .main > .topbar .user-badge .icon-btn {
    width: 32px;
    display: inline-grid;
  }

  .shell-global-search input {
    padding-right: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app,
  .app > .sidebar,
  .shell-mobile-backdrop,
  .shell-collapse-icon,
  .sidebar .brand > div:last-child,
  .shell-sidebar-user-copy {
    transition: none !important;
  }
}
