/*
 * Campus Circle App Shell
 * Desktop: fixed rail + fluid main. Mobile: top bar + bottom tab bar.
 * One DOM tree, one layout language.
 */
.app-shell {
  min-height: 100dvh;
}

.side-rail {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: var(--z-header);
  display: flex;
  width: var(--rail-w);
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-4) var(--sp-4);
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, var(--surface-2), var(--bg-soft));
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-lg);
  color: var(--ink);
  font-size: var(--text-md);
  font-weight: 760;
  letter-spacing: 0;
}

.rail-brand:hover {
  background: var(--surface-3);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: #fff;
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-top: var(--sp-4);
}

.rail-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 42px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-lg);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 620;
  transition: color var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

.rail-link .icon {
  width: 19px;
  height: 19px;
}

.rail-link:hover {
  background: var(--surface-3);
  color: var(--ink);
  transform: translateX(2px);
}

.rail-link.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.rail-link.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  width: 3px;
  height: 20px;
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  background: var(--accent);
  transform: translateY(-50%);
}

.rail-section-label {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  color: var(--faint);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rail-nav .rail-section-label:first-child {
  padding-top: 0;
}

.rail-foot {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: auto;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink-2);
  transition: background var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}

.icon-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.icon-btn:active {
  transform: translateY(0) scale(0.96);
}

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

.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 0 var(--sp-3);
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 620;
}

.theme-toggle:hover {
  background: var(--surface-3);
  color: var(--ink);
}

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

.theme-toggle [data-theme-icon="dark"] {
  display: none;
}

[data-theme="dark"] .theme-toggle [data-theme-icon="dark"] {
  display: block;
}

[data-theme="dark"] .theme-toggle [data-theme-icon="light"] {
  display: none;
}

.app-main {
  min-height: 100dvh;
  margin-left: var(--rail-w);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  border-bottom: 1px solid var(--line);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.15);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.15);
  box-shadow: var(--shadow-inset);
  transition: background var(--dur-3) var(--ease-out), box-shadow var(--dur-3) var(--ease-out);
}

.site-header.is-scrolled {
  box-shadow: var(--shadow-inset), var(--shadow-sm);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--header-h);
  padding-inline: 0 var(--sp-8);
}

.topbar-brand {
  display: none;
}

.site-nav {
  display: flex;
  align-items: center;
  align-self: center;
  gap: var(--sp-1);
  margin-left: auto;
}

.site-header--nav-desktop-hidden .site-nav {
  display: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 620;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}

.nav-link:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.header-actions {
  display: flex;
  align-items: center;
  align-self: center;
  gap: var(--sp-3);
}

.notify-link {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink-2);
  transition: background var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

.notify-link:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  transform: translateY(-1px);
}

.notify-link .icon {
  width: 19px;
  height: 19px;
}

.notify-badge {
  position: absolute;
  top: -5px;
  right: -6px;
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 2px solid var(--surface);
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 750;
  line-height: 1;
}

.notify-badge.is-empty {
  display: none;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 38px;
  padding: 3px 12px 3px 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 620;
  transition: background var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}

.user-chip:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}

.user-chip .avatar {
  width: 30px;
  height: 30px;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink-2);
}

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

.site-footer {
  padding: var(--sp-8) 0;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-sm);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: var(--sp-5);
}

.footer-links a {
  color: var(--ink-2);
  transition: color var(--dur-2) var(--ease-out);
}

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

.mobile-tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-header);
  display: none;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 6px 10px env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  box-shadow: 0 -8px 28px rgba(18, 24, 34, 0.06);
}

