/**
 * ToughBlue — collapsible side navigation with icon system
 */

:root {
  --sidebar-width: 272px;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(185deg, #0a2548 0%, var(--tb-primary-dark) 42%, #0d3266 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 300;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 4px 0 32px rgba(13, 50, 102, 0.18);
  transition: transform 0.22s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.2rem 1.15rem 1.05rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, transparent 100%);
}

.sidebar-brand:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: #fff;
  border-radius: 50%;
  padding: 5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.sidebar-brand-text {
  font-weight: 800;
  font-size: 0.96rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.sidebar-brand-text span {
  color: var(--tb-secondary);
}

.sidebar-brand-sub {
  display: block;
  font-size: 0.67rem;
  font-weight: 600;
  opacity: 0.7;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 0.15rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.65rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 4px;
}

/* ── Icons ── */
.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  color: rgba(255, 255, 255, 0.75);
  transition: color 0.15s;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.nav-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.nav-icon-wrap .nav-icon {
  width: 1rem;
  height: 1rem;
  color: var(--tb-secondary);
}

.sidebar-group.open > .sidebar-group-toggle .nav-icon-wrap.group {
  background: rgba(107, 183, 232, 0.18);
  border-color: rgba(107, 183, 232, 0.35);
}

/* ── Links ── */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.58rem 0.8rem;
  margin-bottom: 0.15rem;
  border-radius: 9px;
  color: rgba(255, 255, 255, 0.86);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, transform 0.12s;
}

.sidebar-link span:last-child {
  line-height: 1.3;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.sidebar-link:hover .nav-icon {
  color: var(--tb-secondary);
}

.sidebar-link.active {
  background: linear-gradient(90deg, rgba(245, 166, 35, 0.16) 0%, rgba(107, 183, 232, 0.14) 100%);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--tb-accent);
  font-weight: 600;
}

.sidebar-link.active .nav-icon {
  color: var(--tb-accent);
}

/* ── Accordion groups ── */
.sidebar-group {
  margin-bottom: 0.4rem;
}

.sidebar-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-group-toggle:hover {
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-group-toggle .group-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.sidebar-group-toggle .group-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
}

.sidebar-group.open .sidebar-group-toggle .group-title {
  color: #fff;
}

.sidebar-group-toggle .chevron {
  display: inline-flex;
  width: 1rem;
  height: 1rem;
  opacity: 0.55;
  transition: transform 0.22s ease, opacity 0.15s;
}

.sidebar-group-toggle .chevron .nav-icon {
  width: 100%;
  height: 100%;
  color: inherit;
}

.sidebar-group.open .sidebar-group-toggle .chevron {
  transform: rotate(180deg);
  opacity: 0.85;
}

.sidebar-group-panel {
  display: none;
  margin: 0.2rem 0 0.35rem 0.85rem;
  padding-left: 0.65rem;
  border-left: 1px solid rgba(107, 183, 232, 0.22);
}

.sidebar-group.open .sidebar-group-panel {
  display: block;
}

.sidebar-group-panel .sidebar-link {
  padding: 0.5rem 0.7rem;
  font-size: 0.84rem;
  font-weight: 500;
}

.sidebar-group-panel .sidebar-link .nav-icon {
  width: 1rem;
  height: 1rem;
  opacity: 0.85;
}

.sidebar-user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem 0.55rem;
  margin-bottom: 0.15rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--tb-secondary);
  letter-spacing: 0.01em;
}

.sidebar-user-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tb-good);
  box-shadow: 0 0 6px rgba(22, 163, 74, 0.6);
  flex-shrink: 0;
}

.sidebar-signout {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: calc(100% - 0.1rem);
  margin-top: 0.1rem;
  padding: 0.5rem 0.7rem;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-signout:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.sidebar-signout:hover .nav-icon {
  color: #fca5a5;
}

.sidebar-footer {
  padding: 0.9rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.71rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.12);
}

.sidebar-footer .think { color: var(--tb-accent); }
.sidebar-footer .act { color: var(--tb-accent-act); }
.sidebar-footer .solve { color: var(--tb-secondary); }

/* ── Main area ── */
.app-main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--tb-primary-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 200;
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--tb-accent), var(--tb-secondary), var(--tb-primary)) 1;
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}

.sidebar-toggle .nav-icon {
  width: 1.15rem;
  height: 1.15rem;
  color: #fff;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

.app-topbar-title {
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 50, 102, 0.45);
  z-index: 250;
  backdrop-filter: blur(3px);
}

body.sidebar-mobile-open .sidebar-backdrop {
  display: block;
}

.app-main .container {
  flex: 1;
  width: 100%;
  max-width: 1080px;
}

/* ── Mobile ── */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  body.sidebar-mobile-open .sidebar {
    transform: translateX(0);
  }

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

  .app-topbar {
    display: flex;
  }
}

@media print {
  .sidebar,
  .app-topbar,
  .sidebar-backdrop {
    display: none !important;
  }

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