* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--app-bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
  overflow-x: hidden;
  padding-left: 260px;
}

.sidebar-toggle {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  width: 260px;
  height: 100vh;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  isolation: isolate;
  contain: paint;
}

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

.sidebar::after {
  content: "";
  position: absolute;
  inset: 0 -48px 0 -48px;
  height: auto;
  pointer-events: none;
  z-index: 0;
  opacity: 0.45;
  background:
    radial-gradient(ellipse 88% 72% at 16% 100%, color-mix(in srgb, var(--accent-600) 84%, transparent) 0%, transparent 55%),
    radial-gradient(ellipse 78% 68% at 74% 106%, color-mix(in srgb, var(--accent-700) 72%, transparent) 0%, transparent 52%),
    radial-gradient(ellipse 72% 62% at 94% 94%, color-mix(in srgb, var(--accent-600) 66%, transparent) 0%, transparent 50%),
    radial-gradient(ellipse 68% 60% at 46% 100%, color-mix(in srgb, var(--accent-700) 76%, transparent) 0%, transparent 54%);
  filter: blur(22px) saturate(1.15);
  background-size: 108% 108%;
  background-position: 0 100%;
  animation: sidebar-bottom-glow 16s ease-in-out infinite alternate;
}

@keyframes sidebar-bottom-glow {
  0% {
    opacity: 0.38;
    background-size: 106% 106%;
    background-position: 0 100%;
  }
  100% {
    opacity: 0.52;
    background-size: 112% 112%;
    background-position: 8px 96%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar::after {
    animation: none;
    opacity: 0.44;
  }
}

.secondary-sidebar {
  width: 240px;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sidebar-surface);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(148, 163, 184, 0.14);
}

.sidebar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.sidebar-brand-icon {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  margin-top: 2px;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

.sidebar-section:first-child {
  padding-top: 0;
  margin-top: 0;
  border-top: none;
}

.sidebar-section-title {
  padding: 0 12px;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(229, 231, 235, 0.72);
  font-weight: 700;
}

.sidebar-nav a {
  color: var(--sidebar-link);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background-color 120ms ease, color 120ms ease;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover-bg);
}

.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--accent-contrast);
}

.nav-icon {
  flex-shrink: 0;
  width: 1.25em;
  text-align: center;
}

