/*
 * History navigation count layout fix.
 * Keep labels and large counters horizontal without changing React data/state.
 */

/* Main gallery toolbar: Personal / Public / Group plus filters. */
#root .flex.items-center.gap-1.ml-4.mr-\[22px\].mt-3.mb-1 {
  min-width: 0;
  min-height: 34px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: center;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

#root .flex.items-center.gap-1.ml-4.mr-\[22px\].mt-3.mb-1::-webkit-scrollbar {
  display: none;
}

#root .flex.items-center.gap-1.ml-4.mr-\[22px\].mt-3.mb-1 > button {
  flex-shrink: 0 !important;
  min-width: max-content;
  white-space: nowrap !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
  writing-mode: horizontal-tb !important;
  line-height: 1.25;
}

/* Right history panel: Personal / Public / Group / module categories. */
#root [class~="w-[280px]"] > [class*="border-b"] > .flex.items-center.gap-1.flex-wrap {
  flex-wrap: nowrap !important;
  align-content: flex-start;
  align-items: center;
}

#root [class~="w-[280px]"] > [class*="border-b"] > .flex.items-center.gap-1.flex-wrap > button {
  flex: 0 0 auto !important;
  min-width: max-content !important;
  white-space: nowrap !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
  writing-mode: horizontal-tb !important;
  line-height: 1.25;
}

/* This compact header only switches between personal and public history. */
#root [class~="w-[280px]"] > [class*="border-b"] > .flex.items-center.gap-1.flex-wrap > button:nth-child(n + 3) {
  display: none !important;
}

#root [class~="w-[280px]"] > [class*="border-b"] > .flex.items-center.gap-1.flex-wrap > button:nth-child(-n + 2) {
  flex: 1 1 0 !important;
  justify-content: center;
  min-width: 0 !important;
}

/* Current compact history header: deliberately expose only Personal / Public. */
#root .nano-history-compact-tabs {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 30px;
  gap: 6px !important;
  overflow: visible !important;
  padding-bottom: 0 !important;
}

#root .nano-history-compact-tabs > :nth-child(n + 3):not(.nano-history-collapse-btn) {
  display: none !important;
}

#root .nano-history-compact-tabs > button:nth-child(-n + 2) {
  width: 100%;
  min-width: 0 !important;
  justify-content: center;
  white-space: nowrap !important;
  writing-mode: horizontal-tb !important;
}

/* Match the Nano homepage creator panel to the AI video creator panel. */
@media (min-width: 1101px) {
  #root [class~="w-[340px]"] {
    width: 400px !important;
  }
}

@media (min-width: 761px) and (max-width: 1100px) {
  #root [class~="w-[340px]"] {
    width: 380px !important;
  }
}

/* Compact history panel: collapsed by default, expandable from its header. */
#root [class~="w-[280px]"] {
  transition: width .2s ease, min-width .2s ease;
}

#root .nano-history-collapse-btn {
  display: inline-flex !important;
  width: 30px !important;
  min-width: 30px !important;
  height: 30px;
  padding: 0 !important;
  align-items: center;
  justify-content: center;
  border: 1px solid #343438;
  border-radius: 8px;
  color: #9ca3af;
  background: #202024;
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background .18s ease, transform .2s ease;
}

#root .nano-history-collapse-btn:hover {
  color: #fff;
  border-color: #8b5cf680;
  background: #29252f;
}

#root .nano-history-collapse-btn svg {
  width: 15px;
  height: 15px;
  pointer-events: none;
  transform: rotate(-90deg);
  transition: transform .2s ease;
}

#root .nano-history-panel-collapsed {
  position: relative;
  width: 0 !important;
  min-width: 0 !important;
  overflow: visible !important;
  border-left: 0 !important;
  background: transparent !important;
}

#root .nano-history-panel-collapsed > :not(:first-child) {
  display: none !important;
}

#root .nano-history-panel-collapsed > :first-child {
  position: absolute;
  top: 136px;
  right: 0;
  z-index: 20;
  width: 38px;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
}

#root .nano-history-panel-collapsed .nano-history-compact-tabs {
  display: flex !important;
  width: 38px;
  justify-content: center;
}

#root .nano-history-panel-collapsed .nano-history-compact-tabs > :not(.nano-history-collapse-btn) {
  display: none !important;
}

