/* ------------------------------
   LAYOUT WRAPPER
------------------------------ */
#layout {
  display: flex;
  height: 100vh;
  min-height: 0;
  width: 100%;
}

/* ------------------------------
   SIDEBAR
------------------------------ */
#sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  color: var(--accent);
  animation: rainbow-shift 50s linear infinite;
}

.logo::after {
  content: "";
  width: 24px;
  height: 24px;
  display: inline-block;
  background: url('/favicon.svg') no-repeat center center;
  background-size: contain;
  flex-shrink: 0;
}

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

.nav-link {
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-dim);
  background: linear-gradient(135deg, rgba(15, 82, 186, 0.2) 0%, rgba(9, 22, 44, 0.24) 54%, rgba(0, 0, 0, 0.28) 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  transition: transform 0.18s ease, color 0.18s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.22s ease;
  position: relative;
  overflow: hidden;
}

.nav-link::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  width: 3px;
  height: 60%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  opacity: 0;
  transform: scaleY(0.65);
  transition: opacity 0.2s ease, transform 0.22s ease;
}

.nav-link:hover {
  background: linear-gradient(135deg, rgba(15, 82, 186, 0.28) 0%, rgba(9, 22, 44, 0.3) 54%, rgba(0, 0, 0, 0.32) 100%);
  color: var(--text);
  transform: translateX(4px);
}

.nav-link:hover::before {
  opacity: 0.75;
  transform: scaleY(1);
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(15, 82, 186, 0.46) 0%, rgba(11, 58, 132, 0.42) 52%, rgba(0, 0, 0, 0.36) 100%);
  color: #fff;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  transform: translateX(2px);
  animation: rainbow-shift 50s linear infinite, navActivePulse 260ms ease-out;
}

.nav-link.active::before {
  opacity: 1;
  transform: scaleY(1);
}

/* ------------------------------
   SIDEBAR FOOTER
------------------------------ */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.8;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: #0F52BA;
  border-radius: 50%;
  animation: rainbow-shift 50s linear infinite;
}

/* ------------------------------
   MAIN CONTENT AREA
------------------------------ */
#main {
  flex: 1;
  padding: 32px 48px;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
}

/* Docs pages use more horizontal space */
#main.docs-main {
  padding: 32px 64px;
}

@media (min-width: 1600px) {
  #main.docs-main {
    padding: 40px 80px;
  }
}

@media (min-width: 1920px) {
  #main.docs-main {
    padding: 48px 120px;
  }
}

@media (min-width: 1400px) {
  #main {
    padding: 40px 64px;
  }
}

@media (max-width: 1200px) {
  #main.docs-main {
    padding: 28px 40px;
  }
}

@media (max-width: 768px) {
  #main {
    padding: 24px;
  }
  
  #main.docs-main {
    padding: 24px 20px;
  }
}

@media (max-width: 960px) {
  #layout {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  #sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px;
    gap: 12px;
  }

  .logo {
    font-size: 18px;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .nav-link {
    padding: 8px 10px;
    font-size: 13px;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  #main,
  #main.docs-main {
    padding: 14px 12px;
    overflow-y: visible;
    overflow-x: hidden;
  }
}

@media (max-width: 640px) {
  #sidebar {
    position: relative;
  }

  .nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  #sidebar::after {
    content: "";
    position: absolute;
    right: 0;
    top: 40px;
    width: 20px;
    height: 40px;
    pointer-events: none;
    background: linear-gradient(to right, rgba(5, 7, 12, 0), rgba(5, 7, 12, 0.72));
  }

  .nav-link {
    white-space: nowrap;
    flex: 0 0 auto;
  }
}

@media (max-width: 380px) {
  #sidebar {
    padding: 10px 8px;
    gap: 10px;
  }

  .nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .nav-link {
    white-space: nowrap;
    flex: 0 0 auto;
    font-size: 12px;
    padding: 7px 9px;
  }

  .sidebar-footer {
    font-size: 12px;
  }
}