.nav-label {
  flex: 1;
  min-width: 0;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.sidebar-footer-link {
  color: var(--sidebar-link);
  text-decoration: none;
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background-color 120ms ease, color 120ms ease;
}

.sidebar-footer-link:hover {
  background: var(--sidebar-hover-bg);
}

.sidebar-footer-link.active {
  background: var(--sidebar-active-bg);
  color: var(--accent-contrast);
}

.sidebar-footer-label {
  flex: 1;
  min-width: 0;
}

.logout-btn {
  width: 100%;
  border: none;
  background: #ef4444;
  color: #fff;
  border-radius: 8px;
  font: inherit;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  cursor: pointer;
}

.content {
  flex: 1;
  padding: 26px;
  min-width: 0;
}

@media (max-width: 1200px) {
  .app-shell {
    padding-left: 0;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    margin-bottom: 10px;
    border: none;
    border-radius: 8px;
    padding: 10px 8px;
    background: transparent;
    color: #e5e7eb;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
  }

  .sidebar-toggle:hover {
    background: #1f2937;
  }

  .sidebar-toggle span {
    display: none;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1090;
    background: rgba(17, 24, 39, 0.45);
  }

  .sidebar-backdrop.is-visible {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1100;
    width: 68px;
    flex: 0 0 68px;
    padding: 14px 8px;
    transform: none;
    transition: width 0.22s ease, padding 0.22s ease;
    overflow-y: auto;
  }

  .secondary-sidebar {
    display: none;
  }

  .sidebar-brand { order: 0; }
  .sidebar-toggle { order: 1; }
  .sidebar-nav { order: 2; }
  .sidebar-footer { order: 3; }

  .sidebar-brand,
  .sidebar .nav-label,
  .sidebar .sidebar-section-title,
  .sidebar .logout-label,
  .sidebar .sidebar-footer-label {
    display: none;
  }

  .sidebar-nav a {
    justify-content: center;
    gap: 0;
    padding: 10px 8px;
  }

  .sidebar-footer {
    display: block;
  }

  .logout-btn {
    padding: 10px 8px;
    justify-content: center;
  }

  .sidebar.is-open {
    width: min(280px, 82vw);
    flex-basis: min(280px, 82vw);
    padding: 20px 14px;
  }

  .sidebar.is-open .sidebar-brand,
  .sidebar.is-open .sidebar-footer,
  .sidebar.is-open .nav-label,
  .sidebar.is-open .logout-label {
    display: block;
  }

  .sidebar.is-open .sidebar-toggle {
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }

  .sidebar.is-open .sidebar-toggle span {
    display: inline;
  }

  .sidebar.is-open .sidebar-nav a {
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }

  .sidebar.is-open .logout-btn {
    justify-content: flex-start;
    padding: 10px 12px;
  }

  .content {
    padding: 20px 16px 20px 84px;
    width: 100%;
  }
}

.auth-container {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 20px;
  background-color: color-mix(in srgb, var(--accent-100) 50%, var(--app-bg));
  background-image:
    radial-gradient(circle at 12% 16%, color-mix(in srgb, var(--accent-600) 44%, transparent) 0%, transparent 40%),
    radial-gradient(circle at 88% 18%, color-mix(in srgb, var(--accent-700) 36%, transparent) 0%, transparent 38%),
    radial-gradient(circle at 78% 86%, color-mix(in srgb, var(--accent-600) 32%, transparent) 0%, transparent 42%),
    radial-gradient(circle at 18% 84%, color-mix(in srgb, var(--accent-700) 30%, transparent) 0%, transparent 40%);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  animation: app-modal-pop-in 220ms ease forwards;
}

.auth-container::before,
.auth-container::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  filter: blur(16px);
  opacity: 0.78;
  pointer-events: none;
  z-index: 0;
}

.auth-container::before {
  width: min(46vw, 580px);
  height: min(46vw, 580px);
  left: -10%;
  top: -16%;
  background: radial-gradient(circle at 35% 35%, color-mix(in srgb, var(--accent-600) 82%, transparent) 0%, transparent 65%);
  box-shadow:
    400px 64px 0 0 color-mix(in srgb, var(--accent-700) 52%, transparent),
    600px 260px 0 10px color-mix(in srgb, var(--accent-600) 42%, transparent),
    300px 440px 0 0 color-mix(in srgb, var(--accent-700) 46%, transparent);
  animation: auth-orb-float-a 11s ease-in-out infinite alternate;
}

.auth-container::after {
  width: min(42vw, 500px);
  height: min(42vw, 500px);
  right: -10%;
  bottom: -14%;
  background: radial-gradient(circle at 40% 40%, color-mix(in srgb, var(--accent-700) 76%, transparent) 0%, transparent 68%);
  box-shadow:
    -340px -64px 0 0 color-mix(in srgb, var(--accent-600) 48%, transparent),
    -520px -240px 0 0 color-mix(in srgb, var(--accent-700) 42%, transparent),
    -240px -380px 0 12px color-mix(in srgb, var(--accent-600) 38%, transparent);
  animation: auth-orb-float-b 13s ease-in-out infinite alternate;
}

@keyframes auth-orb-float-a {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    transform: translate3d(52px, 36px, 0) scale(1.12);
  }
}

@keyframes auth-orb-float-b {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    transform: translate3d(-44px, -34px, 0) scale(1.14);
  }
}

.auth-container > * {
  position: relative;
  z-index: 1;
}

.flash-wrap {
  margin-bottom: 16px;
}

.auth-container .flash-wrap {
  width: 100%;
  max-width: 380px;
  margin-bottom: 8px;
}

.flash {
  background: var(--accent-100);
  border: 1px solid var(--accent-200);
  color: var(--accent-700);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.flash-error {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}