#root .nano-history-panel-collapsed .nano-history-collapse-btn {
  width: 38px !important;
  min-width: 38px !important;
  height: 42px;
  border-right: 0;
  border-radius: 12px 0 0 12px;
  background: #20242d;
  box-shadow: -8px 8px 24px #0007;
  transform: none;
}

#root .nano-history-panel-collapsed .nano-history-collapse-btn svg {
  transform: rotate(90deg);
}

/* One visual language for expandable sections: down = open, right = closed. */
#root #nano-stats-collapse-btn {
  position: relative;
  display: inline-flex;
  width: 28px;
  min-width: 28px;
  height: 26px;
  padding: 0;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 0;
}

#root #nano-stats-collapse-btn:hover {
  color: #e5e7eb;
  background: #ffffff0a;
}

#root #nano-stats-collapse-btn > span {
  display: none !important;
}

#root #nano-stats-collapse-btn::before,
#root .nano-generation-channel-heading::after {
  content: '';
  width: 7px;
  height: 7px;
  border: solid currentColor;
  border-width: 0 1.8px 1.8px 0;
  transform: rotate(45deg);
  transition: transform .18s ease;
}

#root #nano-stats-collapse-btn[data-nano-collapsed="1"]::before,
#root .nano-generation-channel-collapsed > .nano-generation-channel-heading::after {
  transform: rotate(-45deg);
}

#root .nano-generation-channel-heading {
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  padding: 3px 4px;
  margin: -3px -4px 5px;
  transition: color .18s ease, background .18s ease;
}

#root .nano-generation-channel-heading:hover,
#root .nano-generation-channel-heading:focus-visible {
  color: #e5e7eb;
  background: #ffffff08;
  outline: none;
}

#root .nano-generation-channel-collapsed > :nth-child(2) {
  display: none !important;
}

#root button.nano-unified-collapse-control svg.lucide-chevron-down {
  width: 14px;
  height: 14px;
  color: #9ca3af;
  stroke-width: 2;
}

/* Give the work gallery the same breathing room as the AI Video workspace. */
@media (min-width: 1101px) {
  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none {
    padding: 24px !important;
  }

  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none > .grid {
    gap: 20px !important;
  }

  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none > .grid > [class*="rounded-2xl"] > .p-3\.5 {
    padding: 16px !important;
  }
}

@media (min-width: 761px) and (max-width: 1100px) {
  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none {
    padding: 18px !important;
  }

  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none > .grid {
    gap: 16px !important;
  }
}

/* Align the Nano home workspace edge with the AI Video workspace. */
@media (min-width: 761px) {
  #root .flex-1.flex.flex-col.min-w-0.relative > .m-4.mb-0 {
    margin-top: 28px !important;
    margin-left: 30px !important;
    margin-right: 30px !important;
    padding: 13px 16px !important;
    border-radius: 12px !important;
  }

  #root .flex.items-center.gap-1.ml-4.mr-\[22px\].mt-3.mb-1,
  #root .ml-4.mr-\[22px\].mb-1,
  #root .flex.items-center.gap-2.ml-4.mr-\[22px\].mb-1 {
    margin-left: 30px !important;
    margin-right: 30px !important;
  }

  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none {
    padding-left: 30px !important;
    /* The 6px gallery scrollbar occupies layout width on Windows Chrome. */
    padding-right: 24px !important;
  }

  /* Group the view controls and filter summary like the AI Video toolbar. */
  #root .flex.items-center.gap-1.ml-4.mr-\[22px\].mt-3.mb-1 {
    margin-bottom: 0 !important;
    padding: 10px 12px 7px;
    border: 1px solid #292b30;
    border-bottom: 0;
    border-radius: 11px 11px 0 0;
    background: #141416;
  }

  #root .flex.items-center.gap-1.ml-4.mr-\[22px\].mt-3.mb-1 + .ml-4.mr-\[22px\].mb-1 {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding: 7px 12px 10px;
    border: 1px solid #292b30;
    border-radius: 0 0 11px 11px;
    background: #141416;
  }

  #root .w-full.h-full.overflow-auto.p-4.custom-scrollbar.relative.select-none {
    padding-top: 16px !important;
  }
}