.mobile-tab {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  border: 0;
  border-radius: var(--r-lg);
  background: transparent;
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 640;
  transition: color var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

.mobile-tab .icon {
  width: 21px;
  height: 21px;
}

.mobile-tab:hover,
.mobile-tab.active {
  color: var(--ink);
  background: var(--surface-3);
}

.mobile-tab.active::after {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 18px;
  height: 3px;
  border-radius: var(--r-pill);
  background: var(--accent);
  transform: translateX(-50%);
}

.mobile-tab .notify-badge {
  top: 4px;
  right: calc(50% - 18px);
  border-width: 2px;
  border-color: var(--surface);
}

.composer-fab {
  position: fixed;
  right: clamp(18px, 3vw, 36px);
  bottom: 28px;
  z-index: var(--z-float);
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: #fff;
  box-shadow: 0 14px 32px var(--accent-glow), 0 4px 10px rgba(18, 24, 34, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: transform var(--dur-3) var(--ease-spring), box-shadow var(--dur-3) var(--ease-out);
}

.composer-fab .icon {
  width: 24px;
  height: 24px;
}

.composer-fab:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 18px 40px var(--accent-glow), 0 6px 14px rgba(18, 24, 34, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.composer-fab:active {
  transform: translateY(0) scale(0.96);
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 84px;
  z-index: var(--z-toast);
  display: grid;
  gap: var(--sp-2);
  width: min(340px, calc(100vw - 40px));
  pointer-events: none;
}

@media (max-width: 1099px) {
  .side-rail {
    display: none;
  }

  .app-main {
    margin-left: 0;
  }

  .topbar-brand {
    display: inline-flex;
  }

  .site-nav {
    position: fixed;
    top: var(--header-h);
    right: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-1);
    padding: var(--sp-3);
    border-bottom: 1px solid var(--line);
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-md);
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: transform var(--dur-3) var(--ease-out), opacity var(--dur-3) var(--ease-out), visibility var(--dur-3);
  }

  .site-nav.is-open {
    transform: none;
    opacity: 1;
    visibility: visible;
  }

  .nav-link {
    min-height: 44px;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .site-header--nav-desktop-hidden .site-nav {
    display: flex;
  }

  .mobile-tabbar {
    display: flex;
  }

  .page-main {
    padding-bottom: 108px;
  }

  .composer-fab {
    right: 18px;
    bottom: 82px;
  }
}

@media (max-width: 640px) {
  .site-header {
    height: 58px;
  }

  .topbar-inner {
    min-height: 58px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .topbar-inner::-webkit-scrollbar {
    display: none;
  }

  .page-main {
    padding: 22px 0 100px;
  }

  .header-actions .user-chip {
    display: none;
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header,
  .mobile-tabbar,
  .site-nav {
    background: var(--surface);
  }
}

/* Collapsible side rail */
.side-rail,
.app-main {
  transition: width var(--dur-3) var(--ease-out), margin-left var(--dur-3) var(--ease-out), padding var(--dur-3) var(--ease-out);
}

.rail-toggle {
  display: inline-flex;
}

.app-shell.is-rail-collapsed .side-rail {
  width: 78px;
  padding: var(--sp-5) 12px var(--sp-4);
}

.app-shell.is-rail-collapsed .rail-brand {
  justify-content: center;
  padding: var(--sp-2) 0;
}

.app-shell.is-rail-collapsed .brand-name,
.app-shell.is-rail-collapsed .rail-link span,
.app-shell.is-rail-collapsed .theme-toggle span,
.app-shell.is-rail-collapsed .rail-section-label {
  display: none;
}

.app-shell.is-rail-collapsed .rail-link {
  justify-content: center;
  padding: 0;
}

.app-shell.is-rail-collapsed .rail-link.active::before {
  left: -12px;
}

.app-shell.is-rail-collapsed .rail-foot {
  align-items: center;
}

.app-shell.is-rail-collapsed .theme-toggle {
  width: 44px;
  padding: 0;
  justify-content: center;
}

.app-shell.is-rail-collapsed .app-main {
  margin-left: 78px;
}

@media (max-width: 1099px) {
  .rail-toggle {
    display: none;
  }
}

/* Rail footer collapse button */
.rail-foot-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 0 var(--sp-3);
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 620;
}

.rail-foot-toggle:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.app-shell.is-rail-collapsed .rail-foot-toggle {
  width: 44px;
  padding: 0;
  justify-content: center;
}

.app-shell.is-rail-collapsed .rail-toggle-label {
  display: none;
}

@media (max-width: 1099px) {
  .rail-foot-toggle {
    display: none;
  }
}


/* Sliding theme switch */
.theme-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 58px;
  height: 32px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface-3);
  cursor: pointer;
  transition: background var(--dur-3) var(--ease-out), border-color var(--dur-3) var(--ease-out), box-shadow var(--dur-3) var(--ease-out);
  flex: none;
}

.theme-switch:hover {
  border-color: var(--faint);
  box-shadow: var(--shadow-xs);
}

.theme-switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-switch-thumb {
  position: absolute;
  left: 3px;
  top: 3px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-3) var(--ease-spring), background var(--dur-3) var(--ease-out), color var(--dur-3) var(--ease-out);
}

.theme-switch-thumb .icon {
  width: 14px;
  height: 14px;
}

.theme-switch-thumb [data-theme-icon="dark"] {
  display: none;
}

[data-theme="dark"] .theme-switch {
  background: var(--accent-soft);
  border-color: var(--accent);
}

[data-theme="dark"] .theme-switch-thumb {
  transform: translateX(26px);
  background: var(--accent);
  color: #fff;
}

[data-theme="dark"] .theme-switch-thumb [data-theme-icon="dark"] {
  display: block;
}

[data-theme="dark"] .theme-switch-thumb [data-theme-icon="light"] {
  display: none;
}

.rail-foot .theme-switch {
  align-self: flex-start;
}

.auth-visual-top .theme-switch {
  margin-left: auto;
}

.header-actions .theme-switch {
  display: none;
}

@media (max-width: 1099px) {
  .header-actions .theme-switch {
    display: inline-flex;
  }
}


/* Fixed sun/moon track with sliding knob */
.theme-switch-track {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  color: var(--faint);
  pointer-events: none;
}

.theme-switch-track .icon {
  width: 14px;
  height: 14px;
}

.theme-switch-sun {
  color: var(--accent);
  opacity: 1;
  transition: color var(--dur-3) var(--ease-out), opacity var(--dur-3) var(--ease-out);
}

.theme-switch-moon {
  color: var(--faint);
  opacity: 0.55;
  transition: color var(--dur-3) var(--ease-out), opacity var(--dur-3) var(--ease-out);
}

[data-theme="dark"] .theme-switch-sun {
  color: var(--faint);
  opacity: 0.55;
}

[data-theme="dark"] .theme-switch-moon {
  color: var(--accent);
  opacity: 1;
}

.theme-switch-thumb {
  z-index: 1;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .theme-switch-thumb {
  transform: translateX(26px);
  background: var(--accent);
}


/* Theme icons from local asset library */
.theme-switch-sun .theme-icon,
.theme-switch-moon .theme-icon {
  display: block;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.theme-switch-sun .theme-icon {
  -webkit-mask-image: url('../media/theme/sun.svg');
  mask-image: url('../media/theme/sun.svg');
}

.theme-switch-moon .theme-icon {
  -webkit-mask-image: url('../media/theme/moon.svg');
  mask-image: url('../media/theme/moon.svg');
}