.page-header {
  margin-bottom: 30px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.subtitle {
  color: var(--text-dim);
  margin-top: 6px;
}

.system-main {
  width: 100%;
}

.system-section {
  margin-bottom: 18px;
}

.system-section ul,
.system-section li,
.system-section p,
.system-section h3,
.system-section code,
.system-section strong {
  overflow-wrap: anywhere;
}

.system-section .status-card {
  display: grid;
  gap: 10px;
}

.system-section .btn {
  width: fit-content;
  max-width: 100%;
}

@media (max-width: 600px) {
  .system-section {
    margin-bottom: 14px;
  }

  .system-section .status-card {
    padding: 14px;
  }

  .system-section .btn {
    width: 100%;
  }
}

@media (max-width: 320px) {
  .system-section {
    margin-bottom: 12px;
  }

  .system-section h3 {
    font-size: 18px;
  }

  .system-section p,
  .system-section li,
  .system-section code {
    font-size: 13px;
    line-height: 1.5;
  }

  .system-section .status-card {
    padding: 12px;
    gap: 8px;
  }
}

.tools-main,
.memory-main {
  width: 100%;
}

.tools-section,
.memory-list,
.memory-actions {
  margin-bottom: 16px;
}

.tools-section h3,
.memory-list h3,
.tools-section p,
.memory-list p,
.tools-section strong,
.memory-list strong,
.tool-log pre {
  overflow-wrap: anywhere;
}

.tools-main .tool-grid,
.memory-main .memory-list {
  display: grid;
  gap: 12px;
}

.memory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tool-log pre {
  margin: 0;
  max-width: 100%;
  overflow-x: auto;
}

@media (max-width: 600px) {
  .tools-section,
  .memory-list,
  .memory-actions {
    margin-bottom: 12px;
  }

  .tools-main .tool-grid,
  .memory-main .memory-list {
    gap: 10px;
  }

  .memory-actions .btn,
  .tools-section .btn,
  .memory-list .btn {
    width: 100%;
  }
}

@media (max-width: 320px) {
  .tools-section h3,
  .memory-list h3 {
    font-size: 18px;
  }

  .tools-section p,
  .memory-list p,
  .tool-log pre,
  .memory-toggle-row {
    font-size: 13px;
    line-height: 1.5;
  }

  .tools-main .feature-card,
  .memory-main .feature-card,
  .tool-log,
  .memory-main .status-card {
    padding: 12px;
  }
}
.nav-link {
  position: relative;
  overflow: hidden;
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(15, 82, 186, 0.46) 0%, rgba(11, 58, 132, 0.42) 52%, rgba(0, 0, 0, 0.36) 100%);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}

.nav-link:hover {
  transform: translateX(4px);
}

@keyframes navActivePulse {
  0% {
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
  100% {
    box-shadow: 0 0 12px var(--accent-glow);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-link,
  .nav-link::before {
    transition: none;
  }

  .nav-link:hover,
  .nav-link.active {
    transform: none;
  }

  .nav-link.active {
    animation: none;
  }
}
#layout::before {
  content: "";
  position: fixed;
  top: -20%;
  left: -20%;
  width: 140%;
  height: 140%;
  background: radial-gradient(
    circle at 30% 20%,
    rgba(15, 82, 186, 0.18) 0%,
    rgba(15, 82, 186, 0.1) 42%,
    transparent 72%
  );
  pointer-events: none;
  z-index: -1;
  animation: ambientMove 18s infinite alternate ease-in-out;
}

@keyframes ambientMove {
  0% { transform: translate(0,0); }
  100% { transform: translate(10%, 6%); }
}

/* ---------- PAGE WRAPPER ---------- */
.page {
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ---------- CARD GRID (Desktop) ---------- */
@media (min-width: 800px) {
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-4);
  }
}